Ejemplo n.º 1
0
        def __view(request):
            result = view_func(request)

            if isinstance(result, _http.HttpResponse):
                return result

            if isinstance(result, str):
                return _render(request, result)
            elif isinstance(result, tuple):
                return _render(request, *result)
            elif isinstance(result, dict):
                return _render(request, **result)
            else:
                raise TypeError("return type with @render must be str, tuple or dict")
Ejemplo n.º 2
0
def render(request, template, context):
    english = Menu.objects.root_nodes().for_region(
        Region.objects.get(abbr='ru')).filter(name='English')[0]
    contact = Menu.objects.root_nodes().for_region().filter(name=u'Контакты')[0]
    form = AuthenticationForm(request)

    try:
        counter = Counter.object.get(region=get_region())
    except Counter.DoesNotExist:
        counter = None

    main_menu = Menu.objects.root_nodes().for_region().get(name=u'Основное меню')
    persons = Person.objects.select_related('region').filter(show_on_map=True)
    context.update({
        'persons': persons,
        'english': english,
        'contact': contact,
        'auth_form': form,
        'request': request,
        'region': get_region(),
        'regions': Region.objects.all(),
        'counter': counter,
    }),
    context.setdefault('main_menu', Menu.objects.filter(parent=main_menu))
    return _render(request, template, context)
Ejemplo n.º 3
0
def create_account(request):

    if request.method == "POST":
        first_name = request.POST["first_name"]
        last_name = request.POST["last_name"]
        username = request.POST["username"]
        email = request.POST["email"]
        password = request.POST["password"]
        confirmation_password = request.POST["confirmation_password"]

        if not _account.is_password_confirmation_password(
                password, confirmation_password):
            _messages.error(request, "Passwords do not match")
            return _redirect("create-account")

        if _account.username_exists(username):
            _messages.error(request, "Username is already in use")
            return _redirect("create-account")

        if _account.email_exists(email):
            _messages.error(request, "Email is already in use")
            return _redirect("create-account")

        user = _account.create_user(username, password, email, first_name,
                                    last_name)

        _auth.login(request, user)

        return _redirect("index")

    return _render(
        request,
        "pages/authentication/create_account.html",
        {"form": _forms.CreateAccoutForm()},
    )
Ejemplo n.º 4
0
def render(request, template, context):
    try:
        user = User.objects.select_related('profile').get(pk=request.user.id)
        context.setdefault('user', user)
    except User.DoesNotExist:
        pass
    context.setdefault('region', get_region())
    return _render(request, template, context)
Ejemplo n.º 5
0
def add_item(request, list_id):
    # get the list using the list_id
    list_obj = _get_object_or_404(_models.List, pk=list_id)
    if list_obj.user != request.user:
        return _defaults.page_not_found()

    # ensure that the list belongs to the auth user

    return _render(request, "pages/lists/add_item.html")
Ejemplo n.º 6
0
def render(req, url, extra={}):
    """
    Hooking into render functionality and dynamically
    making entries list available for all views
    """
    alphabet_list = list(map(chr, range(65, 65 + 26)))
    extra.update(entries_options=util.list_entries(),
                 alphabet_list=alphabet_list,
                 debug=settings.DEBUG)

    return _render(req, url, extra)
Ejemplo n.º 7
0
def render(*args, **kwargs):
    # Set the threading local stuff so we can validate
    # that the user is using this render function if
    # they are using the partials in their templates

    request = args[0]
    partial_name = request.GET.get('partial')
    partial_data = {"name": partial_name} if partial_name else None
    THREAD_LOCAL.ajax_partial = partial_data if request.is_ajax() else None

    response = _render(*args, **kwargs)
    if THREAD_LOCAL.ajax_partial and 'content' in THREAD_LOCAL.ajax_partial:
        response.content = THREAD_LOCAL.ajax_partial['content']

    return response
Ejemplo n.º 8
0
def render(*args, **kwargs):
    # Set the threading local stuff so we can validate
    # that the user is using this render function if
    # they are using the partials in their templates

    request = args[0]
    partial_name = request.GET.get('partial')
    partial_data = { "name": partial_name } if partial_name  else None
    THREAD_LOCAL.ajax_partial = partial_data if request.is_ajax() else None

    response = _render(*args, **kwargs)
    if THREAD_LOCAL.ajax_partial and 'content' in THREAD_LOCAL.ajax_partial:
        response.content = THREAD_LOCAL.ajax_partial['content']

    return response
