diff options
-rwxr-xr-x | forum/auth.py | 4 | ||||
-rwxr-xr-x | forum/models/__init__.py | 22 | ||||
-rwxr-xr-x | forum/models/question.py | 3 | ||||
-rw-r--r-- | stackexchange/management/commands/load_stackexchange.py | 7 |
4 files changed, 20 insertions, 16 deletions
diff --git a/forum/auth.py b/forum/auth.py index b034cc8d..5d6e71c4 100755 --- a/forum/auth.py +++ b/forum/auth.py @@ -10,8 +10,7 @@ from django.db import transaction from models import Repute from models import Question from models import Answer -#todo: why can't I import these? -#from models import mark_offensive, delete_post_or_answer +from models import mark_offensive, delete_post_or_answer from const import TYPE_REPUTATION import logging @@ -257,7 +256,6 @@ def onFlaggedItem(item, post, user, timestamp=None): mark_by=user ) - @transaction.commit_on_success def onAnswerAccept(answer, user, timestamp=None): if timestamp is None: diff --git a/forum/models/__init__.py b/forum/models/__init__.py index ef591702..ddb21319 100755 --- a/forum/models/__init__.py +++ b/forum/models/__init__.py @@ -8,9 +8,20 @@ import re from base import * import datetime -from forum import auth from django.contrib.contenttypes.models import ContentType +#todo: move to a separate file? +# custom signals +tags_updated = django.dispatch.Signal(providing_args=["question"]) +edit_question_or_answer = django.dispatch.Signal(providing_args=["instance", "modified_by"]) +delete_post_or_answer = django.dispatch.Signal(providing_args=["instance", "deleted_by"]) +mark_offensive = django.dispatch.Signal(providing_args=["instance", "mark_by"]) +user_updated = django.dispatch.Signal(providing_args=["instance", "updated_by"]) +user_logged_in = django.dispatch.Signal(providing_args=["session"]) + +#todo: must go after signals +from forum import auth + # User extend properties QUESTIONS_PER_PAGE_CHOICES = ( (10, u'10'), @@ -72,15 +83,6 @@ User.add_to_class('tag_filter_setting', ) ) -# custom signal -tags_updated = django.dispatch.Signal(providing_args=["question"]) -edit_question_or_answer = django.dispatch.Signal(providing_args=["instance", "modified_by"]) -delete_post_or_answer = django.dispatch.Signal(providing_args=["instance", "deleted_by"]) -mark_offensive = django.dispatch.Signal(providing_args=["instance", "mark_by"]) -user_updated = django.dispatch.Signal(providing_args=["instance", "updated_by"]) -user_logged_in = django.dispatch.Signal(providing_args=["session"]) - - def get_messages(self): messages = [] for m in self.message_set.all(): diff --git a/forum/models/question.py b/forum/models/question.py index f4d4ac2e..68cd5293 100755 --- a/forum/models/question.py +++ b/forum/models/question.py @@ -70,6 +70,9 @@ class QuestionManager(models.Manager): return False + #todo: why not make this into a method of class Question? + # also it is actually strange - why do we need the answer_count + # field if the count depends on who is requesting this? def update_answer_count(self, question): """ Executes an UPDATE query to update denormalised data with the diff --git a/stackexchange/management/commands/load_stackexchange.py b/stackexchange/management/commands/load_stackexchange.py index 11b0efc9..afe4b9ea 100644 --- a/stackexchange/management/commands/load_stackexchange.py +++ b/stackexchange/management/commands/load_stackexchange.py @@ -30,6 +30,7 @@ xml_read_order = ( #association tables SE item id --> OSQA item id #table associations are implied +#todo: there is an issue that these may be inconsistent with the database USER = {}#SE User.id --> django(OSQA) User.id QUESTION = {} ANSWER = {} @@ -383,7 +384,7 @@ class Command(BaseCommand): ) QUESTION[rev_group[0].post.id] = q elif post_type == 'Answer': - q = QUESTION[rev_group[0].post.parent.id] + q = X.get_post(rev_group[0].post.parent) a = osqa.Answer.objects.create_new( question = q, author = author, @@ -419,7 +420,7 @@ class Command(BaseCommand): post_type = rev0.post.post_type.name if post_type == 'Question': - q = QUESTION[rev0.post.id] + q = X.get_post(rev0.post) q.apply_edit( edited_at = edited_at, edited_by = edited_by, @@ -429,7 +430,7 @@ class Command(BaseCommand): tags = tags, ) elif post_type == 'Answer': - a = ANSWER[rev0.post.id] + a = X.get_post(rev0.post) a.apply_edit( edited_at = edited_at, edited_by = edited_by, |