Exemple #1
0
def new_blog_entry():
    form = BlogEntryForm()

    # Die Klasse ab hier neu machen!!!
    if form.validate_on_submit():
        with open('/home/pi/temp_blog.html', 'w') as f:
            print(form.text.data)
            f.write("\n<p>\n")
            f.write("<strong>")
            f.write(form.titel.data)
            f.write("</strong>")
            f.write("\n</p>\n")
            f.write("\n<p>\n")
            f.write(form.text.data)
            f.write("\n</p>\n")
            if form.bild1.data:
                picture_file, thumbnail_file = save_picture_blog(
                    form.bild1.data)
                print(picture_file)
                print(thumbnail_file)
                f.write("<a href='/static/bilder/reiseblog/" + picture_file +
                        "'>\n")
                f.write("<img src='/static/bilder/reiseblog/" +
                        thumbnail_file + "'>\n")
                f.write("</a>\n")
            if form.bild2.data:
                picture_file, thumbnail_file = save_picture_blog(
                    form.bild2.data)
                print(picture_file)
                print(thumbnail_file)
                f.write("<a href='/static/bilder/reiseblog/" + picture_file +
                        "'>\n")
                f.write("<img src='/static/bilder/reiseblog/" +
                        thumbnail_file + "'>\n")
                f.write("</a>\n")
            if form.bild3.data:
                picture_file, thumbnail_file = save_picture_blog(
                    form.bild3.data)
                print(picture_file)
                print(thumbnail_file)
                f.write("<a href='/static/bilder/reiseblog/" + picture_file +
                        "'>\n")
                f.write("<img src='/static/bilder/reiseblog/" +
                        thumbnail_file + "'>\n")
                f.write("</a>\n")
            if form.bild4.data:
                picture_file, thumbnail_file = save_picture_blog(
                    form.bild4.data)
                print(picture_file)
                print(thumbnail_file)
                f.write("<a href='/static/bilder/reiseblog/" + picture_file +
                        "'>\n")
                f.write("<img src='/static/bilder/reiseblog/" +
                        thumbnail_file + "'>\n")
                f.write("</a>\n")
        return redirect('blog')

    return render_template('new_blog_entry.html', form=form)
Exemple #2
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 #3
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})