Changeset 6fa27110c516097eaf3deaada94aed7286097065


Ignore:
Timestamp:
28.07.2013 02:28:55 (8 years ago)
Author:
Stanislaw Klekot <dozzie@…>
Branches:
b66903eafbcb1d49112014abc82c8bf683413db0
Children:
0472ab6f7f555828f0d3039cdd825ae8a0748665
Parents:
ace270d198a7864aa505097173d330417be0ca6c
git-author:
Stanislaw Klekot <dozzie@…> (28.07.2013 02:28:55)
git-committer:
Stanislaw Klekot <dozzie@…> (28.07.2013 02:28:55)
Message:

#22 First stab at parametrized wiki pages.

It's a hack, though, and probably should be replaced with dedicated
infrastructure.

Location:
dashwiki/wiki
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • dashwiki/wiki/templates/display_wiki.html

    r0ee13e r6fa271  
    3131  {% if editable %} 
    3232    <p> 
    33       <form method="get" action="{% url display_wiki_page name %}" style='display:inline'> 
     33      <form method="get" action="{% url display_wiki_page real_name %}" style='display:inline'> 
    3434        <input type="hidden" name="edit" value="true" /> 
    3535        <input type="submit" value="Edit" /> 
    3636      </form> 
    3737      <span>|</span> 
    38       <form method="get" action="{% url display_wiki_page name %}" style='display:inline'> 
     38      <form method="get" action="{% url display_wiki_page real_name %}" style='display:inline'> 
    3939        <input type="hidden" name="remove" value="true" /> 
    4040        <input type="submit" value="Remove" /> 
  • dashwiki/wiki/urls.py

    r8298e0 r6fa271  
    77urlpatterns = patterns('dashwiki.wiki.views', 
    88  (r'^$', 'display_wiki', {'page_name': 'WikiStart'}), 
    9   (r'^(?P<page_name>[A-Z][a-zA-Z0-9_/]+)', 'display_wiki', {}, 'display_wiki_page'), 
     9  (r'^(?P<page_name>[A-Z][a-zA-Z0-9_]+/.*)', 'display_wiki', {}, 'display_wiki_page'), 
     10  (r'^(?P<page_name>[A-Z][a-zA-Z0-9_/]+)', 'display_wiki', {}), 
    1011) 
    1112 
  • dashwiki/wiki/views.py

    r0f27e5 r6fa271  
    2525  except ObjectDoesNotExist, e: 
    2626    page = None 
     27    if '/' in page_name: 
     28      parametrized_name = page_name[0:page_name.rfind('/') + 1] 
     29      # XXX: hack(?) for loading parametrized wiki pages 
     30      try: 
     31        page = WikiPage.objects.get(name = parametrized_name) 
     32      except ObjectDoesNotExist, e: 
     33        pass 
    2734 
    2835  return page 
     
    3138# TODO: limit how much time this function spends in calling remote systems 
    3239# (timeout) 
    33 def call_all_macros(tree, request, page_name): 
     40def call_all_macros(tree, request, page_name, page_param = None): 
    3441  from dashwiki.macros.models import Macro 
    3542  from django.core.exceptions import ObjectDoesNotExist 
     
    4855 
    4956  def load_macro(macro_name): # {{{ 
     57    # XXX: hack to include pre-defined macro 
     58    if macro_name == '__param__': 
     59      def _page_param(): 
     60        return page_param 
     61      return _page_param 
     62 
    5063    try: 
    5164      macro = Macro.objects.get(name = macro_name) 
     
    119132    context = RequestContext(request, { 
    120133      'name': page_name, 
     134      'real_name': page_name, 
    121135      'form': page_form, 
    122136      'body_raw': page.content, 
     
    139153    context = RequestContext(request, { 
    140154      'name': page_name, 
     155      'real_name': page_name, 
    141156      'form': page_form, 
    142157      'body_raw': page.content, 
     
    167182  context = RequestContext(request, { 
    168183    'name': page_name, 
     184    'real_name': page_name, 
    169185    'form': page_form, 
    170186    'body_raw':  None, 
     
    196212  context = RequestContext(request, { 
    197213    'name': page_name, 
     214    'real_name': page_name, 
    198215    'form_target': "%s?remove=%s" % (request.path, request.GET.get('remove', "")), 
    199216    'confirmed': ('confirm' in request.POST), 
     
    219236    rev = None 
    220237    page = load_wiki_or_null(page_name) 
     238    if page: 
     239      real_name = page.name 
     240    else: 
     241      real_name = page_name 
    221242 
    222243  context = RequestContext(request, { 
    223244    'name': page_name, 
     245    'real_name': real_name, 
    224246    'body_raw':  None, 
    225247    'body_tree': None, 
     
    229251  if page != None: 
    230252    context['body_raw']  = page.content 
    231     context['body_tree'] = call_all_macros(page.get_ast(), request, page_name) 
     253    context['body_tree'] = call_all_macros( 
     254      page.get_ast(), request, page_name, page_name[len(real_name):] 
     255    ) 
    232256 
    233257  return HttpResponse(template.render(context)) 
Note: See TracChangeset for help on using the changeset viewer.