def get_context_data(self, **kwargs): context = super(ForumsView, self).get_context_data(**kwargs) self.public_forums = [] self.users_forums = [] self.groups_forums = [] if ENABLE_PRIVATE_FORUMS is True: all_forums = Forum.objects.filter(is_active=True).prefetch_related('topics', 'authorized_groups') for forum in all_forums: if user_can_see_forum(forum, self.request.user) is True: if forum.is_restricted_to_groups is True: self.groups_forums += [forum] else: if forum.is_public is True: self.public_forums += [forum] else: self.users_forums += [forum] else: self.public_forums = Forum.objects.filter(is_active=True).prefetch_related('topics') is_moderator = user_is_moderator(self.request.user) if is_moderator: event_classes = ['Forum post'] model = Post context['num_items_in_queue'] = MEvent.objects.count_for_model(model, event_classes) context['public_forums'] = self.public_forums context['users_forums'] = self.users_forums context['groups_forums'] = self.groups_forums context['is_moderator'] = is_moderator return context
def switch_open_topic(request, topic_pk, action): if request.is_ajax(): is_moderator = user_is_moderator(request.user) if not is_moderator: raise Http404 try: topic=Topic.objects.get(pk=int(topic_pk)) except: MEvent.objects.create( name = "Can not retrieve post ('switch_open_post' view)", event_class ="Warning", request = request, ) return if int(action) == 0: topic.is_closed = True elif int(action) == 1: topic.is_closed = False topic.save() return render_to_response('mgof/topic/switch_open.html', {'topic': topic}, content_type="application/xhtml+xml" ) else: raise Http404
def get_context_data(self, **kwargs): context = super(ForumsView, self).get_context_data(**kwargs) self.public_forums = [] self.users_forums = [] self.groups_forums = [] if ENABLE_PRIVATE_FORUMS is True: all_forums = Forum.objects.filter(is_active=True).prefetch_related( 'topics', 'authorized_groups') for forum in all_forums: if user_can_see_forum(forum, self.request.user) is True: if forum.is_restricted_to_groups is True: self.groups_forums += [forum] else: if forum.is_public is True: self.public_forums += [forum] else: self.users_forums += [forum] else: self.public_forums = Forum.objects.filter( is_active=True).prefetch_related('topics') is_moderator = user_is_moderator(self.request.user) if is_moderator: event_classes = ['Forum post'] model = Post context['num_items_in_queue'] = MEvent.objects.count_for_model( model, event_classes) context['public_forums'] = self.public_forums context['users_forums'] = self.users_forums context['groups_forums'] = self.groups_forums context['is_moderator'] = is_moderator return context
def get_queryset(self): is_moderator = user_is_moderator(self.request.user) if not is_moderator: raise Http404 event_classes = ['Forum post'] model = Post qs = MEvent.objects.events_for_model(model, event_classes).select_related('user') return qs
def get_queryset(self): is_moderator = user_is_moderator(self.request.user) if not is_moderator: raise Http404 event_classes = ['Forum post'] model = Post qs = MEvent.objects.events_for_model( model, event_classes).select_related('user') return qs
def form_valid(self, form, **kwargs): is_moderator = user_is_moderator(self.request.user) if self.request.method == "POST": if self.topic.is_closed: raise Http404 topic = self.topic post_pk = self.kwargs['post_pk'] #~ get posts for topic self.posts = Post.objects.filter(topic=self.topic, is_active=True) #~ get related post information try: post_responded_to = self.posts.filter(pk=post_pk)[0] post_responded_to_username = post_responded_to.posted_by.username post_responded_to_pk = post_responded_to.posted_by.pk except: post_responded_to_username = '' post_responded_to_pk = 0 obj = form.save(commit=False) #~ handle meta info obj.editor = self.request.user obj.posted_by = self.request.user obj.responded_to_pk = post_responded_to_pk obj.responded_to_username = post_responded_to_username obj.topic = topic obj.content = clean_post_data(obj.content) obj.is_active = True #~ counts for topic topic.num_posts = topic.num_posts + 1 topic.last_post_date = timezone.now() topic.last_post_username = self.request.user.username #topic.status = 0 topic.save() #~ counts for forum forum = topic.forum forum.num_posts = forum.num_posts + 1 forum.last_post_date = timezone.now() forum.last_post_username = self.request.user.username forum.save() self.post = obj # moderation check if topic.is_moderated and is_moderator is False: obj.save() MEvent.objects.create(model=Post, name='Post from forum : ' + obj.topic.title, instance=obj, user=obj.posted_by, event_class='Forum post', request=self.request, notes=obj.content) self.messages.success(_(u'Your post has been saved'), extra_tags='save text-info fa-2x') else: raise Http404 return super(AddPostView, self).form_valid(form)
def form_valid(self, form, **kwargs): is_moderator = user_is_moderator(self.request.user) if self.request.method == "POST": if self.topic.is_closed: raise Http404 topic = self.topic post_pk = self.kwargs['post_pk'] #~ get posts for topic self.posts = Post.objects.filter(topic=self.topic, is_active=True) #~ get related post information try: post_responded_to = self.posts.filter(pk=post_pk)[0] post_responded_to_username = post_responded_to.posted_by.username post_responded_to_pk = post_responded_to.posted_by.pk except: post_responded_to_username = '' post_responded_to_pk = 0 obj = form.save(commit=False) #~ handle meta info obj.editor = self.request.user obj.posted_by = self.request.user obj.responded_to_pk = post_responded_to_pk obj.responded_to_username = post_responded_to_username obj.topic = topic obj.content = clean_post_data(obj.content) obj.is_active = True #~ counts for topic topic.num_posts = topic.num_posts+1 topic.last_post_date = timezone.now() topic.last_post_username = self.request.user.username #topic.status = 0 topic.save() #~ counts for forum forum = topic.forum forum.num_posts = forum.num_posts+1 forum.last_post_date = timezone.now() forum.last_post_username = self.request.user.username forum.save() self.post = obj # moderation check if topic.is_moderated and is_moderator is False: obj.save() MEvent.objects.create( model = Post, name = 'Post from forum : '+obj.topic.title, instance = obj, user = obj.posted_by, event_class = 'Forum post', request = self.request, notes = obj.content ) self.messages.success(_(u'Your post has been saved'), extra_tags='save text-info fa-2x') else: raise Http404 return super(AddPostView, self).form_valid(form)
def get_context_data(self, **kwargs): is_moderator = user_is_moderator(self.request.user) context = super(TopicView, self).get_context_data(**kwargs) #~ does it come from the moderation queue? if 'm' in self.request.GET.keys() and is_moderator: #~ get the moderated post number if 'p' in self.request.GET.keys(): context['post_to_moderate_pk'] = int(self.request.GET['p']) context['comes_from_moderation'] = True context['forum'] = self.forum context['topic'] = self.topic return context
def get_context_data(self, **kwargs): context = super(ForumsView, self).get_context_data(**kwargs) if ENABLE_PRIVATE_FORUMS: all_forums = Forum.objects.filter(status=0).prefetch_related('topics', 'authorized_groups') visible_forums = [] for forum in all_forums: if user_can_see_forum(forum, self.request.user): visible_forums += [forum] else: visible_forums = all_forums = Forum.objects.filter(status=0).prefetch_related('topics') is_moderator = user_is_moderator(self.request.user) if is_moderator: event_classes = ['Forum post'] model = Post context['num_items_in_queue'] = MEvent.objects.count_for_model(model, event_classes) context['forums'] = visible_forums context['is_moderator'] = is_moderator return context
def form_valid(self, form, **kwargs): is_moderator = user_is_moderator(self.request.user) if self.request.method == "POST": if self.topic.is_closed: raise Http404 topic = self.topic post_pk = self.kwargs['post_pk'] #~ get posts for topic self.posts = Post.objects.filter(topic=self.topic, status=0) #~ get related post information try: post_responded_to = self.posts.filter(pk=post_pk)[0] post_responded_to_username = post_responded_to.posted_by.username post_responded_to_pk = post_responded_to.posted_by.pk except: post_responded_to_username = '' post_responded_to_pk = 0 obj = form.save(commit=False) #~ handle meta info obj.editor = self.request.user obj.posted_by = self.request.user obj.responded_to_pk = post_responded_to_pk obj.responded_to_username = post_responded_to_username obj.topic = topic obj.content = clean_post_data(obj.content) obj.status = 0 #~ counts for topic topic.num_posts = topic.num_posts + 1 topic.last_post_date = timezone.now() topic.last_post_username = self.request.user.username topic.status = 0 topic.save() #~ counts for forum forum = topic.forum forum.num_posts = forum.num_posts + 1 forum.last_post_date = timezone.now() forum.last_post_username = self.request.user.username forum.save() self.messages.success(_(u'Your post has been saved'), extra_tags='save text-info fa-2x') else: raise Http404 self.post = obj return super(AddPostView, self).form_valid(form)
def moderate_post(request, post_pk, action): if request.is_ajax(): is_moderator = user_is_moderator(request.user) if not is_moderator: raise Http404 #~ retrieve post try: post = Post.objects.get(pk=post_pk) except Post.ObjectDoesNotExist: if settings.DEBUG: return HttpResponse('Post not found') else: return HttpResponse('') #~ prepare action msg = '' predelete_post = post del_event = False if action == '0': del_event = True msg = _(u'Post rejected') elif action == '1': del_event = True msg = _(u'Post validated') #~ delete event if del_event: event = None events = MEvent.objects.events_for_object(predelete_post) for event in events: if event.event_class == "Forum post": event = event break if not event: if settings.DEBUG: return HttpResponse('Event not found ' + str(events)) else: return HttpResponse('') event.delete() #~ process action if action == '0': post.delete() return render_to_response('mgof/post/moderate_success_actionbar.html', {'message': msg}) else: raise Http404
def moderate_post(request, post_pk, action): if request.is_ajax(): is_moderator = user_is_moderator(request.user) if not is_moderator: raise Http404 #~ retrieve post try: post = Post.objects.get(pk=post_pk) except Post.ObjectDoesNotExist: if settings.DEBUG: return HttpResponse('Post not found') else: return HttpResponse('') #~ prepare action msg = '' predelete_post = post del_event = False if action == '0': del_event = True msg = _(u'Post rejected') elif action == '1': del_event = True msg = _(u'Post validated') #~ delete event if del_event: event = None events = MEvent.objects.events_for_object(predelete_post) for event in events: if event.event_class == "Forum post": event = event break if not event: if settings.DEBUG: return HttpResponse('Event not found '+str(events)) else: return HttpResponse('') event.delete() #~ process action if action == '0': post.delete() return render_to_response('mgof/post/moderate_success_actionbar.html', {'message':msg}) else: raise Http404
def form_valid(self, form, **kwargs): is_moderator = user_is_moderator(self.request.user) if self.request.method == "POST": if self.topic.is_closed: raise Http404 topic = self.topic post_pk = self.kwargs['post_pk'] #~ get posts for topic self.posts = Post.objects.filter(topic=self.topic, status=0) #~ get related post information try: post_responded_to = self.posts.filter(pk=post_pk)[0] post_responded_to_username = post_responded_to.posted_by.username post_responded_to_pk = post_responded_to.posted_by.pk except: post_responded_to_username = '' post_responded_to_pk = 0 obj = form.save(commit=False) #~ handle meta info obj.editor = self.request.user obj.posted_by = self.request.user obj.responded_to_pk = post_responded_to_pk obj.responded_to_username = post_responded_to_username obj.topic = topic obj.content = clean_post_data(obj.content) obj.status = 0 #~ counts for topic topic.num_posts = topic.num_posts+1 topic.last_post_date = timezone.now() topic.last_post_username = self.request.user.username topic.status = 0 topic.save() #~ counts for forum forum = topic.forum forum.num_posts = forum.num_posts+1 forum.last_post_date = timezone.now() forum.last_post_username = self.request.user.username forum.save() self.messages.success(_(u'Your post has been saved'), extra_tags='save text-info fa-2x') else: raise Http404 self.post = obj return super(AddPostView, self).form_valid(form)
def set_topic_monitoring_level(request, topic_pk, monitoring_level): if request.is_ajax(): if request.user.is_anonymous(): raise Http404 is_moderator = user_is_moderator(request.user) if not is_moderator: raise Http404 topic = Topic.objects.get(pk=topic_pk) topic.is_moderated = True if int(monitoring_level) == 0: topic.is_moderated = False topic.save() return render_to_response('mgof/topic/set_monitoring.html', {'monitoring_level': monitoring_level, 'topic': topic}, content_type="application/xhtml+xml" ) else: if settings.DEBUG: print "Not ajax request for the 'set_topic_monitoring_level' view" raise Http404
def set_topic_monitoring_level(request, topic_pk, monitoring_level): if request.is_ajax(): if request.user.is_anonymous(): raise Http404 is_moderator = user_is_moderator(request.user) if not is_moderator: raise Http404 topic = Topic.objects.get(pk=topic_pk) topic.is_moderated = True if int(monitoring_level) == 0: topic.is_moderated = False topic.save() return render_to_response('mgof/topic/set_monitoring.html', { 'monitoring_level': monitoring_level, 'topic': topic }, content_type="application/xhtml+xml") else: if settings.DEBUG: print "Not ajax request for the 'set_topic_monitoring_level' view" raise Http404
def get_context_data(self, **kwargs): context = super(ForumsView, self).get_context_data(**kwargs) if ENABLE_PRIVATE_FORUMS: all_forums = Forum.objects.filter(status=0).prefetch_related( 'topics', 'authorized_groups') visible_forums = [] for forum in all_forums: if user_can_see_forum(forum, self.request.user): visible_forums += [forum] else: visible_forums = all_forums = Forum.objects.filter( status=0).prefetch_related('topics') is_moderator = user_is_moderator(self.request.user) if is_moderator: event_classes = ['Forum post'] model = Post context['num_items_in_queue'] = MEvent.objects.count_for_model( model, event_classes) context['forums'] = visible_forums context['is_moderator'] = is_moderator return context
def switch_open_topic(request, topic_pk, action): if request.is_ajax(): is_moderator = user_is_moderator(request.user) if not is_moderator: raise Http404 try: topic = Topic.objects.get(pk=int(topic_pk)) except: MEvent.objects.create( name="Can not retrieve post ('switch_open_post' view)", event_class="Warning", request=request, ) return if int(action) == 0: topic.is_closed = True elif int(action) == 1: topic.is_closed = False topic.save() return render_to_response('mgof/topic/switch_open.html', {'topic': topic}, content_type="application/xhtml+xml") else: raise Http404
def get_context_data(self, **kwargs): context = super(ForumView, self).get_context_data(**kwargs) context['forum'] = self.forum context['is_moderator'] = user_is_moderator(self.request.user) return context