Attachment 'quiz_action.py'

Download

   1 def save_the_page(pagename, request, text=u''):
   2     from MoinMoin.Page import Page
   3     from MoinMoin.PageEditor import PageEditor
   4 
   5     _ = request.getText
   6 
   7     if not request.user.may.write(pagename):
   8         Page(request, pagename).send_page(request,
   9             msg = _('You are not allowed to edit this page.'))
  10         return
  11 
  12     pg = PageEditor(request, pagename)
  13     savetext = pg.getACL(request).getString() + text
  14     rev = 0
  15     comment = u'Quiz answers'
  16     rstrip = 0
  17     trivial = 0
  18 
  19     # IMPORTANT: normalize text from the form. This should be done in
  20     # one place before we manipulate the text.
  21     savetext = pg.normalizeText(savetext, stripspaces=rstrip)
  22     try:
  23         savemsg = pg.saveText(savetext, rev, trivial=trivial, comment=comment)
  24     except pg.EditConflict, msg:
  25         savemsg = _(u'Someone else changed this page while you were editing!')
  26     except pg.SaveError, msg:
  27         # msg contain a unicode string
  28         savemsg = unicode(msg)
  29 
  30     # Send new page after save or after unsuccessful conflict merge.
  31     request.reset()
  32     backto = request.form.get('backto', [None])[0]
  33     if backto:
  34         pg = Page(request, backto)
  35     pg.send_page(request, msg=savemsg)
  36 
  37 def execute(pagename, request):
  38     if request.user:
  39         user = request.user.name or 'anonymous'
  40     else:
  41         user = 'anonymous'
  42     text = u'' #u'#acl %s:read,write GrupaWyk³adowcy:read,write,admin,delete All:'%user
  43     quiz = request.form.iteritems()
  44     for question, answers in quiz:
  45         if question!='action':
  46             text += ' %s::\n'%question
  47             for answer in answers:
  48                 text += '  * %s\n'%answer
  49                                 
  50     save_the_page(pagename+'/'+user, request, text)

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] (2008-09-08 12:05:39, 0.1 KB) [[attachment:quiz_I.py]]
  • [get | view] (2008-09-08 12:05:20, 0.3 KB) [[attachment:quiz_O.py]]
  • [get | view] (2008-09-08 12:04:20, 0.3 KB) [[attachment:quiz_X.py]]
  • [get | view] (2008-09-08 12:03:39, 1.7 KB) [[attachment:quiz_action.py]]
  • [get | view] (2008-09-08 12:04:00, 7.2 KB) [[attachment:quiz_parser.py]]
  • [get | view] (2008-09-08 12:06:01, 5.8 KB) [[attachment:quiz_score.py]]
  • [get | view] (2008-09-08 12:06:19, 6.2 KB) [[attachment:test_score.py]]
 All files | Selected Files: delete move to page copy to page

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