summaryrefslogtreecommitdiffstats
path: root/forum/models
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-05-29 01:47:05 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2010-05-29 01:47:05 -0400
commit43e656cd594ee1debbdae924e0badd1b51066f63 (patch)
tree141aa920fe46445a97d792c518bff7b065b377f3 /forum/models
parent2b91e229af078324d33e0e982142c51af7d5242d (diff)
downloadaskbot-43e656cd594ee1debbdae924e0badd1b51066f63.tar.gz
askbot-43e656cd594ee1debbdae924e0badd1b51066f63.tar.bz2
askbot-43e656cd594ee1debbdae924e0badd1b51066f63.zip
got some basic unit tests to work, now need more coverage
Diffstat (limited to 'forum/models')
-rw-r--r--forum/models/__init__.py22
-rw-r--r--forum/models/answer.py4
-rw-r--r--forum/models/base.py121
-rw-r--r--forum/models/content.py124
-rw-r--r--forum/models/meta.py4
-rw-r--r--forum/models/question.py3
-rw-r--r--forum/models/repute.py1
-rw-r--r--forum/models/user.py16
8 files changed, 151 insertions, 144 deletions
diff --git a/forum/models/__init__.py b/forum/models/__init__.py
index 6085ce5a..0c0914ec 100644
--- a/forum/models/__init__.py
+++ b/forum/models/__init__.py
@@ -4,7 +4,7 @@ from answer import Answer, AnonymousAnswer, AnswerRevision
from tag import Tag, MarkedTag
from meta import Vote, Comment, FlaggedItem
from user import Activity, ValidationHash, EmailFeedSetting
-from user import AuthKeyUserAssociation
+#from user import AuthKeyUserAssociation
from repute import Badge, Award, Repute
from django.core.urlresolvers import reverse
from django.core.mail import EmailMessage
@@ -270,7 +270,7 @@ def send_instant_notifications_about_activity_in_post(
}
template = loader.get_template('instant_notification.html')
- for u in set(receiving_users) + set(newly_mentioned_users):
+ for u in set(receiving_users) | set(newly_mentioned_users):
if u.should_receive_instant_notification_about_post(
post,
newly_mentioned_users = newly_mentioned_users
@@ -497,11 +497,11 @@ def record_answer_accepted(instance, created, **kwargs):
content_object=instance,
activity_type=const.TYPE_ACTIVITY_MARK_ANSWER
)
+ activity.save()
receiving_users = instance.get_author_list(
exclude_list = [instance.question.author]
)
activity.receiving_users.add(*receiving_users)
- activity.save()
def update_last_seen(instance, created, **kwargs):
"""
@@ -685,7 +685,7 @@ Repute = Repute
Activity = Activity
EmailFeedSetting = EmailFeedSetting
ValidationHash = ValidationHash
-AuthKeyUserAssociation = AuthKeyUserAssociation
+#AuthKeyUserAssociation = AuthKeyUserAssociation
__all__ = [
'signals',
@@ -713,15 +713,15 @@ __all__ = [
'Activity',
'EmailFeedSetting',
'ValidationHash',
- 'AuthKeyUserAssociation',
+ #'AuthKeyUserAssociation',
'User',
]
-from forum.modules import get_modules_script_classes
-
-for k, v in get_modules_script_classes('models', models.Model).items():
- if not k in __all__:
- __all__.append(k)
- exec "%s = v" % k
+#from forum.modules import get_modules_script_classes
+#
+#for k, v in get_modules_script_classes('models', models.Model).items():
+# if not k in __all__:
+# __all__.append(k)
+# exec "%s = v" % k
diff --git a/forum/models/answer.py b/forum/models/answer.py
index 9179226f..3f52b4ab 100644
--- a/forum/models/answer.py
+++ b/forum/models/answer.py
@@ -1,4 +1,5 @@
-from base import Content, AnonymousContent, ContentRevision, DeletableContent
+from base import AnonymousContent, ContentRevision, DeletableContent
+from content import Content
#todo: take care of copy-paste markdowner stuff maybe make html automatic field?
from forum import const
from markdown2 import Markdown
@@ -7,6 +8,7 @@ from forum.utils.html import sanitize_html
from django.db import models
from django.utils.http import urlquote as django_urlquote
from django.template.defaultfilters import slugify
+from django.core.urlresolvers import reverse
import datetime
markdowner = Markdown(html4tags=True)
diff --git a/forum/models/base.py b/forum/models/base.py
index e276c6ee..e90bc7a0 100644
--- a/forum/models/base.py
+++ b/forum/models/base.py
@@ -161,124 +161,3 @@ class AnonymousContent(models.Model):
class Meta:
abstract = True
app_label = 'forum'
-
-
-from meta import Comment, Vote, FlaggedItem
-
-class Content(models.Model):
- """
- Base class for Question and Answer
- """
- author = models.ForeignKey(User, related_name='%(class)ss')
- added_at = models.DateTimeField(default=datetime.datetime.now)
-
- wiki = models.BooleanField(default=False)
- wikified_at = models.DateTimeField(null=True, blank=True)
-
- locked = models.BooleanField(default=False)
- locked_by = models.ForeignKey(User, null=True, blank=True, related_name='locked_%(class)ss')
- locked_at = models.DateTimeField(null=True, blank=True)
-
- score = models.IntegerField(default=0)
- vote_up_count = models.IntegerField(default=0)
- vote_down_count = models.IntegerField(default=0)
-
- comment_count = models.PositiveIntegerField(default=0)
- offensive_flag_count = models.SmallIntegerField(default=0)
-
- last_edited_at = models.DateTimeField(null=True, blank=True)
- last_edited_by = models.ForeignKey(User, null=True, blank=True, related_name='last_edited_%(class)ss')
-
- html = models.TextField(null=True)#html rendition of the latest revision
- text = models.TextField(null=True)#denormalized copy of latest revision
- comments = generic.GenericRelation(Comment)
- votes = generic.GenericRelation(Vote)
- flagged_items = generic.GenericRelation(FlaggedItem)
-
- class Meta:
- abstract = True
- app_label = 'forum'
-
- def save(self,**kwargs):
- super(Content,self).save(**kwargs)
- try:
- ping_google()
- except Exception:
- logging.debug('problem pinging google did you register you sitemap with google?')
-
- def get_comments(self):
- comments = self.comments.all().order_by('id')
- return comments
-
- #todo: maybe remove this wnen post models are unified
- def get_text(self):
- return self.text
-
- def add_comment(self, comment=None, user=None, added_at=None):
- if added_at is None:
- added_at = datetime.datetime.now()
- if None in (comment ,user):
- raise Exception('arguments comment and user are required')
-
- Comment = models.get_model('forum','Comment')#todo: forum hardcoded
- comment = Comment(
- content_object=self,
- comment=comment,
- user=user,
- added_at=added_at
- )
- comment.save()
- self.comment_count = self.comment_count + 1
- self.save()
-
- def get_latest_revision(self):
- return self.revisions.all().order_by('-revised_at')[0]
-
- def get_latest_revision_number(self):
- return self.get_latest_revision().revision
-
- def get_last_author(self):
- return self.last_edited_by
-
- def get_author_list(self, include_comments = False, recursive = False, exclude_list = None):
- authors = set()
- authors.update([r.author for r in self.revisions.all()])
- if include_comments:
- authors.update([c.user for c in self.comments.all()])
- if recursive:
- if hasattr(self, 'answers'):
- for a in self.answers.exclude(deleted = True):
- authors.update(a.get_author_list( include_comments = include_comments ) )
- if exclude_list:
- authors -= set(exclude_list)
- return list(authors)
-
- def passes_tag_filter_for_user(self, user):
- tags = self.get_origin_post().tags.all()
-
- if self.tag_filter_setting == 'interesting':
- #at least some of the tags must be marked interesting
- return self.tag_selections.exists(tag__in = tags, reason = 'good')
-
- elif self.tag_filter_setting == 'ignored':
- #at least one tag must be ignored
- if self.tag_selections.exists(tag__in = tags, reason = 'bad'):
- return False
- else:
- return True
-
- else:
- raise Exception('unexpected User.tag_filter_setting %' % self.tag_filter_setting)
- def post_get_last_update_info(self):#todo: rename this subroutine
- when = self.added_at
- who = self.author
- if self.last_edited_at and self.last_edited_at > when:
- when = self.last_edited_at
- who = self.last_edited_by
- comments = self.comments.all()
- if len(comments) > 0:
- for c in comments:
- if c.added_at > when:
- when = c.added_at
- who = c.user
- return when, who
diff --git a/forum/models/content.py b/forum/models/content.py
new file mode 100644
index 00000000..95064692
--- /dev/null
+++ b/forum/models/content.py
@@ -0,0 +1,124 @@
+from django.contrib.auth.models import User
+from django.contrib.contenttypes import generic
+from django.db import models
+from meta import Comment, Vote, FlaggedItem
+import datetime
+import logging
+
+class Content(models.Model):
+ """
+ Base class for Question and Answer
+ """
+ author = models.ForeignKey(User, related_name='%(class)ss')
+ added_at = models.DateTimeField(default=datetime.datetime.now)
+
+ wiki = models.BooleanField(default=False)
+ wikified_at = models.DateTimeField(null=True, blank=True)
+
+ locked = models.BooleanField(default=False)
+ locked_by = models.ForeignKey(User, null=True, blank=True, related_name='locked_%(class)ss')
+ locked_at = models.DateTimeField(null=True, blank=True)
+
+ score = models.IntegerField(default=0)
+ vote_up_count = models.IntegerField(default=0)
+ vote_down_count = models.IntegerField(default=0)
+
+ comment_count = models.PositiveIntegerField(default=0)
+ offensive_flag_count = models.SmallIntegerField(default=0)
+
+ last_edited_at = models.DateTimeField(null=True, blank=True)
+ last_edited_by = models.ForeignKey(User, null=True, blank=True, related_name='last_edited_%(class)ss')
+
+ html = models.TextField(null=True)#html rendition of the latest revision
+ text = models.TextField(null=True)#denormalized copy of latest revision
+ comments = generic.GenericRelation(Comment)
+ votes = generic.GenericRelation(Vote)
+ flagged_items = generic.GenericRelation(FlaggedItem)
+
+ class Meta:
+ abstract = True
+ app_label = 'forum'
+
+ def save(self,**kwargs):
+ super(Content,self).save(**kwargs)
+ try:
+ ping_google()
+ except Exception:
+ logging.debug('problem pinging google did you register you sitemap with google?')
+
+ def get_comments(self):
+ comments = self.comments.all().order_by('id')
+ return comments
+
+ #todo: maybe remove this wnen post models are unified
+ def get_text(self):
+ return self.text
+
+ def add_comment(self, comment=None, user=None, added_at=None):
+ if added_at is None:
+ added_at = datetime.datetime.now()
+ if None in (comment ,user):
+ raise Exception('arguments comment and user are required')
+
+ #Comment = models.get_model('forum','Comment')#todo: forum hardcoded
+ comment = Comment(
+ content_object=self,
+ comment=comment,
+ user=user,
+ added_at=added_at
+ )
+ comment.save()
+ self.comment_count = self.comment_count + 1
+ self.save()
+
+ def get_latest_revision(self):
+ return self.revisions.all().order_by('-revised_at')[0]
+
+ def get_latest_revision_number(self):
+ return self.get_latest_revision().revision
+
+ def get_last_author(self):
+ return self.last_edited_by
+
+ def get_author_list(self, include_comments = False, recursive = False, exclude_list = None):
+ authors = set()
+ authors.update([r.author for r in self.revisions.all()])
+ if include_comments:
+ authors.update([c.user for c in self.comments.all()])
+ if recursive:
+ if hasattr(self, 'answers'):
+ for a in self.answers.exclude(deleted = True):
+ authors.update(a.get_author_list( include_comments = include_comments ) )
+ if exclude_list:
+ authors -= set(exclude_list)
+ return list(authors)
+
+ def passes_tag_filter_for_user(self, user):
+ tags = self.get_origin_post().tags.all()
+
+ if self.tag_filter_setting == 'interesting':
+ #at least some of the tags must be marked interesting
+ return self.tag_selections.exists(tag__in = tags, reason = 'good')
+
+ elif self.tag_filter_setting == 'ignored':
+ #at least one tag must be ignored
+ if self.tag_selections.exists(tag__in = tags, reason = 'bad'):
+ return False
+ else:
+ return True
+
+ else:
+ raise Exception('unexpected User.tag_filter_setting %' % self.tag_filter_setting)
+ def post_get_last_update_info(self):#todo: rename this subroutine
+ when = self.added_at
+ who = self.author
+ if self.last_edited_at and self.last_edited_at > when:
+ when = self.last_edited_at
+ who = self.last_edited_by
+ comments = self.comments.all()
+ if len(comments) > 0:
+ for c in comments:
+ if c.added_at > when:
+ when = c.added_at
+ who = c.user
+ return when, who
diff --git a/forum/models/meta.py b/forum/models/meta.py
index c72bd948..2781d160 100644
--- a/forum/models/meta.py
+++ b/forum/models/meta.py
@@ -112,12 +112,12 @@ class Comment(MetaContent, UserContent):
users = set()
users.update(
#get authors of parent object and all associated comments
- comment.content_object.get_author_list(
+ self.content_object.get_author_list(
include_comments = True,
)
)
- users -= set([comment.user])#remove activity user
+ users -= set([self.user])#remove activity user
return list(users)
def delete(self, **kwargs):
diff --git a/forum/models/question.py b/forum/models/question.py
index 0f46e55a..6a36e0aa 100644
--- a/forum/models/question.py
+++ b/forum/models/question.py
@@ -1,4 +1,5 @@
-from base import Content, DeletableContent, AnonymousContent, ContentRevision
+from base import DeletableContent, AnonymousContent, ContentRevision
+from content import Content
from forum.models import signals
from tag import Tag
from forum import const
diff --git a/forum/models/repute.py b/forum/models/repute.py
index ad640f59..bc6bec1d 100644
--- a/forum/models/repute.py
+++ b/forum/models/repute.py
@@ -5,6 +5,7 @@ from django.db import models
from django.utils.translation import ugettext as _
import datetime
from forum import const
+from django.core.urlresolvers import reverse
class Badge(models.Model):
"""Awarded for notable actions performed on the site by Users."""
diff --git a/forum/models/user.py b/forum/models/user.py
index 85e22f1d..c6f95505 100644
--- a/forum/models/user.py
+++ b/forum/models/user.py
@@ -357,11 +357,11 @@ class ValidationHash(models.Model):
def __str__(self):
return self.hash_code
-class AuthKeyUserAssociation(models.Model):
- key = models.CharField(max_length=255,null=False,unique=True)
- provider = models.CharField(max_length=64)#string 'yahoo', 'google', etc.
- user = models.ForeignKey(User, related_name="auth_keys")
- added_at = models.DateTimeField(default=datetime.datetime.now)
-
- class Meta:
- app_label = 'forum'
+#class AuthKeyUserAssociation(models.Model):
+# key = models.CharField(max_length=255,null=False,unique=True)
+# provider = models.CharField(max_length=64)#string 'yahoo', 'google', etc.
+# user = models.ForeignKey(User, related_name="auth_keys")
+# added_at = models.DateTimeField(default=datetime.datetime.now)
+#
+# class Meta:
+# app_label = 'forum'