def process_request(self, request): request.site = get_current_site(request) try: request.site_settings = SiteSettings.objects.get( site_id=request.site.id) except SiteSettings.DoesNotExist: pass
def post(self, request): form = IdeaForm(request.POST) if form.is_valid(): idea = form.save(commit=False) idea.site = get_current_site(request) idea.author = request.user return render(request, 'idea/idea.html', { "idea": idea, 'comments': [], })
def get(self, request, username=None): user = get_object_or_404(get_user_model(), username=username) ideas = Idea.objects.filter( author=user, site=get_current_site(request)).order_by('-created_at') moderator_sites = user.moderator_sites.all return render( request, 'user/profile.html', { 'user': user, 'ideas': ideas, 'moderator_sites': moderator_sites, 'paging_url_prefix': '/users/%s/ideas/' % user.username, })
def post(self, request): form = IdeaForm(request.POST) if request.POST.get('nosave'): return render(request, 'idea/idea_edit.html', { 'form': form, }) if form.is_valid(): idea = form.save(commit=False) idea.site = get_current_site(request) idea.author = request.user idea.save() idea.upvoters.add(request.user) return HttpResponseRedirect(idea.get_absolute_url()) return HttpResponse(form.errors)
def get_idea_queryset(self, request): return Idea.objects.filter( site=get_current_site(request), archived=False).annotate( score=Count('upvoters')).order_by('-score')
def get_idea_queryset(self, request): return Idea.objects.filter(site=get_current_site(request), archived=False).order_by('-created_at')
def get_idea_queryset(self, request): return sorted(Idea.objects.filter(site=get_current_site(request), archived=False), key=hot, reverse=True)
def get_idea_queryset(self, request): return Idea.objects.filter(site=get_current_site(request), archived=False)
def get_idea_queryset(self, request): return Idea.objects.filter( site=get_current_site(request), archived=False).order_by('-created_at')