Show
Ignore:
Timestamp:
05/23/08 16:33:49 (22 months ago)
Author:
JensDiemer
Message:

new page_msg system. Use a middleware to make page_msg lazy: ticket:193

  • update settings_example.py (insert new middleware)
  • change """contextpage_msg?""" to """request.page_msg"""
  • add a simple page_msg unittest (Need more tests!)
  • update _install data (Templates and index page)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/install/update.py

    r1584 r1585  
    1919 
    2020#______________________________________________________________________________ 
     21 
     22import re 
     23from PyLucid.tools.Diff import diff_lines as _diff_lines 
     24 
     25PAGE_MSG_RE = re.compile(r"""{% if messages %}.*?{% endif %}(?uims)""") 
     26NEW_PAGE_MSG_TAG = "<!-- page_messages -->" 
     27BACKUP_NAME_SUFFIX = " auto backup" 
     28 
    2129class Update2(BaseInstall): 
    2230    def view(self): 
    2331        self._redirect_execute(self._update_tables) 
     32        self._redirect_execute(self._update_templates) 
    2433 
    2534        return self._simple_render( 
    26             headline="Update PyLucid from v0.8.0 to v0.8.1" 
     35            headline="Update PyLucid from v0.8.0 to v0.8.5" 
    2736        ) 
    2837 
    2938    def _update_tables(self): 
    30         print "update database tables:" 
     39        print "*** update database tables:" 
    3140        for table_name in ("pagesinternal", "markup"): 
    3241            try: 
     
    4049                print "OK" 
    4150 
     51    def _update_templates(self): 
     52        print "\n*** update templates:" 
     53        templates = Template.objects.all() 
     54        for template in templates: 
     55            old_id = template.id 
     56 
     57            print "_"*79 
     58            print "process template '%s':" % template.name 
     59 
     60            if BACKUP_NAME_SUFFIX in template.name: 
     61                #template.delete() 
     62                print "Skip!" 
     63                continue 
     64 
     65            old_content = template.content 
     66            new_content = PAGE_MSG_RE.sub(NEW_PAGE_MSG_TAG, old_content) 
     67            if old_content == new_content: 
     68                print "Old tag not found or changes applied in the past." 
     69                continue 
     70 
     71            print "result diff:" 
     72            diff = _diff_lines(old_content, new_content) 
     73            print diff 
     74            print "-"*79 
     75 
     76            original_name = template.name 
     77            backup_name = original_name + BACKUP_NAME_SUFFIX 
     78            print "Create backup template '%s'..." % backup_name, 
     79 
     80            try: 
     81                bak_template = Template.objects.get(name=backup_name) 
     82            except Template.DoesNotExist: 
     83                # ok, create backup 
     84                template.name = backup_name 
     85                template.id = None 
     86                template.save() 
     87                print "OK" 
     88            else: 
     89                print "\nError: A template with the name '%s' exists." % ( 
     90                    backup_name 
     91                ) 
     92                print "Skip update!" 
     93                continue 
     94 
     95            template.name = original_name 
     96            template.id = old_id 
     97 
     98            print "save new content...", 
     99            template.content = new_content 
     100            template.save() 
     101            print "OK" 
    42102 
    43103def update2(request): 
    44104    """ 
    45     1. update from v0.8.0 to v0.8.1 
     105    1. update from v0.8.0 to v0.8.5 
    46106    """ 
    47107    return Update2(request).start_view() 
     
    428488    "<lucid(Function):(.*?)>(.*?)</lucidFunction>" 
    429489) 
    430 PAGE_MSG_TAG = """\ 
    431   {% if messages %} 
    432     <fieldset id="page_msg"><legend>page message</legend> 
    433     {% for message in messages %} 
    434       {{ message }}<br /> 
    435     {% endfor %} 
    436     </fieldset> 
    437   {% endif %}\ 
    438 """ 
    439490 
    440491CHANGE_TAGS = { 
    441     "page_msg": PAGE_MSG_TAG, 
     492    "page_msg": "<!-- page_messages -->", 
    442493    "script_login": "{{ login_link }}", 
    443494    "robots": "{{ robots }}",