def fetch_from_url(request, url): """Analyze URL, returning the article and the articles in its path If something goes wrong, return an error HTTP response""" err = None article = None path = None url_path = get_url_path(url) try: root = Article.get_root() path = Article.get_url_reverse(url_path, root) if not path: print url_path err = not_found(request, '/' + '/'.join(url_path)) else: article = path[-1] except: err = not_found(request, '') return (article, path, err)
def create(request, wiki_url): url_path = get_url_path(wiki_url) if url_path != [] and url_path[0].startswith('_'): c = RequestContext(request, {'wiki_err_keyword': True, 'wiki_url': '/'.join(url_path) }) return render_to_response('simplewiki_error.html', c) # Lookup path try: # Ensure that the path exists... root = Article.get_root() path = Article.get_url_reverse(url_path[:-1], root) if not path: c = RequestContext(request, {'wiki_err_noparent': True, 'wiki_url_parent': '/'.join(url_path[:-1]) }) return render_to_response('simplewiki_error.html', c) perm_err = check_permissions(request, path[-1], check_locked=False, check_write=True) if perm_err: return perm_err # Ensure doesn't already exist article = Article.get_url_reverse(url_path, root) if article: return HttpResponseRedirect(reverse('wiki_view', args=(article[-1].get_url(),))) # TODO: Somehow this doesnt work... #except ShouldHaveExactlyOneRootSlug, (e): except: if Article.objects.filter(parent=None).count() > 0: return HttpResponseRedirect(reverse('wiki_view', args=('',))) # Root not found... path = [] url_path = [""] if request.method == 'POST': f = CreateArticleForm(request.POST) if f.is_valid(): article = Article() article.slug = url_path[-1] if not request.user.is_anonymous(): article.created_by = request.user article.title = f.cleaned_data.get('title') if path != []: article.parent = path[-1] a = article.save() new_revision = f.save(commit=False) if not request.user.is_anonymous(): new_revision.revision_user = request.user new_revision.article = article new_revision.save() import django.db as db return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),))) else: f = CreateArticleForm(initial={'title':request.GET.get('wiki_article_name', url_path[-1]), 'contents':_('Headline\n===\n\n')}) c = RequestContext(request, {'wiki_form': f, 'wiki_write': True, }) return render_to_response('simplewiki_create.html', c)