Ejemplo n.º 9
0
def login(request):
    if request.method == "POST":

        username = request.POST["username"]
        password = request.POST["password"]

        user = _auth.authenticate(username=username, password=password)

        if user is not None:
            _auth.login(request, user)
            return _redirect("index")
        else:
            _messages.error(request, "Invalid Credentials")
            return _redirect("login")

    return _render(request, "pages/authentication/login.html",
                   {"form": _forms.LoginForm()})
Ejemplo n.º 10
0
def render_with_menu(request,
                     template_name,
                     context=None,
                     content_type=None,
                     status=None,
                     using=None):
    """获取菜单并做相应权限验证"""
    cxt = auth_info_required(request)
    if context is None:
        context = cxt
    else:
        context.update(cxt)
    return _render(request,
                   template_name,
                   context=context,
                   content_type=content_type,
                   status=status,
                   using=using)
Ejemplo n.º 11
0
def index(request):
    """
    Display home page.

    **Context**

    ``sample_courses``
        An instance of :model:`pages.Course`.

    **Template:**

    :template:`pages/index.html`
    """
    data = {"edit_mode": 'edit' in request.GET}
    data.update(services.get_website_settings())
    # fast_links = models.Page.objects.filter(publish_on_index=True,
    #                                        is_published=True)
    endorsements = models.Endorsement.objects.filter(is_published=True)
    recent_blog_posts = models.BlogPost.objects.filter(
        is_published=True).defer('body')[:3]
    sample_courses = models.Course.objects.filter(active=True)[:4]
    courses = models.Course.objects.filter(active=True)
    teachers = models.Teacher.objects.filter(publish_on_index=True)
    pricing_plans = models.PricingPlan.objects.all()
    gallery = models.Gallery.objects.filter(is_published=True)
    if data[consts.SETTINGS_ABOUT_ARTICLE]:
        data['article'] = models.Page.objects.get(
            pk=data[consts.SETTINGS_ABOUT_ARTICLE])
    data.update({
        # 'fast_links': fast_links,
        'endorsements': endorsements,
        'recent_blog_posts': recent_blog_posts,
        'sample_courses': sample_courses,
        'courses': courses,
        'teachers': teachers,
        'pricing_plans': pricing_plans,
        'gallery': gallery,
    })
    data.update(services.get_custom_form())
    return _render(request, 'pages/index.html', data)
Ejemplo n.º 12
0
def render(request, period, scenario=None):
    """
    Renders the data visualisation template
    for the given allocation period and scenario.
    """

    if scenario is None and period == "compare":
        scenario = "beneficiary_states"
    elif scenario is None:
        scenario = "overview"

    if scenario not in ALLOCATION_PERIODS[period]:
        raise Http404()

    context = {
        "PERIOD": period,
        "SCENARIO": scenario,
    }

    template = "%s.html" % scenario

    return _render(request, template, context)
Ejemplo n.º 13
0
def create_list(request):
    return _render(request, "pages/lists/create_list.html")
Ejemplo n.º 14
0
def render(request, template, render_keys):
    try:
        render_keys['debug_posts'] = Post.objects.filter(user=request.user)
    except Exception:
        pass
    return _render(request, template, render_keys)
Ejemplo n.º 15
0
def index(request):

    return _render(request, "pages/home/index.html")
Ejemplo n.º 16
0
def render(request, template, data=None):
    if data is None:
        data = {}
    data.update(services.get_website_settings())
    return _render(request, template, data)
Ejemplo n.º 17
0
def render(request, template, render_keys):
    try:
        render_keys['debug_posts'] = Post.objects.filter(user=request.user)
    except Exception:
        pass
    return _render(request, template, render_keys)
Ejemplo n.º 18
0
def render(request, template, context):
    """Add global attribute"""
    context = {} if context is None else context
    context['current_view'] = resolve(request.path_info).url_name
    return _render(request, template, context)