Attachment 'savedict.py'

Download

   1 # -*- coding: utf-8 -*-
   2 """
   3     MoinMoin - edit a page containing dict formatted data
   4 
   5     @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
   6                 2006 MoinMoin:ThomasWaldmann,
   7                 2012 Gordon Messmer <gordon@dragonsdawn.net>
   8 
   9     @license: GNU GPL, see COPYING for details.
  10 """
  11 from MoinMoin import wikiutil
  12 from MoinMoin.Page import Page
  13 from MoinMoin.web.utils import check_surge_protect
  14 from MoinMoin.datastruct.backends.wiki_dicts import WikiDict
  15 
  16 def execute(pagename, request):
  17     """ edit a page """
  18     _ = request.getText
  19 
  20     vardict = request.form.get('vardict')
  21 
  22     if not request.user.may.write(vardict):
  23         page = wikiutil.getLocalizedPage(request, 'PermissionDeniedPage')
  24         page.body = _('You are not allowed to edit this page.')
  25         page.page_name = pagename
  26         page.send_page(send_special=True)
  27         return
  28 
  29     # Load the existing dict values
  30     d = request.dicts.get(vardict, {})
  31 
  32     # Check acl only if dictionary is defined on a wiki page.
  33     if isinstance(d, WikiDict) and not request.user.may.read(vardict):
  34         raise ValueError(_('You don\'t have enough rights on this page'))
  35 
  36     savedict = {}
  37     for k in d:
  38         savedict[k] = d[k]
  39     for k in request.form:
  40         if k in ('vardict',):
  41             continue
  42         savedict[k] = request.form.get(k)
  43 
  44     savetext = u''
  45     for k in savedict:
  46         savetext = u''.join((savetext, u' ', k, u':: ', savedict[k], u'\n'))
  47     rev = request.rev or 0
  48 
  49     # Save new text
  50     from MoinMoin.PageEditor import PageEditor
  51     pg = PageEditor(request, vardict)
  52     try:
  53         savemsg = pg.saveText(savetext, rev)
  54     except pg.EditConflict, e:
  55         msg = e.message
  56 
  57         # Handle conflict and send editor
  58         pg.set_raw_body(savetext, modified=1)
  59 
  60         pg.mergeEditConflict(rev)
  61         # We don't send preview when we do merge conflict
  62         pg.sendEditor(msg=msg)
  63         return
  64 
  65     except pg.SaveError, msg:
  66         # Show the error message
  67         request.theme.add_msg(unicode(msg), 'error')
  68         # And show the editor again
  69         pg.sendEditor(preview=savetext, staytop=1)
  70         return
  71 
  72     # Send new page after successful save
  73     request.reset()
  74     pg = Page(request, pagename)
  75 
  76     # sets revision number to default for further actions
  77     request.rev = 0
  78     request.theme.add_msg(savemsg, 'info')
  79     pg.send_page()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2013-03-03 18:20:33, 34.3 KB) [[attachment:COPYING]]
  • [get | view] (2013-03-03 18:21:12, 1.0 KB) [[attachment:IncludeVal.py]]
  • [get | view] (2013-03-03 18:21:23, 1.3 KB) [[attachment:IncludeWithVals.py]]
  • [get | view] (2013-03-03 18:20:49, 2.3 KB) [[attachment:savedict.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.