3 from urllib import quote_plus, urlencode
\r
4 from django.db import models, IntegrityError, connection, transaction
\r
5 from django.utils.http import urlquote as django_urlquote
\r
6 from django.utils.html import strip_tags
\r
7 from django.core.urlresolvers import reverse
\r
8 from django.contrib.auth.models import User
\r
9 from django.contrib.contenttypes import generic
\r
10 from django.contrib.contenttypes.models import ContentType
\r
11 from django.template.defaultfilters import slugify
\r
12 from django.db.models.signals import post_delete, post_save, pre_save
\r
13 from django.utils.translation import ugettext as _
\r
14 from django.utils.safestring import mark_safe
\r
15 from django.contrib.sitemaps import ping_google
\r
16 import django.dispatch
\r
17 from django.conf import settings
\r
20 if settings.USE_SPHINX_SEARCH == True:
\r
21 from djangosphinx.models import SphinxSearch
\r
23 from forum.const import *
\r
25 class MetaContent(models.Model):
\r
27 Base class for Vote, Comment and FlaggedItem
\r
29 content_type = models.ForeignKey(ContentType)
\r
30 object_id = models.PositiveIntegerField()
\r
31 content_object = generic.GenericForeignKey('content_type', 'object_id')
\r
32 user = models.ForeignKey(User, related_name='%(class)ss')
\r
39 class DeletableContent(models.Model):
\r
40 deleted = models.BooleanField(default=False)
\r
41 deleted_at = models.DateTimeField(null=True, blank=True)
\r
42 deleted_by = models.ForeignKey(User, null=True, blank=True, related_name='deleted_%(class)ss')
\r
49 class ContentRevision(models.Model):
\r
51 Base class for QuestionRevision and AnswerRevision
\r
53 revision = models.PositiveIntegerField()
\r
54 author = models.ForeignKey(User, related_name='%(class)ss')
\r
55 revised_at = models.DateTimeField()
\r
56 summary = models.CharField(max_length=300, blank=True)
\r
57 text = models.TextField()
\r
64 class AnonymousContent(models.Model):
\r
66 Base class for AnonymousQuestion and AnonymousAnswer
\r
68 session_key = models.CharField(max_length=40) #session id for anonymous questions
\r
69 wiki = models.BooleanField(default=False)
\r
70 added_at = models.DateTimeField(default=datetime.datetime.now)
\r
71 ip_addr = models.IPAddressField(max_length=21) #allow high port numbers
\r
72 author = models.ForeignKey(User,null=True)
\r
73 text = models.TextField()
\r
74 summary = models.CharField(max_length=180)
\r
81 from meta import Comment, Vote, FlaggedItem
\r
83 class Content(models.Model):
\r
85 Base class for Question and Answer
\r
87 author = models.ForeignKey(User, related_name='%(class)ss')
\r
88 added_at = models.DateTimeField(default=datetime.datetime.now)
\r
90 wiki = models.BooleanField(default=False)
\r
91 wikified_at = models.DateTimeField(null=True, blank=True)
\r
93 locked = models.BooleanField(default=False)
\r
94 locked_by = models.ForeignKey(User, null=True, blank=True, related_name='locked_%(class)ss')
\r
95 locked_at = models.DateTimeField(null=True, blank=True)
\r
97 score = models.IntegerField(default=0)
\r
98 vote_up_count = models.IntegerField(default=0)
\r
99 vote_down_count = models.IntegerField(default=0)
\r
101 comment_count = models.PositiveIntegerField(default=0)
\r
102 offensive_flag_count = models.SmallIntegerField(default=0)
\r
104 last_edited_at = models.DateTimeField(null=True, blank=True)
\r
105 last_edited_by = models.ForeignKey(User, null=True, blank=True, related_name='last_edited_%(class)ss')
\r
107 html = models.TextField()
\r
108 comments = generic.GenericRelation(Comment)
\r
109 votes = generic.GenericRelation(Vote)
\r
110 flagged_items = generic.GenericRelation(FlaggedItem)
\r
114 app_label = 'forum'
\r
116 def save(self,**kwargs):
\r
117 super(Content,self).save(**kwargs)
\r
121 logging.debug('problem pinging google did you register you sitemap with google?')
\r
123 def get_object_comments(self):
\r
124 comments = self.comments.all().order_by('id')
\r
127 def post_get_last_update_info(self):
\r
128 when = self.added_at
\r
130 if self.last_edited_at and self.last_edited_at > when:
\r
131 when = self.last_edited_at
\r
132 who = self.last_edited_by
\r
133 comments = self.comments.all()
\r
134 if len(comments) > 0:
\r
136 if c.added_at > when:
\r