diff options
Diffstat (limited to 'forum/managers.py')
-rw-r--r-- | forum/managers.py | 47 |
1 files changed, 11 insertions, 36 deletions
diff --git a/forum/managers.py b/forum/managers.py index 06fae761..1504491a 100644 --- a/forum/managers.py +++ b/forum/managers.py @@ -7,28 +7,6 @@ from forum.models import * from urllib import quote, unquote class QuestionManager(models.Manager): -<<<<<<< HEAD:forum/managers.py - def get_translation_questions(self, orderby, page_size): - questions = self.filter(deleted=False, author__id__in=[28,29]).order_by(orderby)[:page_size] - return questions - - def get_questions_by_pagesize(self, orderby, page_size): - questions = self.filter(deleted=False).order_by(orderby)[:page_size] - return questions - - def get_questions_by_tag(self, tagname, orderby): - questions = self.filter(deleted=False, tags__name = unquote(tagname)).order_by(orderby) - return questions - - def get_unanswered_questions(self, orderby): - questions = self.filter(deleted=False, answer_accepted=False).order_by(orderby) - return questions - - def get_questions(self, orderby): - questions = self.filter(deleted=False).order_by(orderby) - return questions -======= ->>>>>>> 82d35490db90878f013523c4d1a5ec3af2df8b23:forum/managers.py def update_tags(self, question, tagnames, user): """ @@ -95,20 +73,12 @@ class QuestionManager(models.Manager): Questions with the individual tags will be added to list if above questions are not full. """ #print datetime.datetime.now() -<<<<<<< HEAD:forum/managers.py from forum.models import Question - questions = list(Question.objects.filter(tagnames = question.tagnames, deleted=False).all()) - - tags_list = question.tags.all() - for tag in tags_list: - extend_questions = Question.objects.filter(tags__id = tag.id, deleted=False)[:50] -======= questions = list(self.filter(tagnames = question.tagnames, deleted=False).all()) tags_list = question.tags.all() for tag in tags_list: extend_questions = self.filter(tags__id = tag.id, deleted=False)[:50] ->>>>>>> 82d35490db90878f013523c4d1a5ec3af2df8b23:forum/managers.py for item in extend_questions: if item not in questions and len(questions) < 10: questions.append(item) @@ -177,17 +147,22 @@ class TagManager(models.Manager): class AnswerManager(models.Manager): GET_ANSWERS_FROM_USER_QUESTIONS = u'SELECT answer.* FROM answer INNER JOIN question ON answer.question_id = question.id WHERE question.author_id =%s AND answer.author_id <> %s' - def get_answers_from_question(self, question, user=None): + def get_answers_from_question(self, question, user=None, other_orderby = None): """ Retrieves visibile answers for the given question. Delete answers are only visibile to the person who deleted them. - """ - + """ if user is None or not user.is_authenticated(): - return self.filter(question=question, deleted=False) + q = self.filter(question=question, deleted=False) else: - return self.filter(Q(question=question), - Q(deleted=False) | Q(deleted_by=user)) + q = self.filter(Q(question=question), + Q(deleted=False) | Q(deleted_by=user)) + if other_orderby is None: + q = q.order_by("-accepted") + else: + q = q.order_by("-accepted", other_orderby) + + return q def get_answers_from_questions(self, user_id): """ |