Exemple #1
0
 def post(self, *args):
     form = BlogEntryForm(data=self.request.POST)
     if form.is_valid():
         shop = db.get(self.request.get('shop'))
         if self.request.get('key'):
             entry = db.get(self.request.get('key'))
             entry.shop = shop
             entry.title = self.request.get('title')
             entry.body = self.request.get('body')
         else:
             entry = BlogEntry(user = users.get_current_user(),
                               shop = shop,
                               title = self.request.get('title'),
                               body = self.request.get('body'),
                               )
         entry.put()
         self.redirect('/blog')
     else:
         shops = Shop.all().order('area')
         template_vars = { 'shops': shops, 'form': form }
         self.render_response('blog/blog_edit.html', template_vars)
Exemple #2
0
def save_post(request, idee):
    if request.method == 'POST':
        submit_names = ('save', 'publish', 'quit')
        submit = [i for i in request.POST if i in submit_names][0]
        author = request.user
        form = BlogEntryForm(request.POST)

        if form.is_valid():
            if idee:
                entry = get_object_or_404(BlogEntry, pk=idee, author=author)
                entry.title = form.cleaned_data['title']
                entry.content = form.cleaned_data['content']
                entry.updated = entry.updated.now()
            else:
                entry = BlogEntry(author=author)
                entry.title=form.cleaned_data['title']
                entry.name = flatten(entry.title) + '.html'
                entry.content = form.cleaned_data['content']
                # We need a pk before settings tag_names below
                entry.save()
            Tag.objects.update_tags(entry, form.cleaned_data['tags'])
            if submit == "publish":
                entry.published = True
                entry.posted = datetime.now()
                entry.save()
                return HttpResponseRedirect(reverse('index'))
            elif submit == "save":
                entry.save()
                return render_to_response('edit_post.html', {'form': form,
                        'entry': entry})
            else:
                entry.save()
                return HttpResponseRedirect(reverse('admin'))
        elif submit == "quit":
            return HttpResponseRedirect(reverse('admin'))
    else:
        form = BlogEntryForm()
    return render_to_response('edit_post.html', {'form': form})