Esempio n. 1
0
def newentry(request, blog_id):
    b = get_object_or_404(MyBlog, pk=blog_id)
    d = datetime.datetime.now()
    #try:
    new_subject = request.POST['subject']
    new_content = request.POST['content']
    #except (KeyError, subject.DoesNotExist):
    if (new_subject == '') :
        # Redisplay the poll voting form.
        return render_to_response('blogs/detail.html', {
            'blog': b,
            'error_message': "You must enter a subject.",
        }, context_instance=RequestContext(request))
    if (new_content == '') :
    #except (KeyError, sontent.DoesNotExist):
        # Redisplay the poll voting form.
        return render_to_response('blogs/detail.html', {
            'blog': b,
            'error_message': "You must enter some content.",
        }, context_instance=RequestContext(request))
    else:
        e = BlogEntry(blog=b, subject=new_subject, content=new_content, created=d, updated=d)
        e.save()        
        # Always return an HttpResponseRedirect after successfully dealing
        # with POST data. This prevents data from being posted twice if a
        # user hits the Back button.
        return HttpResponseRedirect(reverse('blogs.views.oneblog', args=(blog_id,)))
Esempio n. 2
0
def parse_feed(feed_url, page):
    ids = []
    entries = get_feed_entries(feed_url)
    for entry in entries:
        parsed = parse_entry(entry) 
        clean_summary = smart_str(bleach.clean(parsed['summary'], tags=(), strip=True))
        checksum = hashlib.md5(clean_summary + page).hexdigest()
        exists = BlogEntry.objects.filter(checksum=checksum)
        if not exists:
            entry = BlogEntry(
                title = parsed['title'].encode('utf-8'),
                link = parsed['link'].encode('utf-8'),
                summary = clean_summary,
                page = page, 
                checksum = checksum,
                updated = time.strftime(
                    "%Y-%m-%d", parsed['updated_on']),
                autor = parsed['author'])
            entry.save()
            entry_id = entry.id
        else:
            entry_id = exists[0].id
        ids.append(entry_id)
    return ids