Changeset 1831

Show
Ignore:
Timestamp:
02/20/09 08:22:34 (18 months ago)
Author:
JensDiemer
Message:
Location:
trunk/pylucid_project
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid_project/media/PyLucid/internal_page/page_admin/edit_page.css

    r1466 r1831  
    3434#input_fields label { 
    3535    float: left; 
    36     padding-right: 4px; 
     36    padding: 0.4em; 
    3737    text-align: right; 
    38     width: 9em; 
     38    width: 11em; 
    3939} 
    4040#input_fields input, #input_fields select { 
    4141    width: 35%; 
     42} 
     43#input_fields input[type=submit] { 
     44    width: auto; 
    4245} 
    4346 
     
    5053    width: 75%; 
    5154} 
    52 #input_fields .edit_comment .field_help_text, 
    53 #input_fields .keywords .field_help_text, 
    54 #input_fields .description .field_help_text { 
     55#input_fields .field_help_text { 
    5556    /* setup the help text for keywords and description */ 
    5657    /* put the help text for bigger input field in the second line */ 
     
    5859    padding-left: 14em; 
    5960} 
     61#input_fields input[type=checkbox] { 
     62    /* help text after a checkbox should not printed in the next line */ 
     63    float: left; 
     64} 
     65 
    6066#input_fields textarea, hr.seperator, #action_buttons { 
    6167    /* make the space between the action buttons and the text area smaller */ 
  • trunk/pylucid_project/media/PyLucid/internal_page/page_admin/edit_page.html

    r1650 r1831  
    6565        {% endfor %} 
    6666    </ul> 
     67     
     68    <fieldset> 
     69    <legend>{% trans 'Change/convert markup' %}</legend> 
     70    <ul id="input_fields"> 
     71        {% for field in markup_form %} 
     72            <li title="{{ field.help_text }}" class="{{ field.html_name }}"> 
     73            <label for="{{ field.auto_id }}">{{ field.label }} :</label> 
     74            {{ field }} 
     75            <input type="submit" name="submit_{{ field.html_name }}" value="{% trans 'preview' %}" /> 
     76            <br /> 
     77            <span class="field_help_text">{{ field.help_text }}</span> 
     78            {% if field.errors %}<li class="field_errors">{{ field.errors }}</li>{% endif %} 
     79        </li> 
     80        {% endfor %} 
     81    </ul> 
     82    </fieldset> 
    6783</form> 
    6884</fieldset> 
  • trunk/pylucid_project/PyLucid/models/Page.py

    r1769 r1831  
    88    Last commit info: 
    99    ~~~~~~~~~~~~~~~~~ 
    10     $LastChangedDate: $ 
    11     $Rev: $ 
    12     $Author: $ 
     10    $LastChangedDate$ 
     11    $Rev$ 
     12    $Author$ 
    1313 
    1414    :copyleft: 2007-2008 by the PyLucid team, see AUTHORS for more details. 
     
    2727from PyLucid.tools.shortcuts import getUniqueShortcut 
    2828from PyLucid.system.exceptions import AccessDenied, LowLevelError 
    29  
    30  
    31 MARKUPS = ( 
    32     (6, u'Creole wiki markup'), 
    33     (0, u'html'), 
    34     (1, u'html + TinyMCE'), 
    35     (2, u'textile'), 
    36     (3, u'Textile (original)'), 
    37     (4, u'Markdown'), 
    38     (5, u'ReStructuredText'), 
    39 ) 
    4029 
    4130 
     
    171160    http://code.djangoproject.com/wiki/Signals 
    172161    """ 
     162     
     163    # IDs used in other parts of PyLucid, too   
     164    MARKUP_CREOLE       = 6 
     165    MARKUP_HTML         = 0 
     166    MARKUP_HTML_EDITOR  = 1 
     167    MARKUP_TINYTEXTILE  = 2 
     168    MARKUP_TEXTILE      = 3 
     169    MARKUP_MARKDOWN     = 4 
     170    MARKUP_REST         = 5 
     171     
     172    MARKUP_CHOICES = ( 
     173        (MARKUP_CREOLE      , u'Creole wiki markup'), 
     174        (MARKUP_HTML        , u'html'), 
     175        (MARKUP_HTML_EDITOR , u'html + JS-Editor'), 
     176        (MARKUP_TINYTEXTILE , u'textile'), 
     177        (MARKUP_TEXTILE     , u'Textile (original)'), 
     178        (MARKUP_MARKDOWN    , u'Markdown'), 
     179        (MARKUP_REST        , u'ReStructuredText'), 
     180    ) 
     181    MARKUP_DICT = dict(MARKUP_CHOICES) 
     182    #-------------------------------------------------------------------------- 
    173183 
    174184    objects = PageManager() 
     
    210220    markup = models.IntegerField( 
    211221        db_column="markup_id", # Use the old column name. 
    212         max_length=1, choices=MARKUPS, 
     222        max_length=1, choices=MARKUP_CHOICES, 
    213223        help_text="the used markup language for this page", 
    214224    ) 
     
    472482    markup = models.IntegerField( 
    473483        db_column="markup_id", # Use the old column name. 
    474         max_length=1, choices=MARKUPS, 
     484        max_length=1, choices=Page.MARKUP_CHOICES, 
    475485        help_text="the used markup language for this page", 
    476486    ) 
  • trunk/pylucid_project/PyLucid/models/__init__.py

    r1660 r1831  
    1717""" 
    1818 
    19 from Page import Page, PageArchiv, MARKUPS 
     19from Page import Page, PageArchiv 
    2020from Plugin import Plugin, Preference 
    2121from JS_LoginData import JS_LoginData, User 
  • trunk/pylucid_project/PyLucid/plugins_internal/page_admin/page_admin.py

    r1724 r1831  
    2929 
    3030from django import forms 
    31 from django.forms import ValidationError 
    3231from django.http import HttpResponse, HttpResponseRedirect 
    33 from django.core.cache import cache 
    3432from django.utils.translation import ugettext as _ 
    3533from django.utils.safestring import mark_safe 
    3634 
     35 
    3736from django.conf import settings 
    38 from PyLucid.models import Page, Plugin, MARKUPS 
    39 from PyLucid.db.page import flat_tree_list, get_sitemap_tree 
     37from PyLucid.models import Page, Plugin 
    4038from PyLucid.db.page_archiv import archive_page 
     39from PyLucid.system.markups.creole import html2creole 
    4140from PyLucid.system.BasePlugin import PyLucidBasePlugin 
    42 from PyLucid.system.plugin_import import get_plugin_module 
     41from PyLucid.plugins_internal.page_style.page_style import replace_add_data 
    4342from PyLucid.tools.content_processors import apply_markup, \ 
    4443                                                        render_string_template 
    45 from PyLucid.plugins_internal.page_style.page_style import replace_add_data 
    46  
    47 from PyLucid.db.page import PageChoiceField, get_page_choices, flat_tree_list 
     44from PyLucid.db.page import PageChoiceField, get_page_choices, \ 
     45                                            flat_tree_list, get_sitemap_tree 
    4846 
    4947 
     
    5250# Keys must be correspond with PyLucid.models.MARKUPS 
    5351HELP_INFO = { 
    54     2: u'markup_help_tinyTextile', 
    55     6: u'markup_help_creole', 
     52    Page.MARKUP_TINYTEXTILE: u'markup_help_tinyTextile', 
     53    Page.MARKUP_CREOLE: u'markup_help_creole', 
    5654} 
    5755 
     
    8179        max_length=255, required=False, help_text=_("A long page title"), 
    8280    ) 
    83     markup = forms.IntegerField( 
    84         widget=forms.Select(choices=MARKUPS), 
    85         help_text=_("the used markup language for this page"), 
    86     ) 
    87  
    8881    keywords = forms.CharField( 
    8982        max_length=255, required=False, 
     
    109102#______________________________________________________________________________ 
    110103 
     104 
     105 
     106# Use only supported markups for converting choice field 
     107CONVERT_MARKUPS = [entry for entry in Page.MARKUP_CHOICES 
     108    if entry[0] in ( 
     109        Page.MARKUP_CREOLE, Page.MARKUP_HTML, Page.MARKUP_HTML_EDITOR 
     110    ) 
     111] 
     112 
     113class MarkupForm(forms.Form): 
     114    markup = forms.IntegerField( 
     115        widget=forms.Select(choices=Page.MARKUP_CHOICES), 
     116        help_text=_( 
     117            "the used markup language for this page (without converting!)" 
     118        ), 
     119    ) 
     120    dest_markup = forms.IntegerField( 
     121        widget=forms.Select(choices=CONVERT_MARKUPS), 
     122        help_text=_("convert the current page data to a new markup"), 
     123    ) 
     124 
     125 
     126 
     127 
     128#______________________________________________________________________________ 
     129 
    111130class SelectEditPageForm(forms.Form): 
    112131    page_id = forms.IntegerField() 
     132 
     133#______________________________________________________________________________ 
     134 
     135 
     136def change_formdata(form, new_data): 
     137    """ 
     138    Update form data, after the form instance was validated. 
     139     
     140    Used in page_admin._convert_markup() 
     141    
     142    form.data is a django.http.QueryDict with POST data 
     143    we must change it to mutable. 
     144     
     145    FIXME: Ugly way to update data 
     146    http://www.python-forum.de/topic-17894.html (de) 
     147    """ 
     148    old_mutable = form.data._mutable   
     149    form.data._mutable = True 
     150    form.data.update(new_data) 
     151    form.data._mutable = old_mutable 
     152 
    113153 
    114154#______________________________________________________________________________ 
     
    154194        self.context["PAGE"] = page_instance 
    155195 
    156     def _save_edited_page(self, page_instance, html_form): 
     196    def _save_edited_page(self, page_instance, page_form, markup_form): 
    157197        """ 
    158198        Save a edited page into the database. 
     
    165205        if page_instance.id == self.current_page.id: 
    166206            # A existing page was edited 
    167             edit_comment = html_form.cleaned_data.pop("edit_comment") 
     207            edit_comment = page_form.cleaned_data.pop("edit_comment") 
    168208            # achive the old page data: 
    169209            archive_page(self.current_page, edit_comment) 
     
    171211 
    172212        # Assign parent page 
    173         parent_page_id = html_form.cleaned_data.pop("parent") 
     213        parent_page_id = page_form.cleaned_data.pop("parent") 
    174214        if parent_page_id != None: 
    175215            parent = Page.objects.get(id=parent_page_id) 
     
    179219 
    180220        # Transfer the form values into the page instance 
    181         for key, value in html_form.cleaned_data.iteritems(): 
     221        for key, value in page_form.cleaned_data.iteritems(): 
    182222            setattr(page_instance, key, value) 
     223        page_instance.markup = markup_form.cleaned_data["markup"] 
    183224 
    184225        try: 
     
    198239            # refresh the current page data: 
    199240            self._refresh_curent_page(page_instance) 
    200  
     241             
     242 
     243    def _convert_markup(self, content, page_form, markup_form): 
     244        """ 
     245        Convert the page markup in a POST preview. 
     246        After a succsessfull convert, we update the form instance data. 
     247        """ 
     248        dest_markup = markup_form.cleaned_data["dest_markup"] 
     249        markup_name = Page.MARKUP_DICT[dest_markup] 
     250         
     251        if dest_markup == Page.MARKUP_CREOLE: 
     252            try: 
     253                new_content = html2creole( 
     254                    html_string=content, debug=self.request.debug 
     255                ) 
     256            except Exception, err: 
     257                self.page_msg.red( 
     258                    "Error converting markup to '%s': %s" % (markup_name, err) 
     259                ) 
     260                return 
     261        else: 
     262            # Only 'html' left as the new "markup" 
     263            new_content = content 
     264         
     265        # Update form instance data for display the converted new content 
     266        change_formdata(page_form, {"content": new_content}) 
     267         
     268        # update the old page markup to the new destination markup 
     269        change_formdata(markup_form, {"markup": dest_markup}) 
     270         
     271        self.page_msg.green( 
     272            "Markup successfull converted to '%s'" % markup_name 
     273        ) 
     274 
     275    def _preview(self, context, page_form, markup_form): 
     276        # Apply the markup witch is selected in the form 
     277        content = apply_markup( 
     278            page_form.cleaned_data["content"], 
     279            self.context, 
     280            markup_form.cleaned_data["markup"] 
     281        ) 
     282         
     283        if "submit_dest_markup" in self.request.POST: 
     284            # We should convert the markup 
     285            self._convert_markup(content, page_form, markup_form)                     
     286 
     287        preview_escape = page_form.cleaned_data["preview_escape"] 
     288        if preview_escape == True: 
     289            # escape django template tags for preview 
     290            content = escape_django_tags(content) 
     291 
     292        content = render_string_template(content, self.context) 
     293        context["preview_content"] = content 
    201294 
    202295    def edit_page(self, edit_page_id=None, new_page_instance=None): 
     
    233326        if self.request.method != 'POST': 
    234327            parent = getattr(page_instance.parent, "id", 0) # Root is None 
    235  
    236             html_form = EditPageForm({ 
     328             
     329            markup_form = MarkupForm({ 
     330                "markup": current_markup, 
     331                "dest_markup": Page.MARKUP_CREOLE, 
     332            }) 
     333 
     334            page_form = EditPageForm({ 
    237335                "content": page_instance.content, 
    238336                "parent": parent, 
    239337                "name": page_instance.name, 
    240338                "title": page_instance.title, 
    241                 "markup": current_markup, 
    242339                "keywords": page_instance.keywords, 
    243340                "description": page_instance.description, 
     
    245342            }) 
    246343        else: # POST 
     344            #self.page_msg(self.request.POST) 
    247345            #self.page_msg(dict(self.request.POST)) 
    248             html_form = EditPageForm(self.request.POST) 
    249             if html_form.is_valid(): 
    250                 if "preview" in self.request.POST: 
    251                     cleaned_data = html_form.cleaned_data 
    252                     content = apply_markup( 
    253                         cleaned_data["content"], self.context, 
    254                         cleaned_data["markup"] 
    255                     ) 
    256  
    257                     preview_escape = cleaned_data["preview_escape"] 
    258                     if preview_escape == True: 
    259                         # escape django template tags for preview 
    260                         content = escape_django_tags(content) 
    261  
    262                     content = render_string_template(content, self.context) 
    263                     context["preview_content"] = content 
    264  
    265                     # Use the current selected markup 
    266                     current_markup = html_form.cleaned_data["markup"] 
     346             
     347            markup_form = MarkupForm(self.request.POST) 
     348            page_form = EditPageForm(self.request.POST) 
     349             
     350            if page_form.is_valid() and markup_form.is_valid(): 
     351                if "preview" in self.request.POST or \ 
     352                                "submit_markup" in self.request.POST or \ 
     353                                "submit_dest_markup" in self.request.POST: 
     354                    self._preview(context, page_form, markup_form) 
     355                     
     356                    # For later use 
     357                    current_markup = markup_form.cleaned_data["markup"] 
    267358 
    268359                elif "save" in self.request.POST: 
    269360                    # Save the new page data. returns a new page instance 
    270                     return self._save_edited_page(page_instance, html_form) 
     361                    return self._save_edited_page( 
     362                        page_instance, page_form, markup_form 
     363                    ) 
    271364                else: 
    272365                    self.page_msg.red("Form error!") 
    273366 
    274         context["edit_page_form"] = html_form 
     367 
     368        context["markup_form"] = markup_form 
     369        context["edit_page_form"] = page_form 
    275370 
    276371        # Edit in the django admin panel:# 
     
    291386            context["help_link"] = self.URLs.methodLink( 
    292387                "markup_help", current_markup 
     388         
    293389            ) 
    294390            # TODO: make help link working 
  • trunk/pylucid_project/PyLucid/tools/content_processors.py

    r1830 r1831  
    149149    return HtmlEmitter(document, macros=PyLucid_creole_macros, verbose=1).emit() 
    150150 
     151from PyLucid.models import Page 
     152 
     153 
    151154 
    152155def apply_markup(content, context, markup_no): 
     
    159162    page_msg = request.page_msg 
    160163 
    161     if markup_no == 2: # textile 
     164    if markup_no == Page.MARKUP_TINYTEXTILE: # PyLucid's TinyTextile 
    162165        content = apply_tinytextile(content, context) 
    163     elif markup_no == 3: # Textile (original) 
     166         
     167    elif markup_no == Page.MARKUP_TEXTILE: # Textile (original) 
    164168        content = apply_textile(content, page_msg) 
    165     elif markup_no == 4: # Markdown 
     169         
     170    elif markup_no == Page.MARKUP_MARKDOWN: 
    166171        content = apply_markdown(content, page_msg) 
    167     elif markup_no == 5: # ReStructuredText 
     172         
     173    elif markup_no == Page.MARKUP_REST: 
    168174        content = apply_restructuretext(content, page_msg) 
    169     elif markup_no == 6: # Creole wiki markup 
     175         
     176    elif markup_no == Page.MARKUP_CREOLE: 
    170177        content = apply_creole(content) 
    171178