Exemplo n.º 1
0
    def create_new(self,
                   title,
                   author,
                   added_at,
                   wiki,
                   text,
                   tagnames=None,
                   is_anonymous=False,
                   by_email=False,
                   email_address=None):
        """creates new thread"""
        # TODO: Some of this code will go to Post.objects.create_new

        thread = super(ThreadManager, self).create(title=title,
                                                   tagnames=tagnames,
                                                   last_activity_at=added_at,
                                                   last_activity_by=author)

        #todo: code below looks like ``Post.objects.create_new()``
        question = Post(
            post_type='question',
            thread=thread,
            author=author,
            added_at=added_at,
            wiki=wiki,
            is_anonymous=is_anonymous,
            #html field is denormalized in .save() call
            text=text,
            #summary field is denormalized in .save() call
        )
        if question.wiki:
            #DATED COMMENT
            #todo: this is confusing - last_edited_at field
            #is used as an indicator whether question has been edited
            #but in principle, post creation should count as edit as well
            question.last_edited_by = question.author
            question.last_edited_at = added_at
            question.wikified_at = added_at

        question.parse_and_save(author=author)

        question.add_revision(author=author,
                              is_anonymous=is_anonymous,
                              text=text,
                              comment=const.POST_STATUS['default_version'],
                              revised_at=added_at,
                              by_email=by_email,
                              email_address=email_address)

        # INFO: Question has to be saved before update_tags() is called
        thread.update_tags(tagnames=tagnames, user=author, timestamp=added_at)

        return thread
Exemplo n.º 2
0
    def create_new(self, title, author, added_at, wiki, text, tagnames=None, is_anonymous=False):
        # TODO: Some of this code will go to Post.objects.create_new

        thread = super(
            ThreadManager,
            self
        ).create(
            title=title,
            tagnames=tagnames,
            last_activity_at=added_at,
            last_activity_by=author
        )

        question = Post(
            post_type='question',
            thread=thread,
            author = author,
            added_at = added_at,
            wiki = wiki,
            is_anonymous = is_anonymous,
            #html field is denormalized in .save() call
            text = text,
            #summary field is denormalized in .save() call
        )
        if question.wiki:
            #DATED COMMENT
            #todo: this is confusing - last_edited_at field
            #is used as an indicator whether question has been edited
            #but in principle, post creation should count as edit as well
            question.last_edited_by = question.author
            question.last_edited_at = added_at
            question.wikified_at = added_at

        question.parse_and_save(author = author)

        question.add_revision(
            author = author,
            is_anonymous = is_anonymous,
            text = text,
            comment = const.POST_STATUS['default_version'],
            revised_at = added_at,
        )

        # INFO: Question has to be saved before update_tags() is called
        thread.update_tags(tagnames = tagnames, user = author, timestamp = added_at)

        return thread
Exemplo n.º 3
0
from askbot.conf import settings as askbot_settings

from core.facebook_sync import utils

LANGUAGE = 'fr'


def post_get_facebook_post(self):
    try:
        if isinstance(self, Thread):
            return self.get_post_data()[0].facebookpost
        return self.facebookpost
    except Post.DoesNotExist:
        return

Post.add_to_class('get_facebook_post', post_get_facebook_post)
Thread.add_to_class('get_facebook_post', post_get_facebook_post)


class FacebookPostManager(PostManager):
    def create_question(self, fb_obj):
        user = utils.guess_user(fb_obj)
        timestamp = utils.guess_timestamp(fb_obj)
        question = user.post_question(
            title=utils.guess_title(fb_obj),
            body_text=utils.guess_text(fb_obj),
            tags=utils.guess_tags(fb_obj),
            timestamp=timestamp,
            wiki=False,
            is_anonymous=False,
            is_private=False,
Exemplo n.º 4
0
    def create_new(
                self,
                title,
                author,
                added_at,
                wiki,
                text,
                tagnames = None,
                is_anonymous = False,
                is_private = False,
                by_email = False,
                email_address = None
            ):
        """creates new thread"""
        # TODO: Some of this code will go to Post.objects.create_new

        thread = super(
            ThreadManager,
            self
        ).create(
            title=title,
            tagnames=tagnames,
            last_activity_at=added_at,
            last_activity_by=author
        )

        #todo: code below looks like ``Post.objects.create_new()``
        question = Post(
            post_type='question',
            thread=thread,
            author = author,
            added_at = added_at,
            wiki = wiki,
            is_anonymous = is_anonymous,
            #html field is denormalized in .save() call
            text = text,
            #summary field is denormalized in .save() call
        )
        if question.wiki:
            #DATED COMMENT
            #todo: this is confusing - last_edited_at field
            #is used as an indicator whether question has been edited
            #but in principle, post creation should count as edit as well
            question.last_edited_by = question.author
            question.last_edited_at = added_at
            question.wikified_at = added_at

        #this is kind of bad, but we save assign privacy groups to posts and thread
        question.parse_and_save(author = author, is_private = is_private)

        revision = question.add_revision(
            author = author,
            is_anonymous = is_anonymous,
            text = text,
            comment = const.POST_STATUS['default_version'],
            revised_at = added_at,
            by_email = by_email,
            email_address = email_address
        )

        if is_private:#add groups to thread and question
            thread.make_private(author)

        # INFO: Question has to be saved before update_tags() is called
        thread.update_tags(tagnames = tagnames, user = author, timestamp = added_at)

        return thread