Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def delete(request, note_id):
	note = Note.load(db, note_id)
	
	if request.method == 'POST':
		# TODO The delete function here.
		return HttpResponseRedirect(reverse('notes_index'))
	
	return render_to_response('notes/delete.html', { 'note': note }, context_instance=RequestContext(request))
Ejemplo n.º 3
0
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 }))
Ejemplo n.º 4
0
def detail(request, note_id):
	note = Note.load(db, note_id)
	if note.private and not request.user.is_staff:
		raise Http404
	
	if request.user.is_staff:
		form = NoteForm(initial={
			'body':				note.body,
			'tags':				note.tags,
			'allow_comments':	note.allow_comments,
			'private':			note.private,
		})
	else:
		form = None
	
	return render_to_response('notes/detail.html', { 'note': note, 'form': form }, context_instance=RequestContext(request))
Ejemplo n.º 5
0
def update(request, note_id):
	note = Note.load(db, note_id)
	
	if request.method == 'POST':
		new_data = request.POST.copy()
		form = NoteForm(new_data)
		if form.is_valid():
			note.body = form.cleaned_data['body']
			note.tags = form.cleaned_data['tags']
			note.allow_comments = form.cleaned_data['allow_comments']
			note.private = form.cleaned_data['private']
			note.store()
	
	form = NoteForm(initial={
		'body':				note.body,
		'tags':				note.tags,
		'allow_comments':	note.allow_comments,
		'private':			note.private,
	})
	
	return render_to_response('notes/form.html', { 'form': form, 'note': note }, context_instance=RequestContext(request))