コード例 #1
0
ファイル: models.py プロジェクト: nadavperetz/MeneEduca
    def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
        super(Group, self).save()
        description = u"Forum " + unicode(self.name)

        if len(Forum.objects.filter(group=self)) == 0:
            forum = Forum(title=self.name, description=description, group=self)
            forum.save()
        else:
            forum = Forum.objects.filter(group=self)[0]
            forum.title = self.name
            forum.description = description
            forum.save()
コード例 #2
0
 def restore(cls, in_):
     data = json.load(open(in_))
     forum = Forum(**dict(id=data["self"]["id"],
                          title=data["self"]["title"],
                          description=data["self"]["description"],
                          parent_id=data["self"]["parent"],
                          category_id=data["self"]["category"],
                          last_modified=data["self"]["last_modified"],
                          view_count=data["self"]["view_count"],
                          post_count=data["self"]["post_count"]))
     forum._importing = True
     forum.save()
     for thread_data in data["threads"]:
         thread = ForumThread(
             **dict(id=thread_data["id"],
                    author_id=thread_data["author"],
                    content=thread_data["content"],
                    created=thread_data["created"],
                    forum_id=thread_data["forum"],
                    title=thread_data["title"],
                    last_modified=thread_data["last_modified"],
                    view_count=thread_data["view_count"],
                    reply_count=thread_data["reply_count"],
                    subscriber_count=thread_data["subscriber_count"]))
         thread._importing = True
         thread.save()
         for reply_data in thread_data["replies"]:
             reply = ForumReply(**dict(
                 id=reply_data["id"],
                 author_id=reply_data["author"],
                 content=reply_data["content"],
                 created=reply_data["created"],
                 thread_id=reply_data["thread"],
             ))
             reply._importing = True
             reply.save()
         for subscriber_data in thread_data["subscriptions"]:
             ThreadSubscription(**dict(
                 id=subscriber_data["id"],
                 user_id=subscriber_data["user"],
                 thread_id=subscriber_data["thread"],
                 kind=subscriber_data["kind"],
             )).save()
         thread.last_reply_id = thread_data["last_reply"]
         thread.save()
     forum.last_thread_id = data["self"]["last_thread"]
     forum.save()
コード例 #3
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def restore(cls, in_):
     data = json.load(open(in_))
     forum = Forum(**dict(
         id=data["self"]["id"],
         title=data["self"]["title"],
         description=data["self"]["description"],
         parent_id=data["self"]["parent"],
         category_id=data["self"]["category"],
         last_modified=data["self"]["last_modified"],
         view_count=data["self"]["view_count"],
         post_count=data["self"]["post_count"]
     ))
     forum._importing = True
     forum.save()
     for thread_data in data["threads"]:
         thread = ForumThread(**dict(
             id=thread_data["id"],
             author_id=thread_data["author"],
             content=thread_data["content"],
             created=thread_data["created"],
             forum_id=thread_data["forum"],
             title=thread_data["title"],
             last_modified=thread_data["last_modified"],
             view_count=thread_data["view_count"],
             reply_count=thread_data["reply_count"],
             subscriber_count=thread_data["subscriber_count"]
         ))
         thread._importing = True
         thread.save()
         for reply_data in thread_data["replies"]:
             reply = ForumReply(**dict(
                 id=reply_data["id"],
                 author_id=reply_data["author"],
                 content=reply_data["content"],
                 created=reply_data["created"],
                 thread_id=reply_data["thread"],
             ))
             reply._importing = True
             reply.save()
         for subscriber_data in thread_data["subscriptions"]:
             ThreadSubscription(**dict(
                 id=subscriber_data["id"],
                 user_id=subscriber_data["user"],
                 thread_id=subscriber_data["thread"],
                 kind=subscriber_data["kind"],
             )).save()
         thread.last_reply_id = thread_data["last_reply"]
         thread.save()
     forum.last_thread_id = data["self"]["last_thread"]
     forum.save()