Changeset 1831
- Timestamp:
- 02/20/09 08:22:34 (18 months ago)
- Location:
- trunk/pylucid_project
- Files:
-
- 6 modified
-
media/PyLucid/internal_page/page_admin/edit_page.css (modified) (3 diffs)
-
media/PyLucid/internal_page/page_admin/edit_page.html (modified) (1 diff)
-
PyLucid/models/Page.py (modified) (5 diffs)
-
PyLucid/models/__init__.py (modified) (1 diff)
-
PyLucid/plugins_internal/page_admin/page_admin.py (modified) (12 diffs)
-
PyLucid/tools/content_processors.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid_project/media/PyLucid/internal_page/page_admin/edit_page.css
r1466 r1831 34 34 #input_fields label { 35 35 float: left; 36 padding -right: 4px;36 padding: 0.4em; 37 37 text-align: right; 38 width: 9em;38 width: 11em; 39 39 } 40 40 #input_fields input, #input_fields select { 41 41 width: 35%; 42 } 43 #input_fields input[type=submit] { 44 width: auto; 42 45 } 43 46 … … 50 53 width: 75%; 51 54 } 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 { 55 56 /* setup the help text for keywords and description */ 56 57 /* put the help text for bigger input field in the second line */ … … 58 59 padding-left: 14em; 59 60 } 61 #input_fields input[type=checkbox] { 62 /* help text after a checkbox should not printed in the next line */ 63 float: left; 64 } 65 60 66 #input_fields textarea, hr.seperator, #action_buttons { 61 67 /* 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 65 65 {% endfor %} 66 66 </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> 67 83 </form> 68 84 </fieldset> -
trunk/pylucid_project/PyLucid/models/Page.py
r1769 r1831 8 8 Last commit info: 9 9 ~~~~~~~~~~~~~~~~~ 10 $LastChangedDate :$11 $Rev :$12 $Author :$10 $LastChangedDate$ 11 $Rev$ 12 $Author$ 13 13 14 14 :copyleft: 2007-2008 by the PyLucid team, see AUTHORS for more details. … … 27 27 from PyLucid.tools.shortcuts import getUniqueShortcut 28 28 from 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 )40 29 41 30 … … 171 160 http://code.djangoproject.com/wiki/Signals 172 161 """ 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 #-------------------------------------------------------------------------- 173 183 174 184 objects = PageManager() … … 210 220 markup = models.IntegerField( 211 221 db_column="markup_id", # Use the old column name. 212 max_length=1, choices=MARKUP S,222 max_length=1, choices=MARKUP_CHOICES, 213 223 help_text="the used markup language for this page", 214 224 ) … … 472 482 markup = models.IntegerField( 473 483 db_column="markup_id", # Use the old column name. 474 max_length=1, choices= MARKUPS,484 max_length=1, choices=Page.MARKUP_CHOICES, 475 485 help_text="the used markup language for this page", 476 486 ) -
trunk/pylucid_project/PyLucid/models/__init__.py
r1660 r1831 17 17 """ 18 18 19 from Page import Page, PageArchiv , MARKUPS19 from Page import Page, PageArchiv 20 20 from Plugin import Plugin, Preference 21 21 from JS_LoginData import JS_LoginData, User -
trunk/pylucid_project/PyLucid/plugins_internal/page_admin/page_admin.py
r1724 r1831 29 29 30 30 from django import forms 31 from django.forms import ValidationError32 31 from django.http import HttpResponse, HttpResponseRedirect 33 from django.core.cache import cache34 32 from django.utils.translation import ugettext as _ 35 33 from django.utils.safestring import mark_safe 36 34 35 37 36 from django.conf import settings 38 from PyLucid.models import Page, Plugin, MARKUPS 39 from PyLucid.db.page import flat_tree_list, get_sitemap_tree 37 from PyLucid.models import Page, Plugin 40 38 from PyLucid.db.page_archiv import archive_page 39 from PyLucid.system.markups.creole import html2creole 41 40 from PyLucid.system.BasePlugin import PyLucidBasePlugin 42 from PyLucid. system.plugin_import import get_plugin_module41 from PyLucid.plugins_internal.page_style.page_style import replace_add_data 43 42 from PyLucid.tools.content_processors import apply_markup, \ 44 43 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 44 from PyLucid.db.page import PageChoiceField, get_page_choices, \ 45 flat_tree_list, get_sitemap_tree 48 46 49 47 … … 52 50 # Keys must be correspond with PyLucid.models.MARKUPS 53 51 HELP_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', 56 54 } 57 55 … … 81 79 max_length=255, required=False, help_text=_("A long page title"), 82 80 ) 83 markup = forms.IntegerField(84 widget=forms.Select(choices=MARKUPS),85 help_text=_("the used markup language for this page"),86 )87 88 81 keywords = forms.CharField( 89 82 max_length=255, required=False, … … 109 102 #______________________________________________________________________________ 110 103 104 105 106 # Use only supported markups for converting choice field 107 CONVERT_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 113 class 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 111 130 class SelectEditPageForm(forms.Form): 112 131 page_id = forms.IntegerField() 132 133 #______________________________________________________________________________ 134 135 136 def 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 113 153 114 154 #______________________________________________________________________________ … … 154 194 self.context["PAGE"] = page_instance 155 195 156 def _save_edited_page(self, page_instance, html_form):196 def _save_edited_page(self, page_instance, page_form, markup_form): 157 197 """ 158 198 Save a edited page into the database. … … 165 205 if page_instance.id == self.current_page.id: 166 206 # 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") 168 208 # achive the old page data: 169 209 archive_page(self.current_page, edit_comment) … … 171 211 172 212 # Assign parent page 173 parent_page_id = html_form.cleaned_data.pop("parent")213 parent_page_id = page_form.cleaned_data.pop("parent") 174 214 if parent_page_id != None: 175 215 parent = Page.objects.get(id=parent_page_id) … … 179 219 180 220 # 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(): 182 222 setattr(page_instance, key, value) 223 page_instance.markup = markup_form.cleaned_data["markup"] 183 224 184 225 try: … … 198 239 # refresh the current page data: 199 240 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 201 294 202 295 def edit_page(self, edit_page_id=None, new_page_instance=None): … … 233 326 if self.request.method != 'POST': 234 327 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({ 237 335 "content": page_instance.content, 238 336 "parent": parent, 239 337 "name": page_instance.name, 240 338 "title": page_instance.title, 241 "markup": current_markup,242 339 "keywords": page_instance.keywords, 243 340 "description": page_instance.description, … … 245 342 }) 246 343 else: # POST 344 #self.page_msg(self.request.POST) 247 345 #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"] 267 358 268 359 elif "save" in self.request.POST: 269 360 # 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 ) 271 364 else: 272 365 self.page_msg.red("Form error!") 273 366 274 context["edit_page_form"] = html_form 367 368 context["markup_form"] = markup_form 369 context["edit_page_form"] = page_form 275 370 276 371 # Edit in the django admin panel:# … … 291 386 context["help_link"] = self.URLs.methodLink( 292 387 "markup_help", current_markup 388 293 389 ) 294 390 # TODO: make help link working -
trunk/pylucid_project/PyLucid/tools/content_processors.py
r1830 r1831 149 149 return HtmlEmitter(document, macros=PyLucid_creole_macros, verbose=1).emit() 150 150 151 from PyLucid.models import Page 152 153 151 154 152 155 def apply_markup(content, context, markup_no): … … 159 162 page_msg = request.page_msg 160 163 161 if markup_no == 2: # textile164 if markup_no == Page.MARKUP_TINYTEXTILE: # PyLucid's TinyTextile 162 165 content = apply_tinytextile(content, context) 163 elif markup_no == 3: # Textile (original) 166 167 elif markup_no == Page.MARKUP_TEXTILE: # Textile (original) 164 168 content = apply_textile(content, page_msg) 165 elif markup_no == 4: # Markdown 169 170 elif markup_no == Page.MARKUP_MARKDOWN: 166 171 content = apply_markdown(content, page_msg) 167 elif markup_no == 5: # ReStructuredText 172 173 elif markup_no == Page.MARKUP_REST: 168 174 content = apply_restructuretext(content, page_msg) 169 elif markup_no == 6: # Creole wiki markup 175 176 elif markup_no == Page.MARKUP_CREOLE: 170 177 content = apply_creole(content) 171 178