def post_add_edit(request, id=None): if id: post = Post.load(db, id) form = PostForm(initial={ 'title': post.title, 'slug': post.slug, 'body': post.body, 'published': post.published, 'tags': ', '.join(post.tags), 'allow_comments': post.allow_comments, 'allow_pings': post.allow_pings }) add = False else: post = None form = PostForm() add = True if request.method == 'POST': new_data = request.POST.copy() form = PostForm(new_data) if form.is_valid(): if add: # Adding a new Post post = Post() post.title = form.cleaned_data['title'] post.slug = form.cleaned_data['slug'] post.body = form.cleaned_data['body'] post.published = form.cleaned_data['published'] post.tags = form.cleaned_data['tags'] post.allow_comments = form.cleaned_data['allow_comments'] post.allow_pings = form.cleaned_data['allow_pings'] post.store() else: # Updating a new Post post = Post.load(db, id) post.title = form.cleaned_data['title'] post.slug = form.cleaned_data['slug'] post.body = form.cleaned_data['body'] post.published = form.cleaned_data['published'] post.tags = form.cleaned_data['tags'] post.allow_comments = form.cleaned_data['allow_comments'] post.allow_pings = form.cleaned_data['allow_pings'] post.store() return render_to_response('comfy_admin/blog/posts/post_add_edit.html', { 'title': u'%s %s' % (add and _('Add') or _('Edit'), _('page')), 'post': post, 'form': form, 'add': add, }, context_instance=RequestContext(request))
def redirect(request, document_id): # FIXME F**k I am an idiot need to figure out a way to make this better. # Maybe something like Django's Content Types where it will look up the model # within the `INSTALLED_APPS` or something. try: doc = Document.load(db, document_id) except: raise Http404 # Is it a Blog post? if doc.type == 'Post': from comfy.apps.blog.models import Post post = Post.load(db, doc.id) return HttpResponseRedirect(post.get_absolute_url()) # Is it a Flat page? elif doc.type == 'FlatPage': from comfy.apps.flatpages.models import FlatPage f = FlatPage.load(db, doc.id) return HttpResponseRedirect(f.get_absolute_url()) # Is it a Note? elif doc.type == 'Note': from comfy.apps.notes.models import Note note = Note.load(db, doc.id) return HttpResponseRedirect(note.get_absolute_url()) elif doc.type == 'Bookmark': from comfy.apps.bookmarks.models import Bookmark bookmark = Bookmark.load(db, doc.id) return HttpResponseRedirect(bookmark.get_absolute_url()) else: raise Http404
def render_item(item, document_type=None, template_directory='items'): if document_type == 'Post': content_object = Post.load(db, item.id) elif document_type == 'Note': content_object = Note.load(db, item.id) elif document_type == 'Bookmark': content_object = Bookmark.load(db, item.id) else: content_object = None document_type = 'none' t = get_template('tumblelog/%s/%s.html' % (template_directory, document_type.lower())) return t.render(template.Context({ 'item': content_object }))