def get_context_data(self, **kwargs): context = super(ViewDebate, self).get_context_data(**kwargs) columns = Column.objects.filter(debate=self.kwargs['debate_id']) rows = Row.objects.filter(debate=self.kwargs['debate_id']) space_key = self.kwargs['space_url'] current_space = get_or_insert_object_in_cache(Space, space_key, url=space_key) debate_key = self.kwargs['debate_id'] current_debate = get_or_insert_object_in_cache(Debate, debate_key, pk=debate_key) notes = Note.objects.filter(debate=current_debate.pk) try: last_note = Note.objects.latest('id') except: last_note = 0 context['get_place'] = current_space context['notes'] = notes context['columns'] = columns context['rows'] = rows if last_note == 0: context['lastnote'] = 0 else: context['lastnote'] = last_note.pk return context
def get_context_data(self, **kwargs): """ """ context = super(ViewDebate, self).get_context_data(**kwargs) columns = Column.objects.filter(debate=self.kwargs["debate_id"]) rows = Row.objects.filter(debate=self.kwargs["debate_id"]) space_key = self.kwargs["space_url"] current_space = get_or_insert_object_in_cache(Space, space_key, url=space_key) debate_key = self.kwargs["debate_id"] current_debate = get_or_insert_object_in_cache(Debate, debate_key, pk=debate_key) notes = Note.objects.filter(debate=current_debate.pk) try: last_note = Note.objects.latest("id") except: last_note = 0 context["get_place"] = current_space context["notes"] = notes context["columns"] = columns context["rows"] = rows if last_note == 0: context["lastnote"] = 0 else: context["lastnote"] = last_note.pk return context
def get_object(self): # Makes sure the space ins't already in the cache before hitting # the database space_url = self.kwargs['space_url'] space_object = get_or_insert_object_in_cache(Space, space_url, url=space_url) if space_object.public == True \ or self.request.user.is_staff \ or self.request.user.is_superuser: if self.request.user.is_anonymous(): messages.info(self.request, _("Hello anonymous user. Remember \ that this space is public to view, but you must \ <a href=\"/accounts/register\">register</a> or \ <a href=\"/accounts/login\">login</a> to participate.")) return space_object # Check if the user is in the admitted user groups of the space if self.request.user in space_object.users.all() \ or self.request.user in space_object.admins.all() \ or self.request.user in space_object.mods.all(): return space_object # If the user does not meet any of the conditions, it's not allowed to # enter the space if self.request.user.is_anonymous(): messages.info(self.request, _("You're an anonymous user. You must \ <a href=\"/accounts/register\">register</a> or \ <a href=\"/accounts/login\">login</a> to access here.")) else: messages.warning(self.request, _("You're not registered to this \ space.")) self.template_name = 'not_allowed.html' return space_object
def get_context_data(self, **kwargs): context = super(ViewSpaceIndex, self).get_context_data(**kwargs) # Makes sure the space ins't already in the cache before hitting the # databass place_url = self.kwargs['space_url'] place = get_or_insert_object_in_cache(Space, place_url, url=place_url) '''posts_by_score = Comment.objects.filter(is_public=True) \ .values('object_pk').annotate(score=Count('id')).order_by('-score')''' posts_by_score = Comment.objects.filter(is_public=True) \ .values('object_pk').annotate(score=Count('id')).order_by('-score') post_ids = [int(obj['object_pk']) for obj in posts_by_score] top_posts = Post.objects.filter(space=place.id).in_bulk(post_ids) # print top_posts.values()[0].title # o_list = Comment.objects.annotate(ocount=Count('object_pk')) comment_list = {} most_commented = [] for proposal in Proposal.objects.filter(space=place.id): comment_list[proposal.pk]=Comment.objects.filter(object_pk=proposal.pk).count() for p in dict(sorted(comment_list.items(), key=itemgetter(1))): most_commented.append(Proposal.objects.filter(pk=p)) highlighted = {} highlight = [] for i in Proposal.objects.filter(space=place.id): highlighted[i.pk] = i.support_votes.count for p in dict(sorted(highlighted.items(), key=itemgetter(1))): highlight.append(Proposal.objects.filter(pk=p)) context['entities'] = Entity.objects.filter(space=place.id) context['documents'] = Document.objects.filter(space=place.id) context['proposalsets'] = ProposalSet.objects.filter(space=place.id) context['proposals'] = Proposal.objects.filter(space=place.id) \ .order_by('-pub_date') context['publication'] = Post.objects.filter(space=place.id) \ .order_by('-pub_date')[:5] context['mostviewed'] = Post.objects.filter(space=place.id) \ .order_by('-views')[:5] # context['mostcommented'] = [top_posts.get(id,None) for id in post_ids] context['mostcommented'] = filter(None, map(lambda x: top_posts.get(x, None), post_ids)) context['mostcommentedproposal'] = most_commented context['highlightedproposal'] = highlight # context['mostcommented'] = sorted(o_list, # key=lambda k: k['ocount'])[:10] # print sorted(o_list, key=lambda k: k['ocount'])[:10] context['page'] = StaticPage.objects.filter(show_footer=True) \ .order_by('-order') context['messages'] = messages.get_messages(self.request) context['debates'] = Debate.objects.filter(space=place.id) \ .order_by('-date') context['event'] = Event.objects.filter(space=place.id) \ .order_by('-event_date') context['votings'] = Voting.objects.filter(space=place.id) context['polls'] = Poll.objects.filter(space=place.id) # True if the request.user has admin rights on this space context['user_is_admin'] = (self.request.user in place.admins.all() or self.request.user in place.mods.all() or self.request.user.is_staff or self.request.user.is_superuser) context['polls'] = Poll.objects.filter(space=place.id) return context
def get_object(self): # Makes sure the space ins't already in the cache before hitting # the database space_url = self.kwargs['space_url'] space_object = get_or_insert_object_in_cache(Space, space_url, url=space_url) return space_object
def get_context_data(self, **kwargs): context = super(ViewSpaceIndex, self).get_context_data(**kwargs) # Makes sure the space ins't already in the cache before hitting the # databass place_url = self.kwargs['space_url'] place = get_or_insert_object_in_cache(Space, place_url, url=place_url) '''posts_by_score = Comment.objects.filter(is_public=True) \ .values('object_pk').annotate(score=Count('id')).order_by('-score')''' posts_by_score = Comment.objects.filter(is_public=True) \ .values('object_pk').annotate(score=Count('id')).order_by('-score') post_ids = [int(obj['object_pk']) for obj in posts_by_score] top_posts = Post.objects.filter(space=place.id).in_bulk(post_ids) # print top_posts.values()[0].title # o_list = Comment.objects.annotate(ocount=Count('object_pk')) comment_list = {} most_commented = [] for proposal in Proposal.objects.filter(space=place.id): comment_list[proposal.pk] = Comment.objects.filter( object_pk=proposal.pk).count() for p in dict(sorted(comment_list.items(), key=itemgetter(1))): most_commented.append(Proposal.objects.filter(pk=p)) highlighted = {} highlight = [] for i in Proposal.objects.filter(space=place.id): highlighted[i.pk] = i.support_votes.count for p in dict(sorted(highlighted.items(), key=itemgetter(1))): highlight.append(Proposal.objects.filter(pk=p)) context['entities'] = Entity.objects.filter(space=place.id) context['documents'] = Document.objects.filter(space=place.id) context['proposalsets'] = ProposalSet.objects.filter(space=place.id) context['proposals'] = Proposal.objects.filter(space=place.id) \ .order_by('-pub_date') context['publication'] = Post.objects.filter(space=place.id) \ .order_by('-pub_date')[:5] context['mostviewed'] = Post.objects.filter(space=place.id) \ .order_by('-views')[:5] # context['mostcommented'] = [top_posts.get(id,None) for id in post_ids] context['mostcommented'] = filter( None, map(lambda x: top_posts.get(x, None), post_ids)) context['mostcommentedproposal'] = most_commented context['highlightedproposal'] = highlight # context['mostcommented'] = sorted(o_list, # key=lambda k: k['ocount'])[:10] # print sorted(o_list, key=lambda k: k['ocount'])[:10] context['page'] = StaticPage.objects.filter(show_footer=True) \ .order_by('-order') context['messages'] = messages.get_messages(self.request) context['debates'] = Debate.objects.filter(space=place.id) \ .order_by('-date') context['event'] = Event.objects.filter(space=place.id) \ .order_by('-event_date') context['votings'] = Voting.objects.filter(space=place.id) context['polls'] = Poll.objects.filter(space=place.id) context['participants'] = get_users_with_perms(place) return context
def get_object(self): key = self.kwargs["debate_id"] debate = get_or_insert_object_in_cache(Debate, key, pk=key) # Check debate dates if datetime.date.today() >= debate.end_date or datetime.date.today() < debate.start_date: self.template_name = "debate/debate_outdated.html" # return Debate.objects.none() return debate
def get_queryset(self): key = self.kwargs['space_url'] current_space = get_or_insert_object_in_cache(Space, key, url=key) debates = Debate.objects.filter(space=current_space) # Here must go a validation so a user registered to the space # can always see the debate list. While an anonymous or not # registered user can't see anything unless the space is public return debates
def get_queryset(self): key = self.kwargs['space_url'] current_space = get_or_insert_object_in_cache(Space, key, url=key) polls = Poll.objects.filter(space=current_space) # Here must go a validation so a user registered to the space # can always see the poll list. While an anonymous or not # registered user can't see anything unless the space is public return polls
def get_object(self): key = self.kwargs['debate_id'] debate = get_or_insert_object_in_cache(Debate, key, pk=key) # Check debate dates if datetime.date.today() >= debate.end_date or datetime.date.today( ) < debate.start_date: self.template_name = 'debate/debate_outdated.html' #return Debate.objects.none() return debate
def get_object(self): key = self.kwargs['debate_id'] debate = get_or_insert_object_in_cache(Debate, key, pk=key) # Check debate dates if datetime.date.today() >= debate.end_date \ or datetime.date.today() < debate.start_date: self.template_name = 'debate/debate_outdated.html' return debate # We can't return none, if we do, the platform cannot show # the start and end dates and the title #return Debate.objects.none() return debate
def get_object(self): # Makes sure the space ins't already in the cache before hitting # the database space_url = self.kwargs["space_url"] space_object = get_or_insert_object_in_cache(Space, space_url, url=space_url) if space_object.public or has_all_permissions(self.request.user): if self.request.user.is_anonymous(): messages.info( self.request, _( 'Hello anonymous user. Remember \ that this space is public to view, but you must \ <a href="/accounts/register">register</a> or \ <a href="/accounts/login">login</a> to participate.' ), ) return space_object # Check if the user is in the admitted user groups of the space if has_space_permission(self.request.user, space_object, allow=["admins", "mods", "users"]): return space_object # If the user does not meet any of the conditions, it's not allowed to # enter the space if self.request.user.is_anonymous(): messages.info( self.request, _( 'You\'re an anonymous user. You must \ <a href="/accounts/register">register</a> or \ <a href="/accounts/login">login</a> to access here.' ), ) else: messages.warning( self.request, _( "You're not registered to this \ space." ), ) self.template_name = "not_allowed.html" return space_object
def get_context_data(self, **kwargs): context = super(ViewSpaceIndex, self).get_context_data(**kwargs) # Makes sure the space ins't already in the cache before hitting the # databass place_url = self.kwargs['space_url'] place = get_or_insert_object_in_cache(Space, place_url, url=place_url) posts_by_score = Comment.objects.filter(is_public=True) \ .values('object_pk').annotate(score=Count('id')).order_by('-score') post_ids = [int(obj['object_pk']) for obj in posts_by_score] top_posts = Post.objects.filter(space=place.id).in_bulk(post_ids) o_list = Comment.objects.annotate(ocount=Count('object_pk')) print o_list context['entities'] = Entity.objects.filter(space=place.id) context['documents'] = Document.objects.filter(space=place.id) context['proposalsets'] = ProposalSet.objects.filter(space=place.id) context['proposals'] = Proposal.objects.filter(space=place.id) \ .order_by('-pub_date') context['publication'] = Post.objects.filter(space=place.id) \ .order_by('-pub_date')[:5] context['mostviewed'] = Post.objects.filter(space=place.id) \ .order_by('-views')[:5] context['mostcommented'] = top_posts # context['mostcommented'] = sorted(o_list, # key=lambda k: k['ocount'])[:10] # print sorted(o_list, key=lambda k: k['ocount'])[:10] context['page'] = StaticPage.objects.filter(show_footer=True) \ .order_by('-order') context['messages'] = messages.get_messages(self.request) context['debates'] = Debate.objects.filter(space=place.id) \ .order_by('-date') context['event'] = Event.objects.filter(space=place.id) \ .order_by('-event_date') context['votings'] = Voting.objects.filter(space=place.id) context['polls'] = Poll.objects.filter(space=place.id) #True if the request.user has admin rights on this space context['user_is_admin'] = (self.request.user in place.admins.all() or self.request.user in place.mods.all() or self.request.user.is_staff or self.request.user.is_superuser) context['polls'] = Poll.objects.filter(space=place.id) return context
def get_context_data(self, **kwargs): context = super(ViewSpaceIndex, self).get_context_data(**kwargs) # Makes sure the space ins't already in the cache before hitting the # databass place_url = self.kwargs["space_url"] place = get_or_insert_object_in_cache(Space, place_url, url=place_url) """posts_by_score = Comment.objects.filter(is_public=True) \ .values('object_pk').annotate(score=Count('id')).order_by('-score')""" posts_by_score = ( Comment.objects.filter(is_public=True).values("object_pk").annotate(score=Count("id")).order_by("-score") ) post_ids = [int(obj["object_pk"]) for obj in posts_by_score] top_posts = Post.objects.filter(space=place.id).in_bulk(post_ids) # print top_posts.values()[0].title # o_list = Comment.objects.annotate(ocount=Count('object_pk')) context["entities"] = Entity.objects.filter(space=place.id) context["documents"] = Document.objects.filter(space=place.id) context["proposalsets"] = ProposalSet.objects.filter(space=place.id) context["proposals"] = Proposal.objects.filter(space=place.id).order_by("-pub_date") context["publication"] = Post.objects.filter(space=place.id).order_by("-pub_date")[:5] context["mostviewed"] = Post.objects.filter(space=place.id).order_by("-views")[:5] # context['mostcommented'] = [top_posts.get(id,None) for id in post_ids] context["mostcommented"] = filter(None, map(lambda x: top_posts.get(x, None), post_ids)) # context['mostcommented'] = sorted(o_list, # key=lambda k: k['ocount'])[:10] # print sorted(o_list, key=lambda k: k['ocount'])[:10] context["page"] = StaticPage.objects.filter(show_footer=True).order_by("-order") context["messages"] = messages.get_messages(self.request) context["debates"] = Debate.objects.filter(space=place.id).order_by("-date") context["event"] = Event.objects.filter(space=place.id).order_by("-event_date") context["votings"] = Voting.objects.filter(space=place.id) context["polls"] = Poll.objects.filter(space=place.id) # True if the request.user has admin rights on this space context["user_is_admin"] = ( self.request.user in place.admins.all() or self.request.user in place.mods.all() or self.request.user.is_staff or self.request.user.is_superuser ) context["polls"] = Poll.objects.filter(space=place.id) return context
def get_context_data(self, **kwargs): context = super(ViewSpaceIndex, self).get_context_data(**kwargs) # Makes sure the space ins't already in the cache before hitting the # databass place_url = self.kwargs['space_url'] place = get_or_insert_object_in_cache(Space, place_url, url=place_url) posts_by_score = Comment.objects.filter(is_public=True) \ .values('object_pk').annotate(score=Count('id')).order_by('-score') post_ids = [int(obj['object_pk']) for obj in posts_by_score] top_posts = Post.objects.filter(space=place.id).in_bulk(post_ids) o_list = Comment.objects.annotate(ocount=Count('object_pk')) print o_list context['entities'] = Entity.objects.filter(space=place.id) context['documents'] = Document.objects.filter(space=place.id) context['proposalsets'] = ProposalSet.objects.filter(space=place.id) context['proposals'] = Proposal.objects.filter(space=place.id) \ .order_by('-pub_date') context['publication'] = Post.objects.filter(space=place.id) \ .order_by('-pub_date')[:5] context['mostviewed'] = Post.objects.filter(space=place.id) \ .order_by('views')[:5] context['mostcommented'] = top_posts # context['mostcommented'] = sorted(o_list, # key=lambda k: k['ocount'])[:10] # print sorted(o_list, key=lambda k: k['ocount'])[:10] context['page'] = StaticPage.objects.filter(show_footer=True) \ .order_by('-order') context['messages'] = messages.get_messages(self.request) context['debates'] = Debate.objects.filter(space=place.id) \ .order_by('-date') context['event'] = Event.objects.filter(space=place.id) \ .order_by('-event_date') context['votings'] = Voting.objects.filter(space=place.id) context['polls'] = Poll.objects.filter(space=place.id) #True if the request.user has admin rights on this space context['user_is_admin'] = (self.request.user in place.admins.all() or self.request.user in place.mods.all() or self.request.user.is_staff or self.request.user.is_superuser) context['polls'] = Poll.objects.filter(space=place.id) return context
def get_object(self): # Makes sure the space ins't already in the cache before hitting the # databass space_url = self.kwargs['space_url'] space_object = get_or_insert_object_in_cache(Space, space_url, url=space_url) if has_space_permission(self.request.user, space_object, allow=['admins','mods']) \ or has_all_permissions(self.request.user): try: intent = Intent.objects.get(token=self.kwargs['token']) intent.space.users.add(intent.user) self.status = _("The user has been authorized to participate \ in space \"%s\"." % space_object.name) messages.success(self.request, _("Authorization successful")) except Intent.DoesNotExist: self.status = _("The requested intent does not exist!") return space_object
def get_object(self): # Makes sure the space ins't already in the cache before hitting # the database space_url = self.kwargs['space_url'] space_object = get_or_insert_object_in_cache(Space, space_url, url=space_url) if space_object.public or has_all_permissions(self.request.user): if self.request.user.is_anonymous(): messages.info( self.request, _("Hello anonymous user. Remember \ that this space is public to view, but you must \ <a href=\"/accounts/register\">register</a> or \ <a href=\"/accounts/login\">login</a> to participate.")) return space_object # Check if the user is in the admitted user groups of the space if has_space_permission(self.request.user, space_object, allow=['admins', 'mods', 'users']): return space_object # If the user does not meet any of the conditions, it's not allowed to # enter the space if self.request.user.is_anonymous(): messages.info( self.request, _("You're an anonymous user. You must \ <a href=\"/accounts/register\">register</a> or \ <a href=\"/accounts/login\">login</a> to access here.")) else: messages.warning( self.request, _("You're not registered to this \ space.")) self.template_name = 'not_allowed.html' return space_object
def get_object(self): # Makes sure the space ins't already in the cache before hitting the # databass space_url = self.kwargs['space_url'] space_object = get_or_insert_object_in_cache(Space, space_url, url=space_url) if has_space_permission(self.request.user, space_object, allow=['admins','mods']) \ or has_all_permissions(self.request.user): try: intent = Intent.objects.get(token=self.kwargs['token']) intent.space.users.add(intent.user) self.status = _("The user has been authorized to participate \ in space \"%s\"." % space_object.name) messages.success(self.request, _("Authorization successful")) except Intent.DoesNotExist: self.status = _("The requested intent does not exist!") return space_object
def get_context_data(self, **kwargs): context = super(ListPolls, self).get_context_data(**kwargs) key = self.kwargs['space_url'] space = get_or_insert_object_in_cache(Space, key, url=key) context['get_place'] = space return context
def get_context_data(self, **kwargs): context = super(ListPolls, self).get_context_data(**kwargs) key = self.kwargs['space_url'] space = get_or_insert_object_in_cache(Space, key, url=key) context['get_place'] = space return context
def get_queryset(self): key = self.kwargs['space_url'] current_space = get_or_insert_object_in_cache(Space, key, url=key) polls = Poll.objects.filter(space=current_space) return polls
def get_object(self): # Makes sure the space ins't already in the cache before hitting # the database space_url = self.kwargs['space_url'] space_object = get_or_insert_object_in_cache(Space, space_url, url=space_url) return space_object
def get_queryset(self): key = self.kwargs['space_url'] current_space = get_or_insert_object_in_cache(Space, key, url=key) votings = Voting.objects.filter(space=current_space) return votings
def get_queryset(self): key = self.kwargs['space_url'] current_space = get_or_insert_object_in_cache(Space, key, url=key) debates = Debate.objects.filter(space=current_space) return debates
def get_context_data(self, **kwargs): context = super(ListDebates, self).get_context_data(**kwargs) key = self.kwargs["space_url"] space = get_or_insert_object_in_cache(Space, key, url=key) context["get_place"] = space return context