Exemple #1
0
    def new_paste(self, language=None):
        """The 'create a new paste' view."""
        language = local.request.args.get('language', language)
        if language is None:
            language = 'text'

        code = error = ''
        show_captcha = False
        private = local.application.pastes_private
        parent = None
        req = local.request
        getform = req.form.get

        if local.request.method == 'POST':
            code = getform('code', u'')
            language = getform('language')

            parent_id = getform('parent')
            if parent_id is not None:
                parent = Paste.get(parent_id)

            spam = getform('webpage') or antispam.is_spam(code)
            if spam:
                error = _('your paste contains spam')
                captcha = getform('captcha')
                if captcha:
                    if check_hashed_solution(captcha):
                        error = None
                    else:
                        error = _('your paste contains spam and the '
                                  'CAPTCHA solution was incorrect')
                show_captcha = True
            if code and language and not error:
                private = coalesce_private(private, 'private' in req.form)
                paste = Paste(code, language, parent, None, bool(private))
                db.session.add(paste)
                db.session.commit()
                return redirect(paste.url)

        else:
            parent_id = req.values.get('reply_to')
            if parent_id is not None:
                parent = Paste.get(parent_id)
                if parent is not None:
                    code = parent.code
                    language = parent.language
                    private = coalesce_private(private, parent.private)

        return render_to_response('new_paste.html',
            languages=list_languages(),
            parent=parent,
            code=code,
            language=language,
            error=error,
            show_captcha=show_captcha,
            private=private
        )
Exemple #2
0
 def show_tree(self, identifier):
     """Display the tree of some related pastes."""
     paste = Paste.resolve_root(identifier)
     if paste is None:
         raise NotFound()
     return render_to_response('paste_tree.html',
         paste=paste,
         current=identifier
     )
Exemple #3
0
    def show_paste(self, identifier, raw=False):
        """Show an existing paste."""
        linenos = local.request.args.get('linenos') != 'no'
        paste = Paste.get(identifier)
        if paste is None:
            raise NotFound()
        if raw:
            return Response(paste.code, mimetype='text/plain; charset=utf-8')

        style, css = get_style(local.request)
        return render_to_response('show_paste.html',
            paste=paste,
            style=style,
            css=css,
            styles=STYLES,
            linenos=linenos,
        )
Exemple #4
0
    def compare_paste(self, new_id=None, old_id=None):
        """Render a diff view for two pastes."""
        getform = local.request.form.get
        # redirect for the compare form box
        if old_id is None:
            old_id = getform('old', '-1').lstrip('#')
            new_id = getform('new', '-1').lstrip('#')
            return redirect('/compare/%s/%s' % (old_id, new_id))

        old = Paste.get(old_id)
        new = Paste.get(new_id)
        if old is None or new is None:
            raise NotFound()

        return render_to_response('compare_paste.html',
            old=old,
            new=new,
            diff=old.compare_to(new, template=True)
        )
Exemple #5
0
 def handle_request(self):
     if local.request.args.get("method"):
         return json.handle_request()
     return render_to_response("json.html")
Exemple #6
0
 def removal(self):
     return render_to_response('removal.html')
Exemple #7
0
 def not_found(self):
     return render_to_response('not_found.html')
Exemple #8
0
 def handle_request(self):
     if local.request.method == 'POST':
         return xmlrpc.handle_request()
     return render_to_response('xmlrpc.html')