diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-11-08 00:39:32 -0500 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-11-08 00:39:32 -0500 |
commit | 96a7854e151235bbc553cf3ffa26cd2b21e32dfa (patch) | |
tree | ecdf330b91d6aa71ed6ee8b07e49b40d5e14377a /askbot/migrations_api | |
parent | ae53fef954ff88a3b594c14a84639a679b6d6dc1 (diff) | |
download | askbot-96a7854e151235bbc553cf3ffa26cd2b21e32dfa.tar.gz askbot-96a7854e151235bbc553cf3ffa26cd2b21e32dfa.tar.bz2 askbot-96a7854e151235bbc553cf3ffa26cd2b21e32dfa.zip |
inbox with persistent responses and flags sort of works, but neds testing on correctness
Diffstat (limited to 'askbot/migrations_api')
-rw-r--r-- | askbot/migrations_api/__init__.py | 10 | ||||
-rw-r--r-- | askbot/migrations_api/version1.py | 63 |
2 files changed, 73 insertions, 0 deletions
diff --git a/askbot/migrations_api/__init__.py b/askbot/migrations_api/__init__.py new file mode 100644 index 00000000..1e213613 --- /dev/null +++ b/askbot/migrations_api/__init__.py @@ -0,0 +1,10 @@ +"""this module serves as a helper for the South orm +by mitigating absence of access to the django model api + +since models change with time, this api is implemented in different +versions. Different versions do not need to have all the same functions. +""" + +class BaseAPI(object): + def __init__(self, orm): + self.orm = orm diff --git a/askbot/migrations_api/version1.py b/askbot/migrations_api/version1.py new file mode 100644 index 00000000..cc63c09d --- /dev/null +++ b/askbot/migrations_api/version1.py @@ -0,0 +1,63 @@ +"""Version 1 of API helper for the south orm +usage of this api implementation starts with migration 24 +""" +from askbot.migrations_api import BaseAPI +from django.db import models +#from django.contrib.contenttypes.models import ContentType + +class API(BaseAPI): + def get_origin_post_from_content_object(self, parent): + """follows relations from the parent object + until origin post (question) is found + starting point is always ``parent.content_object`` + """ + model = parent.content_type.model + id = parent.object_id + #print 'model is ' + model + if model == 'question': + return self.orm.Question.objects.get(id=id) + elif model == 'answer': + return self.orm.Answer.objects.get(id=id).question + elif model == 'favoritequestion': + try: + return self.orm.FavoriteQuestion.objects.get(id=id).question + except self.orm.FavoriteQuestion.DoesNotExist: + #ignore this issue for now + return None + elif model == 'answerrevision': + return self.orm.AnswerRevision.objects.get(id=id).answer.question + elif model == 'questionrevision': + return self.orm.QuestionRevision.objects.get(id=id).question + elif model == 'comment': + comment = self.orm.Comment.objects.get(id=id) + return self.get_question_from_generic_relation(comment) + else: + #print 'dropped migration of activity in %s' % model + return None + + def get_moderators_and_admins(self): + """return list of forum moderators and django site admins + """ + filter_expression = models.Q(status='m') | models.Q(is_superuser=True) + return self.orm['auth.User'].objects.filter(filter_expression) + + def get_activity_items_for_object(self, instance): + """get all activity items that have content_object set + where ``<Activity instance>.content_object == instance`` + """ + return self.orm.Activity.objects.filter( + object_id = instance.id, + content_type = self.get_content_type_for_model(instance) + ) + + def get_content_type_for_model(self, instance): + ct = self.orm['contenttypes.ContentType'].objects + return ct.get(app_label='askbot', model=instance._meta.object_name.lower()) + + def add_recipients_to_activity(self, recipients, activity): + for recipient in recipients: + memo = self.orm.ActivityAuditStatus( + user = recipient, + activity = activity, + ) + memo.save() |