Esempio n. 1
0
    def get_context_data(self, **kwargs):
        # Set up pagination interval before calling super()
        subsite = get_object_or_404(Subsite, slug=self.kwargs.get('slug'))
        self.paginate_by = subsite.ideas_per_page

        context = super(IdeaList, self).get_context_data(**kwargs)
        context['subsite'] = subsite
        context['form'] = self.kwargs.get('form', IdeaForm())
        context['ordering'] = self.ordering
        return context
Esempio n. 2
0
def new_idea(request, slug):
    subsite = get_object_or_404(Subsite, pk=slug)
    if not subsite.user_can_post(request.user):
        return redirect(subsite.get_absolute_url())
    form = IdeaForm(request, request.POST)
    request.session['name'] = form['name'].value()
    request.session['email'] = form['email'].value()
    if form.is_valid():
        data = form.cleaned_data
        data['subsite'] = subsite
        if not request.user.is_anonymous:
            data['user'] = request.user
        idea = Idea.objects.create(**data)
        return redirect(idea)
    else:
        ctx = {'subsite': subsite, 'form': form}
        return render(request, 'brainstorm/idea_form.html', ctx)
Esempio n. 3
0
def idea_list(request, slug, ordering='most_popular', **kwargs):
    subsite = get_object_or_404(Subsite, slug=slug)
    ordering_db = {
        'most_popular': '-score',
        'latest': '-timestamp'
    }.get(ordering, ordering)
    qs = Idea.objects.with_user_vote(request.user).filter(
        subsite__slug=slug,
        is_public=True).select_related().order_by(ordering_db)
    form = kwargs.get('form', IdeaForm(request))
    if hasattr(qs, '_gatekeeper'):
        qs = qs.approved()
    return list_detail.object_list(request,
                                   queryset=qs,
                                   extra_context={
                                       'ordering': ordering,
                                       'subsite': subsite,
                                       'form': form
                                   },
                                   paginate_by=subsite.ideas_per_page,
                                   template_object_name='idea')