Beispiel #1
0
def view_article(request, slug):
    edit_url = reverse('edit_article', args=[slug])
    try:
        # Enables case-insentivity
        article = Article.objects.get(slug__iexact=slug)
        if article.slug != slug:
            return HttpResponseRedirect(reverse('view_article', args=[article.slug]))

        params = {'editurl' : xslt_param_builder(edit_url)}
        return render_to_response('article.xsl', article, params)

    # If the article does not exist, we go to edit mode
    except Article.DoesNotExist:
        return HttpResponseRedirect(edit_url)
Beispiel #2
0
def search(request):

    if request.method == 'POST':
        result = query(request.POST['query'])

        # Redirect straight to single result
        if len(result) == 1:
            view_url = reverse('view_article', args=[result[0].slug])
            return HttpResponseRedirect(view_url)


        params = {'query' : xslt_param_builder(request.POST['query'])}

        return render_to_response('search.xsl', result, params)
Beispiel #3
0
def edit_article(request, slug):
    article = None
    params = {}

    try:
        # Enables case-insentivity
        article = Article.objects.get(slug__iexact=slug)
        if article.slug != slug:
            return HttpResponseRedirect(reverse('edit_article', args=[article.slug]))
    except Article.DoesNotExist:
        title = slug.replace('_', ' ')
        article = Article(title=title, creator=request.user)

    if request.method == 'GET':

        # Check mutual exclusion
        lock = cache.get(article.title, None)
        if lock is None:
            lock = EditLock(article.title, request)
        elif not lock.is_mine(request):
            print "Possible editing conflict. Another user started editing", lock.created_at
            params['locked'] = xslt_param_builder("True")
            format = "%d %b %Y %H:%M:%S"
            params['lock_created'] = xslt_param_builder( lock.created_at.strftime(format) )

    elif request.method == 'POST':
        article.title = request.POST['title']
        article.content = request.POST['content']
        article.save()

        cache.delete(article.title)

        view_url = reverse('view_article', args=[article.slug])
        return HttpResponseRedirect(view_url)

    view_url = reverse('view_article', args=[slug])
    params['viewurl'] = xslt_param_builder(view_url)

    return render_to_response('edit_article.xsl', article, params)
Beispiel #4
0
 def test_xslt_will_render_queryset(self):
     """docstring for test_xslt_will_render_queryset"""
     data = TestModel.objects.all()
     resp = response.render_to_response('xslt/model-to-xml.xsl', data)
     assert(resp)
Beispiel #5
0
 def test_xslt_changes_the_xml(self):
     """docstring for test_xslt_changes_the_xml"""
     data = TestModel.objects.get(pk=1)
     resp = response.render_to_response('xslt/model-to-xml.xsl', data)
     assert(resp != HttpResponse(tree.xml(data)))
Beispiel #6
0
 def test_xslt_template_will_render_one_object(self):
     """docstring for test_xslt_template_will_render"""
     data = TestModel.objects.get(pk=1)
     resp = response.render_to_response('xslt/model-to-xml.xsl', data)
     assert(resp)
Beispiel #7
0
def index(request):
    latest_articles = Article.objects.order_by('-created_at')[:10]
    return render_to_response('base.xsl', latest_articles)
 def test_xslt_will_render_queryset(self):
     """docstring for test_xslt_will_render_queryset"""
     data = TestModel.objects.all()
     resp = response.render_to_response('xslt/model-to-xml.xsl', data)
     assert(resp)
 def test_xslt_changes_the_xml(self):
     """docstring for test_xslt_changes_the_xml"""
     data = TestModel.objects.get(pk=1)
     resp = response.render_to_response('xslt/model-to-xml.xsl', data)
     assert(resp != HttpResponse(tree.xml(data)))
Beispiel #10
0
 def test_xslt_template_will_render_one_object(self):
     """docstring for test_xslt_template_will_render"""
     data = TestModel.objects.get(pk=1)
     resp = response.render_to_response('xslt/model-to-xml.xsl', data)
     assert(resp)