コード例 #1
0
ファイル: proposal.py プロジェクト: coderanger/pynomic
 def get(self, id):
     prop = Proposal.get_by_id(int(id))
     if self.request.get('change'):
         self._handle_change(prop, self.request.get('change'))
         return
     changes_db = Change.all().ancestor(prop).order('created').fetch(100)
     changes = []
     lexer = pygments.lexers.get_lexer_by_name('diff')
     formatter = pygments.formatters.get_formatter_by_name('html', nobackground=True)
     for change_db in changes_db:
         change = {
             'db': change_db,
         }
         if change_db.class_name() == 'PatchChange':
             change['type'] = 'patch'
             change['highlighted'] = pygments.highlight(change_db.diff, lexer, formatter)
         elif change_db.class_name() == 'BinaryChange':
             mime_type, encoding = mimetypes.guess_type(change_db.path, False)
             if mime_type.startswith('image'):
                 change['type'] = 'image'
             else:
                 change['type'] = 'binary'
         changes.append(change)
     
     vote = prop.get_vote(user)
     add_stylesheet(self.request, '/pygments.css')
     self.response.out.write(self.env.get_template('proposal_view.html').render(locals()))
コード例 #2
0
ファイル: proposal.py プロジェクト: coderanger/pynomic
 def _handle_apply(self, id):
     if not users.is_current_user_admin():
         self.redirect(self.request.path)
         return
     prop = Proposal.get_by_id(int(id))
     changes = Change.all().ancestor(prop).order('created').fetch(100)
     def txn():
         for change in changes:
             change.apply()
     #db.run_in_transaction(txn)
     txn()
     self.redirect(self.request.path)