Beispiel #1
0
	def parse_rss(self, user, url):
		d = feedparser.parse(self.get_fulltext_url(url))
		if d['entries']:
			for entry in d['entries']:
				post = Post()
				post.title = entry.title
				post.user = user
				post.description = entry.summary
				date = None
				if hasattr(entry, 'published'):
					date = entry.published_parsed
				elif hasattr(entry, 'date'):
					date = entry.date_parsed
				if date:
					post.publish_date = datetime.fromtimestamp(mktime(date))
				post.status = CONTENT_STATUS_DRAFT
				if hasattr(entry, 'description'):
					post.content = entry.description
				else:
					post.content = post.tease
				post.save()
				for tag in getattr(entry, 'tags', []):
					tag = tag.get('term', '').strip()
					if tag:
						keyword = Keyword.objects.get_or_create(title=tag)[0]
						AssignedKeyword.objects.create(keyword=keyword, content_object=post)
			return True
Beispiel #2
0
def archive(request,start,end):
    from django.contrib.sites.models import Site
    from mezzanine.blog.models import BlogPost
    from db_PNP import DB
    
    start,end = int(start), int(end)

    site = Site.objects.get(name='LA LETTRE')

    for item in DB[start:end]:
        content = item[4].decode('utf-8').replace('src="','src="/archives/')
        u = item[17]
        u = u.split(',')
        u = u[0].split(':')
        u = u[1].replace('"','').replace('\\','')
        if len(u) > 3:
            u = 'archives/'+u
        else:
            u = None
        if item[8] != "0000-00-00 00:00:00":
            k = BlogPost(site=site,
                        user_id=1,
                        title=item[2].decode('utf-8'),
                        content=content,
                        featured_image=u,
                        publish_date=item[8],
                        archive=True
                        )
        else: 
            k = BlogPost(site=site,
                        user_id=1,
                        title=item[2].decode('utf-8'),
                        content=content,
                        featured_image=u,
                        publish_date=item[15],
                        archive=True
                        )
            print item[15]
        k.save()
    return HttpResponse("archiving process ended.")
Beispiel #3
0
    def handle(self, *args, **options):
        csvfilename = options['filename']
        csvfile = self.__csvfile(csvfilename)

        for row in csvfile:
            email = row[1]
            username = email.split('@')[0]
            try:
                u = User.objects.get(username=username)
            except User.DoesNotExist:
                u = User(email=email, username=username)
                u.save()

            try:
                talk = BlogPost.objects.filter(title__exact=row[2], user_id=u.id)[0]
                talk.content = row[3]
                talk.speakers = row[4]
                talk.office = row[5]
                talk.save()
            except:
                talk = BlogPost(title=row[2], content=row[3], user_id=u.id, speakers=row[4], office=row[5])
                talk.save()
                talk.categories.add(int(row[7]))
Beispiel #4
0
def archive(request, start, end):
    from django.contrib.sites.models import Site
    from mezzanine.blog.models import BlogPost
    from db_PNP import DB

    start, end = int(start), int(end)

    site = Site.objects.get(name='LA LETTRE')

    for item in DB[start:end]:
        content = item[4].decode('utf-8').replace('src="', 'src="/archives/')
        u = item[17]
        u = u.split(',')
        u = u[0].split(':')
        u = u[1].replace('"', '').replace('\\', '')
        if len(u) > 3:
            u = 'archives/' + u
        else:
            u = None
        if item[8] != "0000-00-00 00:00:00":
            k = BlogPost(site=site,
                         user_id=1,
                         title=item[2].decode('utf-8'),
                         content=content,
                         featured_image=u,
                         publish_date=item[8],
                         archive=True)
        else:
            k = BlogPost(site=site,
                         user_id=1,
                         title=item[2].decode('utf-8'),
                         content=content,
                         featured_image=u,
                         publish_date=item[15],
                         archive=True)
            print item[15]
        k.save()
    return HttpResponse("archiving process ended.")
def blog_recent_news_posts(limit=5, category="News"):
    """
    Put a list of recently published blog posts into the template
    context. A category title can also be specified to filter the recent posts returned.

    Usage::

        {% blog_recent_news_posts limit=5 category="News" as recent_posts %}

    """
    blog_posts = BlogPost.objects.published()
    title_or_slug = lambda s: Q(title=s) | Q(slug=s)
    try:
        category = BlogCategory.objects.get(title_or_slug(category))
        blog_posts = blog_posts.filter(categories=category)
        if not blog_posts:
            post1 = BlogPost()
            post1.title = 'A feed for the home page'
            post1.content = 'This block displays the ten most recent blog posts of category "News"' \
                            ' in their entirety. Just create a blog post and give it the category "News"'
            post2 = BlogPost()
            post2.title = 'Great for links and deals'
            post2.content = 'Use this space for brief comments and links to other pages. If using with Cartridge' \
                            'it\'s perfect to highlight items.'
            post3 = BlogPost()
            post3.title = 'These example posts are not stored in the database'
            post3.content = 'If you try and edit them inline you\'ll only get an error message. ' \
                            'As soon as you publish a blog post of category "News" they will disappear.'
            blog_posts = [post1, post2, post3,]
            return blog_posts

    except BlogCategory.DoesNotExist:
        post1 = BlogPost()
        post1.title = 'A feed for the home page'
        post1.content = 'This block displays the ten most recent blog posts of category "News"' \
                        ' in their entirety. Just create a blog post and give it the category "News"'
        post2 = BlogPost()
        post2.title = 'Great for links and deals'
        post2.content = 'Use this space for brief comments and links to other pages. If using with Cartridge' \
                        'it\'s perfect to highlight items.'
        post3 = BlogPost()
        post3.title = 'These example posts are not stored in the database'
        post3.content = 'If you try and edit them inline you\'ll only get an error message. ' \
                        'As soon as you publish a blog post of category "News" they will disappear.'
        blog_posts = [post1, post2, post3,]
        return blog_posts
    return list(blog_posts[:limit])
Beispiel #6
0
    def create(self, request, *args, **kwargs):

        post = BlogPost(user_id=request.data['user'],
                        title=request.data['title'],
                        content='<p>'+request.data['content']+'</p>',
                        status=2,
                        featured_image=''
        )

        for key,value in request.data.items():
            if key == 'status':
                post.status = value
            if key == 'gen_description':
                post.gen_description = value
            if key == 'in_sitemap':
                post.in_sitemap = value
            if key == 'slug':
                post.slug = value
            if key == 'featured_image':
                post.featured_image = value
            if key == 'allow_comments':
                post.allow_comments = value
            if key == 'gen_description':
                post.gen_description = value
            if key == 'in_sitemap':
                post.in_sitemap = value

        post.save()


        return HttpResponse('<a href="'+ post.get_absolute_url() + '">' + post.title + '</a>')
Beispiel #7
0
    def create(self, request, *args, **kwargs):

        post = BlogPost(user_id=request.data['user'],
                        title=request.data['title'],
                        content='<p>' + request.data['content'] + '</p>',
                        status=2,
                        featured_image='')

        for key, value in request.data.items():
            if key == 'status':
                post.status = value
            if key == 'gen_description':
                post.gen_description = value
            if key == 'in_sitemap':
                post.in_sitemap = value
            if key == 'slug':
                post.slug = value
            if key == 'featured_image':
                post.featured_image = value
            if key == 'allow_comments':
                post.allow_comments = value
            if key == 'gen_description':
                post.gen_description = value
            if key == 'in_sitemap':
                post.in_sitemap = value

        post.save()

        return HttpResponse('<a href="' + post.get_absolute_url() + '">' +
                            post.title + '</a>')