Changeset 539

Show
Ignore:
Timestamp:
02/11/10 23:31:25 (6 months ago)
Author:
olivier
Message:

add support for rst based flat pages ; add descriptive text and image to home

Location:
trunk/telemeta
Files:
13 added
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/telemeta/htdocs/css/telemeta.css

    r532 r539  
    1 * {margin: 0; padding: 0;} 
     1body {margin: 0; padding: 0;} 
    22a {text-decoration: none; color: #969696;} 
    33a img {border: none;} 
     
    2424a img { border: none; } 
    2525 
    26 h3 { 
     26.rst-content h1, h3 { 
    2727    font-size: 1.2em; 
    2828    font-weight: bold; 
     
    621621    margin-top: 0.8em; 
    622622} 
     623 
     624img.home-image { 
     625    margin: 0 1.5em 1.5em 0; 
     626    float: left; 
     627} 
  • trunk/telemeta/models/location.py

    r534 r539  
    103103    class Meta(MetaCore): 
    104104        db_table = 'locations' 
     105        verbose_name = _('location') 
    105106 
    106107    def __unicode__(self): 
  • trunk/telemeta/templates/telemeta_default/index.html

    r346 r539  
    11{% extends "telemeta/base.html" %} 
     2{% load telemeta_utils %} 
    23{% block content %} 
     4{{ page_content|rst }} 
     5 
     6<!-- 
    37<div class="homelinks"> 
    48<p><a href="{% url telemeta-collections %}">All collections</a><br /> 
     
    1115  Configure Telemeta and manage users</p> 
    1216</div> 
     17--> 
    1318{% endblock %} 
  • trunk/telemeta/templates/telemeta_default/search_criteria.html

    r535 r539  
    3030 
    3131    <p> 
    32     <label for="location">{% trans "Location" %}</label> 
     32    <label for="location">{% field_label "Location" %}</label> 
    3333    <input type="text" name="location" id="location" /> 
    3434    </p> 
  • trunk/telemeta/templatetags/telemeta_utils.py

    r537 r539  
    99from telemeta import models 
    1010from django.utils.translation import ungettext 
     11from docutils.core import publish_parts 
     12from django.utils.encoding import smart_str, force_unicode 
     13from django.utils.safestring import mark_safe 
     14import re 
    1115 
    1216register = template.Library() 
     
    166170 
    167171@register.simple_tag 
    168 def field_label(model, field): 
     172def field_label(model, field=None): 
    169173    if isinstance(model, basestring): 
    170174        model = getattr(models, model) 
    171175             
     176    if not field: 
     177        return capfirst(unicode(model._meta.verbose_name)) 
     178 
    172179    return capfirst(unicode(model.field_label(field))) 
    173180 
     
    210217def equals(value1, value2): 
    211218    return value1 == value2 
     219 
     220@register.filter 
     221def rst(content): 
     222    parsed = "" 
     223    path = getattr(content, 'path', '') 
     224    if isinstance(content, basestring): 
     225        content = content.split("\n") 
     226 
     227    for line in content: 
     228        match = re.match('^(\.\. *(?:_[^:]*:|image::) *)([^ ]+) *$', line) 
     229        if match: 
     230            directive, urlname = match.groups() 
     231            line = directive 
     232            try: 
     233                i = urlname.index('telemeta-') 
     234            except ValueError: 
     235                i = -1 
     236            if i == 0: 
     237                line += reverse(urlname) 
     238            elif urlname[:1] != '/': 
     239                print '|%s|' % urlname 
     240                line += reverse('telemeta-flatpage', args=[path + '/../' + urlname]) 
     241            else: 
     242                line += urlname 
     243 
     244        parsed += line + "\n" 
     245 
     246    parts = publish_parts(source=smart_str(parsed), writer_name="html4css1", settings_overrides={}) 
     247    return mark_safe('<div class="rst-content">\n' + force_unicode(parts["html_body"]) + '</div>') 
     248rst.is_safe = True 
     249 
     250 
     251 
  • trunk/telemeta/urls.py

    r535 r539  
    166166        name="telemeta-timeside"), 
    167167 
     168    # Flat pages 
     169    url(r'^page/(?P<path>.*)$', web_view.render_flatpage, name="telemeta-flatpage"), 
     170 
    168171    # OAI-PMH Data Provider 
    169172    url(r'^oai/.*$', web_view.handle_oai_request, name="telemeta-oai") 
  • trunk/telemeta/web/base.py

    r538 r539  
    4141from django.http import HttpResponse 
    4242from django.http import Http404 
    43 from django.shortcuts import render_to_response 
     43from django.shortcuts import render_to_response, redirect 
    4444from django.views.generic import list_detail 
    4545from django.conf import settings 
     
    5757from django.core.exceptions import ObjectDoesNotExist 
    5858from telemeta.util.unaccent import unaccent 
     59from telemeta.web import pages 
    5960 
    6061class WebView(Component): 
     
    6970 
    7071        template = loader.get_template('telemeta/index.html') 
    71         context = Context({}) 
     72        context = Context({'page_content': pages.get_page_content(request, 'parts/home', True)}) 
    7273        return HttpResponse(template.render(context)) 
    7374 
     
    391392        return HttpResponse(provider.handle(args), mimetype='text/xml') 
    392393         
    393  
     394    def render_flatpage(self, request, path): 
     395        try: 
     396            content = pages.get_page_content(request, path) 
     397        except pages.MalformedPagePath: 
     398            return redirect(request.path + '/') 
     399 
     400        if isinstance(content, pages.PageAttachment): 
     401            return HttpResponse(content, content.mimetype()) 
     402        else: 
     403            return render_to_response('telemeta/flatpage.html', {'page_content': content }) 
     404