示例#1
0
def create_idea(request):
    """
    This view displays a form for creating a idea resp. 
    creates a idea using the form data.
    """
    
    form = IdeaForm(request.POST or None)

    if form.is_valid():
        idea = form.save(commit=False)
        idea.promoted = 0
        idea.demoted = 0
        idea.save()
        
        return HttpResponseRedirect(reverse('bs_show', args=[idea.id]))

    data = {
        'form': form,
        'new' : True,
        'idea': None
    }

    return render_to_response(
        TEMPLATE_NAME + 'brainstorm/edit.html',
        data,
        context_instance = RequestContext(request),
    )
示例#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)
示例#3
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)
示例#4
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
示例#5
0
def edit_idea(request, idea_id, edit_hash):
    """
    This view displays a form to edit an idea resp.
    saves an idea using the form data.
    """
    
    idea = get_object_or_404(Idea, id=idea_id)
    
    if idea.edit_hash != edit_hash:
        return Http404
    
    if not request.POST:
        form = IdeaForm(instance=idea)
    else:
        form = IdeaForm(request.POST)
        
        if form.is_valid():
            idea.short_description = form.cleaned_data['short_description']
            idea.long_description = form.cleaned_data['long_description']
            
            idea.author_name = form.cleaned_data['author_name']
            idea.author_email = form.cleaned_data['author_email']
            idea.author_website = form.cleaned_data['author_website']
            
            idea.save()
            
            request.user.message_set.create(message="Your homework was saved.")
            
            return HttpResponseRedirect(reverse('bs_show', args=[idea.id]))

    data = {
        'form': form,
        'new': False,
        'idea': idea
    }

    return render_to_response(
        TEMPLATE_NAME + 'brainstorm/edit.html',
        data,
        context_instance = RequestContext(request),
    )
示例#6
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')