示例#1
0
    def import_threads(self):
        """import thread objects"""
        count = 0
        for osqa_thread in self.get_objects_for_model('forum.question'):
            count += 1
            #todo: there must be code lated to set the commented values
            lang = django_settings.LANGUAGE_CODE
            thread = Thread(
                title=osqa_thread.title,
                tagnames=osqa_thread.tagnames,
                view_count=osqa_thread.extra_count,
                #favourite_count=thread.favourite_count,
                #answer_count=thread.answer_count,
                last_activity_at=osqa_thread.last_activity_at,
                last_activity_by=self.get_imported_object_by_old_id(
                    User, osqa_thread.last_activity_by),
                language_code=lang,
                #"closed" data is stored differently in OSQA
                #closed_by=self.get_imported_object_by_old_id(User, thread.closed_by_id),
                #closed=thread.closed,
                #closed_at=thread.closed_at,
                #close_reason=thread.close_reason,
                #deleted=False,
                approved=True,  #no equivalent in OSQA
                #must be done later, after importing answers
                #answer_accepted_at=thread.answer_accepted_at,
                added_at=osqa_thread.added_at,
            )

            #apply tags to threads
            tag_names = thread.get_tag_names()
            if tag_names:

                tag_filter = Q(name__iexact=tag_names[0])
                for tag_name in tag_names[1:]:
                    tag_filter |= Q(name__iexact=tag_name)
                tags = Tag.objects.filter(tag_filter & Q(language_code=lang))

                thread.tagnames = ' '.join([tag.name for tag in tags])

                thread.save()
                for tag in tags:
                    thread.tags.add(tag)
                    tag.used_count += 1
                    tag.save()

            else:
                thread.save()

            self.log_action(osqa_thread, thread)
    def import_threads(self):
        """import thread objects"""
        count = 0
        for osqa_thread in self.get_objects_for_model('forum.question'):
            count += 1
            #todo: there must be code lated to set the commented values
            lang = django_settings.LANGUAGE_CODE
            thread = Thread(
                title=osqa_thread.title,
                tagnames=osqa_thread.tagnames,
                view_count=osqa_thread.extra_count,
                #favourite_count=thread.favourite_count,
                #answer_count=thread.answer_count,
                last_activity_at=osqa_thread.last_activity_at,
                last_activity_by=self.get_imported_object_by_old_id(User, osqa_thread.last_activity_by),
                language_code=lang,
                #"closed" data is stored differently in OSQA
                #closed_by=self.get_imported_object_by_old_id(User, thread.closed_by_id),
                #closed=thread.closed,
                #closed_at=thread.closed_at,
                #close_reason=thread.close_reason,
                #deleted=False,
                approved=True, #no equivalent in OSQA
                #must be done later, after importing answers
                #answer_accepted_at=thread.answer_accepted_at,
                added_at=osqa_thread.added_at,
            )

            #apply tags to threads
            tag_names = thread.get_tag_names()
            if tag_names:

                tag_filter = Q(name__iexact=tag_names[0])
                for tag_name in tag_names[1:]:
                    tag_filter |= Q(name__iexact=tag_name)
                tags = Tag.objects.filter(tag_filter & Q(language_code=lang))

                thread.tagnames = ' '.join([tag.name for tag in tags])

                thread.save()
                for tag in tags:
                    thread.tags.add(tag)
                    tag.used_count += 1
                    tag.save()

            else:
                thread.save()

            self.log_action(osqa_thread, thread)
    def import_threads(self):
        """import thread objects"""
        count = 0
        for thread in self.get_objects_for_model('askbot.thread'):
            count += 1
            new_thread = Thread(
                title=thread.title,
                tagnames=thread.tagnames,
                view_count=thread.view_count,
                favourite_count=thread.favourite_count,
                answer_count=thread.answer_count,
                last_activity_at=thread.last_activity_at,
                last_activity_by=self.get_imported_object_by_old_id(
                    User, thread.last_activity_by_id),
                language_code=thread.language_code,
                closed_by=self.get_imported_object_by_old_id(
                    User, thread.closed_by_id),
                closed=thread.closed,
                closed_at=thread.closed_at,
                close_reason=thread.close_reason,
                deleted=thread.deleted,
                approved=thread.approved,
                answer_accepted_at=thread.answer_accepted_at,
                added_at=thread.added_at,
            )

            #apply tags to threads
            tag_names = thread.get_tag_names()
            if tag_names:

                tag_filter = Q(name__iexact=tag_names[0])
                for tag_name in tag_names[1:]:
                    tag_filter |= Q(name__iexact=tag_name)
                tags = Tag.objects.filter(tag_filter & Q(
                    language_code=thread.language_code))

                new_thread.tagnames = ' '.join([tag.name for tag in tags])

                new_thread.save()
                for tag in tags:
                    new_thread.tags.add(tag)
                    tag.used_count += 1
                    tag.save()

            else:
                new_thread.save()

            self.log_action(thread, new_thread)
            """
    def import_threads(self):
        """import thread objects"""
        count = 0
        for thread in self.get_objects_for_model('askbot.thread'):
            count += 1
            new_thread = Thread(
                title=thread.title,
                tagnames=thread.tagnames,
                view_count=thread.view_count,
                favourite_count=thread.favourite_count,
                answer_count=thread.answer_count,
                last_activity_at=thread.last_activity_at,
                last_activity_by=self.get_imported_object_by_old_id(User, thread.last_activity_by_id),
                language_code=thread.language_code,
                closed_by=self.get_imported_object_by_old_id(User, thread.closed_by_id),
                closed=thread.closed,
                closed_at=thread.closed_at,
                close_reason=thread.close_reason,
                deleted=thread.deleted,
                approved=thread.approved,
                answer_accepted_at=thread.answer_accepted_at,
                added_at=thread.added_at,
            )

            #apply tags to threads
            tag_names = thread.get_tag_names()
            if tag_names:

                tag_filter = Q(name__iexact=tag_names[0])
                for tag_name in tag_names[1:]:
                    tag_filter |= Q(name__iexact=tag_name)
                tags = Tag.objects.filter(tag_filter & Q(language_code=thread.language_code))

                new_thread.tagnames = ' '.join([tag.name for tag in tags])

                new_thread.save()
                for tag in tags:
                    new_thread.tags.add(tag)
                    tag.used_count += 1
                    tag.save()

            else:
                new_thread.save()

            self.log_action(thread, new_thread)
            """
