Mercurial > public > sg101
comparison gpp/forums/tools.py @ 228:d77e0dc772ad
Implement #88; add option to create a new forum thread from a new calendar entry.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 11 Jul 2010 21:03:41 +0000 |
parents | 152d77265da6 |
children | 8fd4984d5c3b |
comparison
equal
deleted
inserted
replaced
227:423c39ee44e0 | 228:d77e0dc772ad |
---|---|
1 """ | 1 """ |
2 This module contains misc. utility functions for forum management. | 2 This module contains misc. utility functions for forum management. |
3 """ | 3 """ |
4 import logging | |
5 | |
4 from forums.models import Post, Topic, Forum, ForumLastVisit, TopicLastVisit | 6 from forums.models import Post, Topic, Forum, ForumLastVisit, TopicLastVisit |
5 | 7 |
6 | 8 |
7 def delete_user_posts(user): | 9 def delete_user_posts(user): |
8 """ | 10 """ |
65 | 67 |
66 # delete all the last visit records for this user | 68 # delete all the last visit records for this user |
67 TopicLastVisit.objects.filter(user=user).delete() | 69 TopicLastVisit.objects.filter(user=user).delete() |
68 ForumLastVisit.objects.filter(user=user).delete() | 70 ForumLastVisit.objects.filter(user=user).delete() |
69 | 71 |
72 | |
73 def create_topic(forum_slug, user, topic_name, post_body, ip='', sticky=False, | |
74 locked=False): | |
75 """Programmatically create a topic & first post in a given forum. | |
76 | |
77 This function creates a new topic in the forum that has the slug | |
78 specified by the 'forum_slug' argument. Other arguments are as follows: | |
79 'user' - create the topic and post with this user as the owner | |
80 'topic_name' - topic name (title) | |
81 'post_body' - topic post body (as markup, not HTML) | |
82 'ip' - IP address for the post (as a string) | |
83 'sticky' - if True, the post will be stickied | |
84 'locked' - if True, the post will be locked | |
85 | |
86 """ | |
87 try: | |
88 forum = Forum.objects.get(slug=forum_slug) | |
89 except Forum.DoesNotExist: | |
90 logging.error('could not create_topic for forum_slug=%s' % forum_slug) | |
91 raise | |
92 | |
93 topic = Topic(forum=forum, | |
94 name=topic_name, | |
95 user=user, | |
96 sticky=sticky, | |
97 locked=locked) | |
98 topic.save() | |
99 | |
100 post = Post(topic=topic, | |
101 user=user, | |
102 body=post_body, | |
103 user_ip=ip) | |
104 post.save() |