def newtopic(request, forum_id): request.user.forum_last_act = datetime.datetime.now() request.user.save() f = get_object_or_404(Forum, pk=forum_id) g = f.category c = g.chapter user = request.user if (user.is_superuser) or (g.exec_only == False) or (user.is_staff and ((c == user.chapter) or (c == None))): if request.method == 'POST': topicform = NewTopicForm(request.POST) if topicform.is_valid(): data = topicform.cleaned_data newTopic = Topic() newTopic.forum = f newTopic.posted_by = user newTopic.subject = data['subject'] newTopic.last_post_time = datetime.datetime.now() newTopic.last_post_user = user if Topic.objects.filter(forum=newTopic.forum, subject=newTopic.subject): msg = 'A similar topic already exists' request.user.message_set.create(message=unicode(_(msg))) else: newTopic.save() postMessage = Post() postMessage.topic = newTopic postMessage.posted_by = user postMessage.message = data['message'] postMessage.save() f.num_topics = f.num_topics + 1 f.num_posts = f.num_posts + 1 f.last_post_time = datetime.datetime.now() f.last_post_user = user f.save() else: request.user.message_set.create(message=unicode(_('The fields "New Topic" and "Message" can not be empty'))) else: raise Http404 if 'return' in request.GET: return HttpResponseRedirect(request.GET['return']) elif 'return' in request.POST: return HttpResponseRedirect(request.POST['return']) elif c: return HttpResponseRedirect('/forums/' + c.myrobogals_url + '/forum/' + str(f.pk) + '/') else: return HttpResponseRedirect('/forums/' + request.user.chapter.myrobogals_url + '/forum/' + str(f.pk) + '/') else: raise Http404
def newpost(request, topic_id): request.user.forum_last_act = datetime.datetime.now() request.user.save() user = request.user t = get_object_or_404(Topic, pk=topic_id) f = t.forum g = f.category c = g.chapter if (user.is_superuser) or (g.exec_only == False) or (user.is_staff and ((c == user.chapter) or (c == None))): if request.method == 'POST': postform = WritePostForm(request.POST) if postform.is_valid(): data = postform.cleaned_data postMessage = Post() postMessage.topic = t postMessage.posted_by = user postMessage.message = data['message'] postMessage.save() t.num_views = t.num_views - 1 t.num_replies = t.num_replies + 1 t.last_post_time = datetime.datetime.now() t.last_post_user = user t.save() f.num_posts = f.num_posts + 1 f.last_post_time = datetime.datetime.now() f.last_post_user = user f.save() else: request.user.message_set.create(message=unicode(_('The fields "Message" can not be empty'))) else: raise Http404 if 'return' in request.GET: return HttpResponseRedirect(request.GET['return']) elif 'return' in request.POST: return HttpResponseRedirect(request.POST['return']) elif c: return HttpResponseRedirect('/forums/' + c.myrobogals_url + '/topic/' + str(t.pk) + '/') else: return HttpResponseRedirect('/forums/' + request.user.chapter.myrobogals_url + '/topic/' + str(t.pk) + '/') else: raise Http404
def newpost(request, topic_id): request.user.forum_last_act = datetime.datetime.now() request.user.save() user = request.user t = get_object_or_404(Topic, pk=topic_id) f = t.forum g = f.category c = g.chapter if (user.is_superuser) or (user.is_staff and ((c == user.chapter) or (c == None))) or ((c == user.chapter) and (g.exec_only == False)) or ((c == None) and (g.exec_only == False)): if request.method == 'POST': postform = WritePostForm(request.POST) if postform.is_valid(): data = postform.cleaned_data postMessage = Post() postMessage.topic = t postMessage.posted_by = user postMessage.message = data['message'] postMessage.save() t.num_views = t.num_views - 1 t.last_post_time = datetime.datetime.now() t.last_post_user = user t.save() f.last_post_time = datetime.datetime.now() f.last_post_user = user f.save() if 'watch' in request.POST: if request.POST['watch'] == '1': if not f.watchers.filter(pk=user.pk): t.watchers.add(user) else: if f.watchers.filter(pk=user.pk): f.watchers.remove(user) for topic in f.topic_set.all(): if topic != t: topic.watchers.add(user) else: topic.watchers.remove(user) else: t.watchers.remove(user) watchers = (f.watchers.all() | t.watchers.all()).distinct().exclude(pk=request.user.pk) if watchers: message = EmailMessage() message.subject = 'New Post for topic "' + t.subject + '"' message.body = 'New post for topic "' + t.subject + '" for forum "' + f.name + '" in category "' + g.name + '"\n\nPost message: (posted by ' + postMessage.posted_by.get_full_name() + ')\n' + postMessage.message message.from_name = "myRobogals" message.from_address = "*****@*****.**" message.reply_address = "*****@*****.**" message.sender = User.objects.get(pk=1692) #need to change message.html = False message.email_type = 1 message.status = -1 message.save() for watcher in watchers: recipient = EmailRecipient() recipient.message = message recipient.user = watcher recipient.to_name = watcher.get_full_name() recipient.to_address = watcher.email recipient.save() message.status = 0 message.save() else: request.user.message_set.create(message=unicode(_('- The field "Message" can not be empty'))) else: raise Http404 if 'return' in request.GET: return HttpResponseRedirect(request.GET['return']) elif 'return' in request.POST: return HttpResponseRedirect(request.POST['return']) elif c: return HttpResponseRedirect('/forums/' + c.myrobogals_url + '/topic/' + str(t.pk) + '/') else: return HttpResponseRedirect('/forums/' + request.user.chapter.myrobogals_url + '/topic/' + str(t.pk) + '/') else: raise Http404
def newtopic(request, forum_id): request.user.forum_last_act = datetime.datetime.now() request.user.save() f = get_object_or_404(Forum, pk=forum_id) g = f.category c = g.chapter user = request.user if (user.is_superuser) or (user.is_staff and ((c == user.chapter) or (c == None))) or ((c == user.chapter) and (g.exec_only == False)) or ((c == None) and (g.exec_only == False)): if request.method == 'POST': topicform = NewTopicForm(request.POST) if topicform.is_valid(): data = topicform.cleaned_data newTopic = Topic() newTopic.forum = f newTopic.posted_by = user newTopic.subject = data['subject'] newTopic.last_post_time = datetime.datetime.now() newTopic.last_post_user = user if Topic.objects.filter(forum=newTopic.forum, subject=newTopic.subject): msg = '- A similar topic already exists' request.user.message_set.create(message=unicode(_(msg))) else: newTopic.save() postMessage = Post() postMessage.topic = newTopic postMessage.posted_by = user postMessage.message = data['message'] postMessage.save() f.last_post_time = datetime.datetime.now() f.last_post_user = user f.save() watchers = f.watchers.all().exclude(pk=request.user.pk) if watchers: message = EmailMessage() message.subject = 'New Topic: ' + newTopic.subject message.body = 'New topic for forum "' + f.name + '" in category "' + g.name +'"\n\nTopic subject: ' + newTopic.subject + ' (started by ' + newTopic.posted_by.get_full_name() + ')\n\nTopic Message:\n' + postMessage.message message.from_name = "myRobogals" message.from_address = "*****@*****.**" message.reply_address = "*****@*****.**" message.sender = User.objects.get(username='******') message.html = False message.email_type = 1 message.status = -1 message.save() for watcher in watchers: recipient = EmailRecipient() recipient.message = message recipient.user = watcher recipient.to_name = watcher.get_full_name() recipient.to_address = watcher.email recipient.save() message.status = 0 message.save() else: request.user.message_set.create(message=unicode(_('- The fields "New Topic" and "Message" can not be empty'))) else: raise Http404 if 'return' in request.GET: return HttpResponseRedirect(request.GET['return']) elif 'return' in request.POST: return HttpResponseRedirect(request.POST['return']) elif c: return HttpResponseRedirect('/forums/' + c.myrobogals_url + '/forum/' + str(f.pk) + '/') else: return HttpResponseRedirect('/forums/' + request.user.chapter.myrobogals_url + '/forum/' + str(f.pk) + '/') else: raise Http404