import re from django import forms from django.contrib.auth.models import User from django.conf import settings from django.http import Http404 from django.shortcuts import get_object_or_404 from django.utils.translation import ugettext_lazy as _ from django.utils.safestring import mark_safe from askbot.conf import settings as askbot_settings from askbot.utils.slug import slugify from askbot.utils.functions import split_list from askbot import const from longerusername import MAX_USERNAME_LENGTH import logging import urllib DEFAULT_NEXT = '/' + getattr(settings, 'ASKBOT_URL') def clean_next(next, default = None): if next is None or not next.startswith('/'): if default: return default else: return DEFAULT_NEXT if isinstance(next, str): next = unicode(urllib.unquote(next), 'utf-8', 'replace') next = next.strip() logging.debug('next url is %s' % next) return next def get_next_url(request, default = None): return clean_next(request.REQUEST.get('next'), default) def get_db_object_or_404(params): """a utility function that returns an object in return to the model_name and object_id only specific models are accessible """ from askbot import models try: model_name = params['model_name'] assert(model_name=='Group') model = models.get_model(model_name) obj_id = forms.IntegerField().clean(params['object_id']) return get_object_or_404(model, id=obj_id) except Exception: #need catch-all b/c of the nature of the function raise Http404 def format_errors(error_list): """If there is only one error - returns a string corresponding to that error, to remove the