def __importHitCount(self, zip, fingerprint, replacing):
        hits = json.loads(zip.read('hitcount.json'),
                          object_hook=json_util.object_hook)
        tmap = None
        before = None

        if replacing:
            tmap = {}

        for hit in hits:

            this_hit = HitCount()

            if replacing:
                hit['object_pk'] = fingerprint.id

                before = hit['id']
                del hit['id']

            this_hit.__dict__.update(hit)

            this_hit.save()

            if replacing:
                tmap[before] = this_hit.id

        return tmap
Exemplo n.º 2
0
    def __importHitCount(self, zip , fingerprint , replacing):
        hits = json.loads(zip.read('hitcount.json'), object_hook=json_util.object_hook)
        tmap = None
        before = None

        if replacing:
            tmap = {}

        for hit in hits:

            this_hit = HitCount()

            if replacing:
                hit['object_pk'] = fingerprint.id

                before = hit['id']
                del hit['id']

            this_hit.__dict__.update(hit)

            this_hit.save()

            if replacing:
                tmap[before] = this_hit.id


        return tmap
Exemplo n.º 3
0
    def test_string_representation(self):
        """
        Basic __str__ testing

        """
        post = Post.objects.create(title='my title', content='my text')
        hit_count = HitCount(content_object=post)
        self.assertEqual(hit_count.__str__(), 'Post title: my title')
Exemplo n.º 4
0
    def test_string_representation(self):
        """
        Basic __str__ testing

        """
        post = Post.objects.create(title='my title', content='my text')
        hit_count = HitCount(content_object=post)
        self.assertEqual(hit_count.__str__(), 'Post title: my title')
def set_hit_count(content_object, count):
    print "Storing hitcount of item %s : %s"%(str(content_object), count)
    hitcount = HitCount(content_object=content_object, hits=count)
    hitcount.save()
Exemplo n.º 6
0
    def import_articles(self, article_rows):
        self.vprint("BEGIN Importing articles", 1)
        blog_post_ctype = ContentType.objects.get_for_model(BlogPost)
        user = User.objects.get(username="******")
        for row in article_rows:
            self.vprint("    Importing row: {}/{}/{}".format(row['section'], row['category'], row['title']), 2)
            if row['section'] == 'services':
                # Add it as a page
                self.vprint("Its a page: skipped for now", 3)
            else:
                # Add it as a blog entry
                blog_post = self.get_or_create(BlogPost, title=row['title'])
                blog_post.user = user

                blog_post.title = row['title']
                blog_post.content = row['introtext'] + row['fulltext']
                if not self.dry_run:
                    # Save it a first time so many to many category relation and hitcount can be set up
                    blog_post.save()

                    # Assign created/updated date (this must be done after the first save)
                    blog_post.created = row['created']
                    blog_post.updated = row['modified'] or row['created']
                    blog_post.publish_date = blog_post.updated

                    # Assign its hits
                    try:
                        hitcount = HitCount.objects.get(
                            content_type=blog_post_ctype,
                            object_pk=blog_post.pk)
                    except HitCount.DoesNotExist:
                        hitcount = HitCount(content_object=blog_post)
                    hitcount.hits = row['hits']
                    hitcount.save()

                    # Assign it a category
                    category_title = self.get_blog_post_category_title(row)
                    if category_title is not None:
                        category = BlogCategory.objects.get(title=category_title)
                        blog_post.categories.add(category)

                    # Save it a second time to ensure the category and created dates are saved too
                    blog_post.save()

                    # Assign its comments
                    for comment_row in row['comments']:
                        comment = self.get_or_create(ThreadedComment,
                                                     user_name=comment_row['name'],
                                                     comment=comment_row['comment'])
                        comment.content_object = blog_post
                        comment.user_name = comment_row['name']

                        comment_content = comment_row['title']
                        if len(comment_content) > 0:
                            comment_content += "\n"
                        comment_content += comment_row['comment']

                        comment.comment = comment_content
                        comment.user_email = comment_row['email']
                        comment.user_url = comment_row['website']
                        comment.submit_date = comment_row['date']
                        comment.ip_address = comment_row['ip']
                        comment.save()

        self.vprint("END   Importing articles", 1)