示例#5
0
#--------------------------------------------------------------------------------

class AskbotModelExtender(ModelExtender):

    ext_prefix = '_askbot_ext_'

#--------------------------------------------------------------------------------

class ThreadExtension(AskbotModelExtender):

    @property
    def _askbot_ext_question(self):
        return self._question_post()


Thread.add_to_class('ext_noattr', ThreadExtension())

#--------------------------------------------------------------------------------

class PostExtension(AskbotModelExtender):
 
    def _askbot_ext_is_comment_to_action(self):
        """ Check if the Post is a comment of a question.
        
        If the post is a question, self.get_parent_post()
        returns None anf an AttributeError has to be catched
        (the method will then return False)
        """
        rv = False
        # Use parent.is_question is OK because we are sure that parent is not None
        # (parent would be None if self.is_question())
示例#6
0
class AskbotModelExtender(ModelExtender):

    ext_prefix = '_askbot_ext_'


#--------------------------------------------------------------------------------


class ThreadExtension(AskbotModelExtender):
    @property
    def _askbot_ext_question(self):
        return self._question_post()


Thread.add_to_class('ext_noattr', ThreadExtension())

#--------------------------------------------------------------------------------


class PostExtension(AskbotModelExtender):
    def _askbot_ext_is_comment_to_action(self):
        """ Check if the Post is a comment of a question.
        
        If the post is a question, self.get_parent_post()
        returns None anf an AttributeError has to be catched
        (the method will then return False)
        """
        rv = False
        # Use parent.is_question is OK because we are sure that parent is not None
        # (parent would be None if self.is_question())