예제 #1
0
 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
 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)
예제 #3
0
 def _handle_change(self, prop, change_id):
     change = Change.get_by_id(int(change_id), parent=prop)
     if not change:
         send_error(self, 'Change %s not found', change_id, status=404)
         return
     if self.request.get('format') == 'raw':
         if change.class_name() == 'PatchChange':
             self.response.headers['Content-Type'] = 'text/diff'
             self.response.write(change.diff)
         elif change.class_name() == 'BinaryChange':
             mime_type, encoding = mimetypes.guess_type(change.path, False)
             self.response.headers['Content-Type'] = mime_type
             if not mime_type.startswith('image'):
                 self.response.headers['Content-Disposition'] = 'attachment'
             self.response.out.write(change.data)