Changeset 25 for bitstructures

Show
Ignore:
Timestamp:
12/09/07 15:54:23 (13 months ago)
Author:
simon
Message:

Added code to extract code blocks from Markdown text.
Changed drafts to be publicly viewable.
Added a colophon section to the base.html template that links to the svn repository.

Location:
bitstructures/trunk
Files:
3 added
4 modified

Legend:

Unmodified
Added
Removed
  • bitstructures/trunk/README

    r2 r25  
     1Bitstructures.com 
     2 
     3This is the code running bitstructures.com. It's not really set up (yet) 
     4for easy deployment in other situations but please feel free to reuse 
     5parts if useful. 
     6 
     7Unless explicitly stated, the source code is licensed under the MIT license. 
     8Please see the LICENSE file. 
     9 
    110Dependencies 
    211 
  • bitstructures/trunk/substructure/urls.py

    r24 r25  
    55    (r'^$', 'blog'), 
    66    (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<slug>[a-z0-9-]+)$', 'entry_page'), 
     7    (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<slug>[a-z0-9-]+)/(?P<num>\d+)/(?P<filename>[a-zA-Z0-9-_\.]+)$', 'entry_codeblock'), 
    78    (r'^drafts/(?P<slug>[a-z0-9-]+)$', 'draft_page'), 
     9    (r'^drafts/(?P<slug>[a-z0-9-]+)/(?P<num>\d+)/(?P<filename>[a-zA-Z0-9-_\.]+)$', 'draft_codeblock'), 
    810    (r'^fb-atom.xml$', 'atom_feed') 
    911) 
  • bitstructures/trunk/substructure/views.py

    r24 r25  
    55from django.conf import settings 
    66from bitstructures.substructure.models import Entry 
     7from bitstructures.substructure.codeblocks import MarkdownCodeblocksParser 
    78 
    89def blog(request): 
     
    1314def entry_page(request, year, month, slug): 
    1415    entry = get_object_or_404(Entry, slug=slug) 
     16    check_view_entry(entry, year, month) 
     17    data = get_context_data(request) 
     18    data['entry'] = entry 
     19    return render_to_response('substructure/entry_page.html', data) 
     20 
     21def entry_codeblock(request, year, month, slug, num, filename): 
     22    entry = get_object_or_404(Entry, slug=slug) 
     23    check_view_entry(entry, year, month) 
     24    return get_codeblock_response(entry, num, filename) 
     25 
     26def check_view_entry(entry, year, month): 
    1527    if not entry.is_published(): 
    1628        raise Http404 
     
    1931    if int(month) != entry.date_published.month: 
    2032        raise Http404 
     33 
     34def draft_page(request, slug): 
     35    entry = get_object_or_404(Entry, slug=slug) 
     36    check_view_draft(request, entry) 
    2137    data = get_context_data(request) 
    2238    data['entry'] = entry 
    2339    return render_to_response('substructure/entry_page.html', data) 
    2440 
    25 def draft_page(request, slug): 
    26     if not user_can_change_entry(request): 
    27         raise Http404 
     41def draft_codeblock(request, slug, num, filename): 
    2842    entry = get_object_or_404(Entry, slug=slug) 
     43    check_view_draft(request, entry) 
     44    return get_codeblock_response(entry, num, filename) 
     45 
     46def check_view_draft(request, entry): 
    2947    if not entry.is_draft(): 
    3048        raise Http404 
    31     data = get_context_data(request) 
    32     data['entry'] = entry 
    33     return render_to_response('substructure/entry_page.html', data) 
     49 
     50def get_codeblock_response(entry, num, filename): 
     51    parser = MarkdownCodeblocksParser() 
     52    codeblock = parser.get_codeblock(entry.text, int(num)) 
     53    if codeblock: 
     54        if filename.lower().endswith('html'): 
     55            return HttpResponse(codeblock, mimetype='text/html') 
     56        else: 
     57            return HttpResponse(codeblock, mimetype='text/plain') 
     58    else: 
     59        raise Http404 
    3460 
    3561def atom_feed(request): 
  • bitstructures/trunk/templates/substructure/base.html

    r24 r25  
    3535the <a href="http://dojotoolkit.org/">Dojo</a> JavaScript toolkit.</p> 
    3636<p><a href="http://del.icio.us/simonbates">del.icio.us/simonbates</a></p> 
     37</div> 
     38 
     39<div class="info-entry"> 
     40<h2>Colophon</h2> 
     41<p>This site is running a 
     42<a href="http://trac.bitstructures.com/browser/bitstructures/trunk">custom 
     43Python application</a> (MIT license) built with 
     44<a href="http://www.djangoproject.com/">Django</a>.</p> 
    3745<p><a href="/atom.xml"><img src="{{ MEDIA_URL }}images/feed-icon-14x14.png" alt="Site feed"> Site feed</a></p> 
    3846</div>