def group(request, gurl_number): group = Group.objects(url_number=gurl_number).get() if request.method == "POST": form = NewTopicForm(request.POST) if form.is_valid(): title = form.cleaned_data["title"] content = form.cleaned_data["content"] topic = Topic(title=title) turl_number = len(Topic.objects) + 1 topic.url_number = turl_number topic.content = content topic.creat_time = datetime.datetime.now() topic.is_active = True topic.is_locked = False topic.is_top = False topic.clicks = 0 topic.update_time = datetime.datetime.now() topic.update_author = request.user sgcard = S_G_Card.objects(user=request.user, group=group).get() topic.creator = sgcard topic.save() return HttpResponseRedirect("/group/" + str(gurl_number) + "/topic/" + str(turl_number) + "/") else: form = NewTopicForm() return render_to_response( "group/group.html", {"form": form, "group": group, "STATIC_URL": STATIC_URL, "current_user": request.user}, context_instance=RequestContext(request), )
def topic_create(request, slug): ''' 发表新帖子 ''' node = get_object_or_404(Node, slug=slug) form = CreateForm() if request.method == "POST": form = CreateForm(request.POST) if form.is_valid(): user = request.user topic = Topic(title=form.cleaned_data['title'], content=form.cleaned_data['content'], created=timezone.now(), node=node, author=user, reply_count=0, last_touched=timezone.now()) topic.save() return redirect(reverse('forum:index')) user = request.user # 发帖查重 if request.user.is_authenticated(): counter, notifications_count = user_info(request.user) active_page = 'topic' node_slug = node.slug update_reputation(user.id, -5) return render(request, 'topic/create.html', locals())
def save(self, commit=True): if not self.topic: # if this post create new topic, create this corresponding topic topic = Topic(forum=self.forum, title=escape(self.cleaned_data['title']), created_by=self.user, updated_by=self.user) topic.save() self.topic = topic topic_post = True else: topic = self.topic topic_post = False post = Post(topic=topic, created_by=self.user, updated_by=self.user, topic_post=topic_post, content=self.cleaned_data['content'], reply_on=self.parent) post.topic = topic if commit: post.save() if topic_post: topic.post = post topic.content = post.content topic.save() return post
def new_topic(request): user = request.user if request.method == 'POST': form = NewTopicForm(request.POST) if form.is_valid(): category = form.cleaned_data['category'] topic = Topic(title=form.cleaned_data['title'], author=user, category=category ) topic.save() first_post = Post(topic=topic, author=user, date_published=topic.date_published, content=form.cleaned_data['content']) first_post.save() return HttpResponseRedirect(topic.get_absolute_url()) else: form = NewTopicForm() return render(request, 'xadmin/new_topic.html', { 'form': form })
def import_topics(self): print "* Importing topics" rows = self._query("select * from smf_topics") for row in rows: topic = Topic( id=row['ID_TOPIC'], is_sticky=row['isSticky'], board=Board.objects.get(id=row['ID_BOARD'])) disable_auto_now(topic) topic.save()
def save(self): topic_post = False if not self.topic: topic = Topic(forum=self.forum, posted_by=self.user, subject=self.cleaned_data['subject']) topic_post = True topic.save() else: topic = self.topic post = Post(topic=topic, posted_by=self.user, poster_ip=self.ip, message=self.cleaned_data['message'], topic_post=topic_post) post.save() attachments = self.cleaned_data['attachments'] post.update_attachments(attachments) return post
def add_topic(request): t1 = Topic (topic_cat_id= request.POST['category'], topic_by_id=request.user.id, topic_date=timezone.now(), topic_name=request.POST['topic_name'],topic_desc=request.POST['topic_desc'], topic_views='0', topic_stars='0', topic_active='0') t1.save() if not request.user in t1.topic_subscribers.all(): t1.topic_subscribers.add(request.user) # Topic subscriptions t1.subscribes += 1 t1.save() ###content = "New topic Posted : "+ t1.topic_name +" by -"+ str(request.user) url = "http://test.archilane.com/forum/topic/" + str(t1.id) topic_subscribers = t1.topic_subscribers.all() module = 'add_topic' key = t1.pk Notification.save_notification(module, key, url,'forum','Topic','private',topic_subscribers) if t1.topic_cat.subscribes > 0: cat_subscribers = t1.topic_cat.cat_subscribers.all() Notification.save_notification(module, key, url,'forum','Category','private',cat_subscribers) return HttpResponse(t1.pk)
def post_create(request, slug=None): node = get_object_or_404(Node, slug=slug) form = CreateForm(request.POST) if not form.is_valid(): return get_create(request, slug=slug, errors=form.errors) user = request.user try: last_created = user.topic_author.all().order_by('-created')[0] except IndexError: last_created = None if last_created: # 如果用户最后一篇的标题内容与提交的相同 last_created_fingerprint = hashlib.sha1(last_created.title + \ last_created.content + str(last_created.node_id)).hexdigest() new_created_fingerprint = hashlib.sha1(form.cleaned_data.get('title') + \ form.cleaned_data.get('content') + str(node.id)).hexdigest() if last_created_fingerprint == new_created_fingerprint: errors = {'duplicated_topic': [u'帖子重复提交']} return get_create(request, slug=slug, errors=errors) now = timezone.now() topic = Topic( title = form.cleaned_data.get('title'), content = form.cleaned_data.get('content'), created = now, node = node, author = user, reply_count = 0, last_touched = now, ) topic.save() reputation = user.reputation or 0 reputation = reputation - 5 # 每次发布话题扣除用户威望5点 reputation = 0 if reputation < 0 else reputation ForumUser.objects.filter(pk=user.id).update(reputation=reputation) return redirect('/')
def new_topic(request, slug): form = TopicForm() forum = get_object_or_404(Forum, slug=slug) if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = form.cleaned_data['description'] topic.forum = forum topic.creator = request.user topic.save() return HttpResponseRedirect(reverse('forum:forum-detail', args=(forum.slug, ))) context = get_base_context() context.update({'form': form, 'forum': forum}) return render(request, 'forum/new-topic.html', context)
def new_topic(request, forum_id): form = TopicForm() forum = get_object_or_404(Forum, pk=forum_id) if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = form.cleaned_data['description'] topic.forum = forum topic.creator = request.user topic.save() return HttpResponseRedirect(reverse('forum-detail', args=(forum_id, ))) return render_to_response('django_simple_forum/new-topic.html', { 'form': form, 'forum': forum, }, context_instance=RequestContext(request))
def save(self): # Create the new topic new_topic = Topic(forum=self.topic.forum, name=self.cleaned_data["name"]) new_topic.save() # Move posts to the new topic self.topic.posts.filter(pk__in=self.cleaned_data["posts"]).update(topic=new_topic) # Update the new topic stats new_topic.first_post = new_topic.posts.order_by("date")[0] new_topic.update_posts_count() new_topic.update_last_post() new_topic.save() # Update the old topic stats self.topic.first_post = self.topic.posts.order_by("date")[0] self.topic.update_posts_count() self.topic.update_last_post() self.topic.save() # Inform subscribed users about the new topic inform_new_topic(new_topic) return new_topic
def new_topic(request, forum_id): form = TopicForm() forum = get_object_or_404(Forum, pk=forum_id) user = request.user if forum.closed and not user.has_perm('forum.can_post_lock_forum'): return render(request, 'personal/basic.html', {'content':['This forum is locked.']}) if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = bleach_clean(form.cleaned_data['description']) topic.forum = forum topic.creator = user topic.save() tpkPost = Post() tpkPost.topic = topic tpkPost.title = topic.title tpkPost.body = bleach_clean(form.cleaned_data['description']) tpkPost.creator = user tpkPost.user_ip = get_client_ip(request) tpkPost.save() return HttpResponseRedirect(reverse('topic-detail', args=(topic.id, topic.slug, ))) return render_to_response('forum/new-topic.html', { 'form': form, 'forum': forum, }, context_instance=RequestContext(request))
def main(request): if request.method == "POST": post = json.loads(request.body) if "newTopic" in post.keys(): new_topic = post['newTopic'] topic = Topic(name=new_topic) topic.save() topics = [{"id": x.pk, "name": x.name} for x in Topic.objects.all()] return HttpResponse(json.dumps(topics)) # deleting topics, never actually implemented client side # probably will never implement this feature, as a design choice if "topicID" in post.keys(): tID = post['topicID'] try: Topic.objects.get(pk=tID).delete() except Exception: return HttpResponse("server Error") return HttpResponse("") # searching for posts by title # a more complex algorithm can be employed here, but nah. Maybe later name = post['postName'] posts = [ {"title": x.title, "id": x.id} for x in Post.objects.filter(title__contains=name) ] return HttpResponse(json.dumps(posts)) # loads all topics when loading the forum page posts = [ {"title": x.title, "id": x.id} for x in Post.objects.all() ] return render(request, "forum/forum.html", context={"posts": posts})
def handle(self, *args, **options): username = options['user'] user = User.objects.get(username=username) manager, _created = Group.objects.get_or_create(name="manager") manager.save() user.groups.add(manager) tmpnode = self._add_section(ForumSection) if tmpnode: about = Topic(node=tmpnode, author=user, title="about") about.save() privacy = Topic(node=tmpnode, author=user, title="privacy") privacy.save() credit = Topic(node=tmpnode, author=user, title="credit") credit.save() t = Topic(node=tmpnode, author=user, title="topic") t.save()
def new_topic(request, forum_id): form = TopicForm() forum = get_object_or_404(Forum, pk=forum_id) if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = form.cleaned_data['description'] topic.forum = forum topic.creator = request.user userToUpdate = UserProfile.objects.get(user=request.user) nCredits = userToUpdate.credits userToUpdate.credits = int(float(nCredits + 200)) # TODO: Change status (if points+100>threshold -> status changes) # Alert? Maybe return to page with status update info for user. # Make Gold/Platinum distinction if nCredits + 200 >= GOLD_THRESHOLD: newStatus = "Gold" userToUpdate.status = newStatus userToUpdate.save() topic.save() return render_to_response( "forum/status_change.html", {'status': newStatus}, context_instance=RequestContext(request)) elif nCredits + 100 >= PLATINUM_THRESHOLD: newStatus = "Platinum" userToUpdate.status = newStatus userToUpdate.save() topic.save() return render_to_response( "forum/status_change.html", {'status': newStatus}, context_instance=RequestContext(request)) else: userToUpdate.save() topic.save() return HttpResponseRedirect( reverse('forum-detail', args=(forum_id, ))) return render_to_response('forum/new-topic.html', { 'form': form, 'forum': forum, }, context_instance=RequestContext(request))
def new_topic(request, forum_id): form = TopicForm() forum = get_object_or_404(Forum, pk=forum_id) if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = form.cleaned_data['description'] topic.forum = forum topic.creator = request.user userToUpdate = UserProfile.objects.get(user=request.user) nCredits = userToUpdate.credits userToUpdate.credits = int(float(nCredits + 200)) # TODO: Change status (if points+100>threshold -> status changes) # Alert? Maybe return to page with status update info for user. # Make Gold/Platinum distinction if nCredits + 200 >= GOLD_THRESHOLD: newStatus = "Gold" userToUpdate.status = newStatus userToUpdate.save() topic.save() return render_to_response("forum/status_change.html", {'status': newStatus}, context_instance=RequestContext(request)) elif nCredits + 100 >= PLATINUM_THRESHOLD: newStatus = "Platinum" userToUpdate.status = newStatus userToUpdate.save() topic.save() return render_to_response("forum/status_change.html", {'status': newStatus}, context_instance=RequestContext(request)) else: userToUpdate.save() topic.save() return HttpResponseRedirect(reverse('forum-detail', args=(forum_id, ))) return render_to_response('forum/new-topic.html', { 'form': form, 'forum': forum, }, context_instance=RequestContext(request))
def forum_board(request, board): # Generate a table entry for this topic if it does not already exist. topic_field_str = "" if board == "general": topic_field_str = "gen" elif board == "strategy": topic_field_str = "strat" elif board == "site-suggestions": topic_field_str = "sitesug" elif board == "other": topic_field_str = "other" topic = Topic.objects.filter(type=topic_field_str) #print(topic.count()) if (topic.count() == 0): topic = Topic(type=topic_field_str) topic.save() topic = Topic.objects.get(type=topic_field_str) threads = DiscussionThread.objects.filter(posted_under=topic) if board == "general": data = { "title": "Forum - General", "forum_topic": FORUM_TOPICS[0][1], "topic_description": FORUM_TOPIC_DESCRIPTION[0], "new_thread_topic": "general", "forum_board": "general" } elif board == "strategy": data = { "title": "Forum - Strategy", "forum_topic": FORUM_TOPICS[1][1], "topic_description": FORUM_TOPIC_DESCRIPTION[1], "new_thread_topic": "strategy", "forum_board": "strategy" } elif board == "site-suggestions": data = { "title": "Forum - Site Suggestions", "forum_topic": FORUM_TOPICS[2][1], "topic_description": FORUM_TOPIC_DESCRIPTION[2], "new_thread_topic": "site-suggestions", "forum_board": "site-suggestions" } elif board == "other": data = { "title": "Forum - Other", "forum_topic": FORUM_TOPICS[3][1], "topic_description": FORUM_TOPIC_DESCRIPTION[3], "new_thread_topic": "other", "forum_board": "other" } thread_data = [] # <QuerySet [{'id': 1, 'title': 'fasdfdfasadsf', 'posted_under_id': 1, 'user_id': 2, 'paragraph': 'dfasasdfasdfasdfasdf'}]> for thread in threads: # Go through thread data, and create tuple(s) accordingly thread_data.append( (thread.title, User.objects.get(id=thread.user_id), thread.id)) data["threads"] = thread_data return render(request, "forum/forumboard.html", data)
def save(self, user): newTopic = Topic(title=self.cleaned_data['title'], description=self.cleaned_data['description'], pub_date=timezone.now(), creator=user) newTopic.save() return newTopic
def create_topic(request): """ desc: Create a new topic params: str topic_title, post_text, int tag_id return: bool success, int topic_id, str topic_title, str topic_author """ response = { 'success': False, 'topic_id': -1, 'topic_title': '', 'topic_author': '', 'topic_date': '', } # Validate input if valid_request(request): topic_title = request.POST['topic_title'] tag_id = request.POST['tag_id'] post_text = request.POST['post_text'] date = timezone.now() if topic_title and tag_id and post_text: tag = Tag.objects.get(pk=tag_id) new_topic = Topic( title=topic_title, author=request.user, post_date=date, last_post=date ) new_topic.save() tag_topic = TagTopic.objects.create( tag=tag, topic=new_topic, date_added=date ) tag_topic.save() new_post = Post( text=post_text, author=request.user, post_date=date ) new_post.save() topic_post = TopicPost.objects.create( topic=new_topic, post=new_post, date_added=date ) # Set the response response['topic_id'] = new_topic.id response['topic_title'] = new_topic.title response['topic_author'] = new_topic.author.username response['topic_date'] = date # Everything was successful! response['success'] = True # Return results return JsonResponse(response)
def new_topic(request, forum_id): if 'userid' in request.session: form = TopicForm() forum = get_object_or_404(Forum, pk=forum_id) status = 'student' stud_obj = student.objects.get(pk=request.session['userid']) username = stud_obj.uname if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = form.cleaned_data['description'] topic.forum = forum obj = student.objects.get(pk=request.session['userid']) topic.creator = obj topic.save() return HttpResponseRedirect( reverse('forum-detail', args=(forum_id, ))) return render( request, 'forum/new-topic.html', { 'form': form, 'forum': forum, 'username': username, 'status': status }, ) elif 'instructorid' in request.session: form = TopicForm() forum = get_object_or_404(Forum, pk=forum_id) status = 'instructor' inst_obj = instructor.objects.get(pk=request.session['instructorid']) username = inst_obj.uname if request.method == 'POST': form = TopicForm(request.POST) if form.is_valid(): topic = Topic() topic.title = form.cleaned_data['title'] topic.description = form.cleaned_data['description'] topic.forum = forum obj = instructor.objects.get( pk=request.session['instructorid']) topic.by_instructor = obj topic.save() return HttpResponseRedirect( reverse('forum-detail', args=(forum_id, ))) return render( request, 'forum/new-topic.html', { 'form': form, 'forum': forum, 'username': username, 'status': status }, ) else: return HttpResponseRedirect('/joinus/login/')
def add_topic(request): t1 = Topic (topic_cat_id= request.POST['category'], topic_by_id=request.user.id, topic_date=datetime.datetime.now(),#timezone.now(), topic_name=request.POST['topic_name'],topic_desc=request.POST['topic_desc'], topic_views='0', topic_stars='0', topic_active='0') t1.save() return HttpResponseRedirect("/forum/topic/%d" % t1.id)