[geany/www.geany.org] 2b7490: Update Pastebin app and mount it on the main site as /p/

Enrico Tröger git-noreply at xxxxx
Sat May 11 13:15:49 UTC 2019


Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Sun, 31 Mar 2019 14:01:54 UTC
Commit:      2b7490b7a3acc81f8629d478d0e1eba90aab98c4
             https://github.com/geany/www.geany.org/commit/2b7490b7a3acc81f8629d478d0e1eba90aab98c4

Log Message:
-----------
Update Pastebin app and mount it on the main site as /p/


Modified Paths:
--------------
    pastebin/management/commands/generate_snippets_css.py
    pastebin/models.py
    pastebin/static/css/pastebin.css
    pastebin/static/css/pygments.css
    pastebin/templates/pastebin/api.html
    pastebin/templates/pastebin/base.html
    pastebin/templates/pastebin/help.html
    pastebin/templates/pastebin/snippet_details.html
    pastebin/templates/pastebin/snippet_form.html
    pastebin/templates/pastebin/snippet_list.html
    pastebin/urls.py
    pastebin/views.py

Modified: pastebin/management/commands/generate_snippets_css.py
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -25,4 +25,4 @@ class Command(BaseCommand):
     def handle(self, *args, **options):
         with open('pastebin/static/css/pygments.css', 'w') as css_file:
             # You can change style and the html class here:
-            css_file.write(HtmlFormatter(style='colorful').get_style_defs('.code'))
+            css_file.write(HtmlFormatter(style='colorful').get_style_defs('.highlight'))


Modified: pastebin/models.py
15 lines changed, 11 insertions(+), 4 deletions(-)
===================================================================
@@ -13,7 +13,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from datetime import timedelta
-from django.core.urlresolvers import reverse
+from django.urls import reverse
 from django.db import models
 from django.utils import timezone
 from django.utils.translation import ugettext_lazy as _
@@ -41,7 +41,12 @@ class Snippet(models.Model):
     lexer = models.CharField(_(u'Lexer'), max_length=30, default=LEXER_DEFAULT)
     published = models.DateTimeField(_(u'Published'), blank=True, db_index=True)
     expires = models.DateTimeField(_(u'Expires'), blank=True, db_index=True)
-    parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
+    parent = models.ForeignKey(
+        'self',
+        null=True,
+        blank=True,
+        related_name='children',
+        on_delete=models.PROTECT)
 
     ########################################################################
     class Meta:
@@ -93,9 +98,11 @@ def content_splitted(self):
 
     #----------------------------------------------------------------------
     def save(self, *args, **kwargs):
-        if not self.pk:
-            self.published = timezone.now()
+        if not self.pk and not self.secret_id:
             self.secret_id = generate_secret_id()
+        if not self.published:
+            self.published = timezone.now()
+
         self.content_highlighted = self.content
         models.Model.save(self, *args, **kwargs)
 


Modified: pastebin/static/css/pastebin.css
9 lines changed, 5 insertions(+), 4 deletions(-)
===================================================================
@@ -35,6 +35,7 @@ form.new-snippet-form {
     margin-left: 5px;
     margin-bottom: 0px;
     width: auto;
+    border: none;
 }
 
 .new-snippet-form ul#id_expire_options li {
@@ -156,7 +157,7 @@ pre {
     background-color: rgb(250, 250, 250);
 }
 
-pre.code {
+pre.highlight {
     font-family: "Bitstream Vera Sans Mono", monospace;
     font-size: 12px;
     line-height: 15px;
@@ -165,12 +166,12 @@ pre.code {
     border: none;
 }
 
-div.line:hover pre.code {
+div.line:hover pre.highlight {
     background-color: #FFFFA6;
 }
 
-pre.code div.line.marked,
-pre.code div.line.marked * {
+pre.highlight div.line.marked,
+pre.highlight div.line.marked * {
     background-color: #BAE688 !important;
 }
 /*


Modified: pastebin/static/css/pygments.css
132 lines changed, 69 insertions(+), 63 deletions(-)
===================================================================
@@ -1,63 +1,69 @@
-.code .hll { background-color: #ffffcc }
-.code  { background: #ffffff; }
-.code .c { color: #888888 } /* Comment */
-.code .err { color: #FF0000; background-color: #FFAAAA } /* Error */
-.code .k { color: #008800; font-weight: bold } /* Keyword */
-.code .o { color: #333333 } /* Operator */
-.code .cm { color: #888888 } /* Comment.Multiline */
-.code .cp { color: #557799 } /* Comment.Preproc */
-.code .c1 { color: #888888 } /* Comment.Single */
-.code .cs { color: #cc0000; font-weight: bold } /* Comment.Special */
-.code .gd { color: #A00000 } /* Generic.Deleted */
-.code .ge { font-style: italic } /* Generic.Emph */
-.code .gr { color: #FF0000 } /* Generic.Error */
-.code .gh { color: #000080; font-weight: bold } /* Generic.Heading */
-.code .gi { color: #00A000 } /* Generic.Inserted */
-.code .go { color: #888888 } /* Generic.Output */
-.code .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
-.code .gs { font-weight: bold } /* Generic.Strong */
-.code .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
-.code .gt { color: #0044DD } /* Generic.Traceback */
-.code .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
-.code .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
-.code .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
-.code .kp { color: #003388; font-weight: bold } /* Keyword.Pseudo */
-.code .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
-.code .kt { color: #333399; font-weight: bold } /* Keyword.Type */
-.code .m { color: #6600EE; font-weight: bold } /* Literal.Number */
-.code .s { background-color: #fff0f0 } /* Literal.String */
-.code .na { color: #0000CC } /* Name.Attribute */
-.code .nb { color: #007020 } /* Name.Builtin */
-.code .nc { color: #BB0066; font-weight: bold } /* Name.Class */
-.code .no { color: #003366; font-weight: bold } /* Name.Constant */
-.code .nd { color: #555555; font-weight: bold } /* Name.Decorator */
-.code .ni { color: #880000; font-weight: bold } /* Name.Entity */
-.code .ne { color: #FF0000; font-weight: bold } /* Name.Exception */
-.code .nf { color: #0066BB; font-weight: bold } /* Name.Function */
-.code .nl { color: #997700; font-weight: bold } /* Name.Label */
-.code .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
-.code .nt { color: #007700 } /* Name.Tag */
-.code .nv { color: #996633 } /* Name.Variable */
-.code .ow { color: #000000; font-weight: bold } /* Operator.Word */
-.code .w { color: #bbbbbb } /* Text.Whitespace */
-.code .mb { color: #6600EE; font-weight: bold } /* Literal.Number.Bin */
-.code .mf { color: #6600EE; font-weight: bold } /* Literal.Number.Float */
-.code .mh { color: #005588; font-weight: bold } /* Literal.Number.Hex */
-.code .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
-.code .mo { color: #4400EE; font-weight: bold } /* Literal.Number.Oct */
-.code .sb { background-color: #fff0f0 } /* Literal.String.Backtick */
-.code .sc { color: #0044DD } /* Literal.String.Char */
-.code .sd { color: #DD4422 } /* Literal.String.Doc */
-.code .s2 { background-color: #fff0f0 } /* Literal.String.Double */
-.code .se { color: #666666; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
-.code .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */
-.code .si { background-color: #eeeeee } /* Literal.String.Interpol */
-.code .sx { color: #DD2200; background-color: #fff0f0 } /* Literal.String.Other */
-.code .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
-.code .s1 { background-color: #fff0f0 } /* Literal.String.Single */
-.code .ss { color: #AA6600 } /* Literal.String.Symbol */
-.code .bp { color: #007020 } /* Name.Builtin.Pseudo */
-.code .vc { color: #336699 } /* Name.Variable.Class */
-.code .vg { color: #dd7700; font-weight: bold } /* Name.Variable.Global */
-.code .vi { color: #3333BB } /* Name.Variable.Instance */
-.code .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
\ No newline at end of file
+.highlight .hll { background-color: #ffffcc }
+.highlight  { background: #ffffff; }
+.highlight .c { color: #888888 } /* Comment */
+.highlight .err { color: #FF0000; background-color: #FFAAAA } /* Error */
+.highlight .k { color: #008800; font-weight: bold } /* Keyword */
+.highlight .o { color: #333333 } /* Operator */
+.highlight .ch { color: #888888 } /* Comment.Hashbang */
+.highlight .cm { color: #888888 } /* Comment.Multiline */
+.highlight .cp { color: #557799 } /* Comment.Preproc */
+.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
+.highlight .c1 { color: #888888 } /* Comment.Single */
+.highlight .cs { color: #cc0000; font-weight: bold } /* Comment.Special */
+.highlight .gd { color: #A00000 } /* Generic.Deleted */
+.highlight .ge { font-style: italic } /* Generic.Emph */
+.highlight .gr { color: #FF0000 } /* Generic.Error */
+.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+.highlight .gi { color: #00A000 } /* Generic.Inserted */
+.highlight .go { color: #888888 } /* Generic.Output */
+.highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
+.highlight .gs { font-weight: bold } /* Generic.Strong */
+.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+.highlight .gt { color: #0044DD } /* Generic.Traceback */
+.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
+.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
+.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
+.highlight .kp { color: #003388; font-weight: bold } /* Keyword.Pseudo */
+.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
+.highlight .kt { color: #333399; font-weight: bold } /* Keyword.Type */
+.highlight .m { color: #6600EE; font-weight: bold } /* Literal.Number */
+.highlight .s { background-color: #fff0f0 } /* Literal.String */
+.highlight .na { color: #0000CC } /* Name.Attribute */
+.highlight .nb { color: #007020 } /* Name.Builtin */
+.highlight .nc { color: #BB0066; font-weight: bold } /* Name.Class */
+.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
+.highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
+.highlight .ni { color: #880000; font-weight: bold } /* Name.Entity */
+.highlight .ne { color: #FF0000; font-weight: bold } /* Name.Exception */
+.highlight .nf { color: #0066BB; font-weight: bold } /* Name.Function */
+.highlight .nl { color: #997700; font-weight: bold } /* Name.Label */
+.highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
+.highlight .nt { color: #007700 } /* Name.Tag */
+.highlight .nv { color: #996633 } /* Name.Variable */
+.highlight .ow { color: #000000; font-weight: bold } /* Operator.Word */
+.highlight .w { color: #bbbbbb } /* Text.Whitespace */
+.highlight .mb { color: #6600EE; font-weight: bold } /* Literal.Number.Bin */
+.highlight .mf { color: #6600EE; font-weight: bold } /* Literal.Number.Float */
+.highlight .mh { color: #005588; font-weight: bold } /* Literal.Number.Hex */
+.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
+.highlight .mo { color: #4400EE; font-weight: bold } /* Literal.Number.Oct */
+.highlight .sa { background-color: #fff0f0 } /* Literal.String.Affix */
+.highlight .sb { background-color: #fff0f0 } /* Literal.String.Backtick */
+.highlight .sc { color: #0044DD } /* Literal.String.Char */
+.highlight .dl { background-color: #fff0f0 } /* Literal.String.Delimiter */
+.highlight .sd { color: #DD4422 } /* Literal.String.Doc */
+.highlight .s2 { background-color: #fff0f0 } /* Literal.String.Double */
+.highlight .se { color: #666666; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
+.highlight .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */
+.highlight .si { background-color: #eeeeee } /* Literal.String.Interpol */
+.highlight .sx { color: #DD2200; background-color: #fff0f0 } /* Literal.String.Other */
+.highlight .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
+.highlight .s1 { background-color: #fff0f0 } /* Literal.String.Single */
+.highlight .ss { color: #AA6600 } /* Literal.String.Symbol */
+.highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */
+.highlight .fm { color: #0066BB; font-weight: bold } /* Name.Function.Magic */
+.highlight .vc { color: #336699 } /* Name.Variable.Class */
+.highlight .vg { color: #dd7700; font-weight: bold } /* Name.Variable.Global */
+.highlight .vi { color: #3333BB } /* Name.Variable.Instance */
+.highlight .vm { color: #996633 } /* Name.Variable.Magic */
+.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
\ No newline at end of file


Modified: pastebin/templates/pastebin/api.html
19 lines changed, 10 insertions(+), 9 deletions(-)
===================================================================
@@ -10,13 +10,13 @@
 
 <h1>API</h1>
 
-<p>The following Python code can be used as a simple command line client for this
+<p>The following Python 3 code can be used as a simple command line client for this
 Pastebin service:</p>
 
 <pre>#!/usr/bin/env python
 
-import urllib
-import urllib2
+import urllib.request, urllib.parse, urllib.error
+import urllib.request, urllib.error, urllib.parse
 import os
 import sys
 
@@ -25,12 +25,13 @@ <h1>API</h1>
     fields.append(('content', ''.join(sys.stdin.readlines())))
     fields.append(('author', os.getlogin()))
     fields.append(('lexer', 'python'))
-    request = urllib2.Request(
-        'http://{{ request.site.domain }}/api/',
-        urllib.urlencode(fields),
+    encoded_data = urllib.parse.urlencode(fields).encode('utf-8')
+    request = urllib.request.Request(
+        'https://{{ request.site.domain }}{% url 'snippet_api' %}',
+        encoded_data,
     )
-    response = urllib2.urlopen(request)
-    print response.read()[:-1]
+    response = urllib.request.urlopen(request)
+    print(response.read()[:-1])
 
 if __name__ == '__main__':
     paste_code()</pre>
@@ -75,7 +76,7 @@ <h2>Supported fields</h2>
         <td>lexer</td>
         <td class="nowrap">python, text, php, perl, c, bash, ...</td>
         <td>The lexer to be used, all lexers supported by Pygments are possible and
-            also most of Geany's filetype names (geany --ft-names)
+            also most of Geany's filetype names (<code>geany --ft-names</code>)
         </td>
     </tr>
 </tbody>


Modified: pastebin/templates/pastebin/base.html
24 lines changed, 12 insertions(+), 12 deletions(-)
===================================================================
@@ -1,34 +1,34 @@
 {% extends "skel.html" %}
+{% load static %}
 
 {% block meta_title %}Pastebin{% endblock %}
 
 {% block extra_css %}
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/pastebin.css">
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/pygments.css">
+<link rel="stylesheet" type="text/css" href="{% static "css/pastebin.css" %}">
 {% endblock %}
 
 {% block top_menu %}
-{% url 'home' as url_home %}
-{% url 'help' as url_help %}
-{% url 'api' as url_api %}
+{% url 'snippet_new' as url_snippet_new %}
+{% url 'snippet_help' as url_help %}
+{% url 'snippet_help_api' as url_api %}
 {% url 'snippet_list' as url_snippet_list %}
 
 <div class="navbar navbar-inverse navbar-fixed-top">
     <div class="container">
-        <img src="{{ STATIC_URL }}img/geany-36x36.png" class="navbar-brand">
-        <a class="navbar-brand" href="http://www.geany.org/">Geany</a>
+        <img src="{% static "img/geany-36x36.png" %}" class="navbar-brand">
+        <a class="navbar-brand" href="{% url "home" %}">Geany</a>
 
         <ul class="nav navbar-nav">
-            <li class="{% if request.path = url_home %} active{% endif %}">
-                <a href="{{ url_home }}">New snippet</a>
+            <li class="{% if request.path == url_snippet_new %} active{% endif %}">
+                <a href="{{ url_snippet_new }}">New snippet</a>
             </li>
-            <li class="{% if request.path = url_help %} active{% endif %}">
+            <li class="{% if request.path == url_help %} active{% endif %}">
                 <a href="{{ url_help }}">Help</a>
             </li>
-            <li class="{% if request.path = url_api %} active{% endif %}">
+            <li class="{% if request.path == url_api %} active{% endif %}">
                 <a href="{{ url_api }}">API</a>
             </li>
-            <li class="{% if request.path = url_snippet_list %} active{% endif %}">
+            <li class="{% if request.path == url_snippet_list %} active{% endif %}">
                 <a href="{{ url_snippet_list }}">Recent snippets</a>
             </li>
         </ul>


Modified: pastebin/templates/pastebin/help.html
4 lines changed, 2 insertions(+), 2 deletions(-)
===================================================================
@@ -12,8 +12,8 @@ <h2>What is pastebin?</h2>
 <p>This pastebin is here to help you collaborate on debugging code snippets. If you're not familiar with the idea,
 most people use it like this:</p>
 <ul>
-<li><a href="{% url 'home' %}">submit</a> a code fragment to pastebin,
-getting a url like http://{{ request.site.domain }}/abc1234</li>
+<li><a href="{% url 'snippet_new' %}">submit</a> a code fragment to pastebin,
+getting a url like https://{{ request.site.domain }}/p/abc1234</li>
 <li>paste the url into an IRC or IM conversation</li>
 <li>someone responds by reading and perhaps submitting a modification of your code</li>
 </ul>


Modified: pastebin/templates/pastebin/snippet_details.html
6 lines changed, 3 insertions(+), 3 deletions(-)
===================================================================
@@ -43,7 +43,7 @@ <h1>
                 <ol>
                     {% for line in snippet|highlight %}
                         <li id="l{{ forloop.counter }}">
-                            <div class="line"><pre class="code">{% if line %}{{ line|safe }}{% else %} {% endif %}</pre></div>
+                            <div class="line"><pre class="highlight">{% if line %}{{ line|safe }}{% else %} {% endif %}</pre></div>
                         </li>
                     {% endfor %}
                 </ol>
@@ -106,11 +106,11 @@ <h1>
     */
     $('#word_wrap_toggle').toggle(
         function(){
-            $('div.snippet pre.code').css('white-space', 'pre');
+            $('div.snippet pre.highlight').css('white-space', 'pre');
             return false;
         },
         function(){
-            $('div.snippet pre.code').css('white-space', 'pre-wrap');
+            $('div.snippet pre.highlight').css('white-space', 'pre-wrap');
             return false;
         }
     );


Modified: pastebin/templates/pastebin/snippet_form.html
6 lines changed, 1 insertions(+), 5 deletions(-)
===================================================================
@@ -1,6 +1,4 @@
 {% load geany_tags honeypot i18n mezzanine_tags %}
-{% load  %}
-
 
 {% if snippet_form.non_field_errors or snippet_form.errors %}
 <div class="form-errors">
@@ -12,10 +10,8 @@
 </div>
 {% endif %}
 
-<form method="post" action="{% url 'home' %}" class="form-horizontal new-snippet-form" role="form">
-{% nevercache %}
+<form method="post" action="{% url 'snippet_new' %}" class="form-horizontal new-snippet-form" role="form">
 {% csrf_token %}
-{% endnevercache %}
 {% render_honeypot_field %}
 {% for field in snippet_form %}
     <div>


Modified: pastebin/templates/pastebin/snippet_list.html
2 lines changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -17,7 +17,7 @@ <h4>
         ~ {{ snippet.published|date:"Y/m/d G:i:s" }}
     </h4>
     <div class="snippet well snippet_list">
-        <pre class="code">{% for line in snippet|highlight:5 %}<div class="line" id="l{{ forloop.counter }}">{% if line %}{{ line|safe }}{% else %} {% endif %}</div>{% endfor %}</pre>
+        <pre class="highlight">{% for line in snippet|highlight:5 %}<div class="line" id="l{{ forloop.counter }}">{% if line %}{{ line|safe }}{% else %} {% endif %}</div>{% endfor %}</pre>
     </div>
     {% endfor %}
     {% else %}


Modified: pastebin/urls.py
39 lines changed, 14 insertions(+), 25 deletions(-)
===================================================================
@@ -13,8 +13,10 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from django.conf import settings
-from django.conf.urls import include, url
+from django.conf.urls import url
+from django.views.decorators.cache import never_cache
 from django.views.generic.base import TemplateView
+
 from geany.sitemaps import StaticSitemap
 from pastebin.views import (
     LatestSnippetsView,
@@ -25,36 +27,23 @@
     SnippetNewView)
 
 
-urlpatterns = [
-    # no admin on this site
-    url(r'^admin/', 'mezzanine.core.views.page_not_found'),
-
-    url(r'^help/$', TemplateView.as_view(template_name='pastebin/help.html'), name='help'),
-    url(r'^help/api/$', TemplateView.as_view(template_name='pastebin/api.html'), name='api'),
+urlpatterns = (
+    url(r'^help/$', TemplateView.as_view(template_name='pastebin/help.html'), name='snippet_help'),
+    url(r'^help/api/$', TemplateView.as_view(template_name='pastebin/api.html'), name='snippet_help_api'),
 
-    url(r'^api/$', SnippetAPIView.as_view()),
+    url(r'^api/$', never_cache(SnippetAPIView.as_view()), name='snippet_api'),
 
-    url(r'^$', SnippetNewView.as_view(), name='home'),
+    url(r'^$', never_cache(SnippetNewView.as_view()), name='snippet_new'),
     url(r'^latest/$', LatestSnippetsView.as_view(), name='snippet_list'),
     url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/$', SnippetDetailView.as_view(), name='snippet_details'),
     url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/delete/$', SnippetDeleteView.as_view(), name='snippet_delete'),
     url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/raw/$', SnippetDetailRawView.as_view(), name='snippet_details_raw'),
-]
+)
 
-# Django-Debug-Toolbar support
-if settings.DEBUG:
-    import debug_toolbar
-    urlpatterns += (
-        url(r'^__debug__/', include(debug_toolbar.urls)),
-    )
 
 # Sitemap framework
-sitemaps = {"sitemaps": {"all": StaticSitemap(settings.SITE_DOMAIN_PASTEBIN, urlpatterns)}}
-urlpatterns += (
-    # use our custom sitemap implementation
-    url(r"^sitemap\.xml$", 'django.contrib.sitemaps.views.sitemap', sitemaps),
-)
-
-# Adds ``STATIC_URL`` to the context of error pages, so that error pages can use JS, CSS and images.
-handler404 = "mezzanine.core.views.page_not_found"
-handler500 = "mezzanine.core.views.server_error"
+#sitemaps = {"sitemaps": {"all": StaticSitemap(settings.SITE_DOMAIN_PASTEBIN, urlpatterns)}}
+#urlpatterns += (
+#    # use our custom sitemap implementation
+#    url(r"^sitemap\.xml$", 'django.contrib.sitemaps.views.sitemap', sitemaps),
+#)


Modified: pastebin/views.py
33 lines changed, 13 insertions(+), 20 deletions(-)
===================================================================
@@ -14,18 +14,19 @@
 
 from django.conf import settings
 from django.contrib.sites.models import Site
-from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
-from django.core.urlresolvers import reverse
-from django.http import HttpResponseRedirect, HttpResponseBadRequest, HttpResponse
-from django.shortcuts import render_to_response, get_object_or_404
+from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
+from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseRedirect
+from django.shortcuts import get_object_or_404, render
 from django.template.context import RequestContext
 from django.template.response import TemplateResponse
+from django.urls import reverse
 from django.utils import timezone
 from django.utils.decorators import method_decorator
 from django.utils.translation import ugettext_lazy as _
 from django.views.decorators.csrf import csrf_exempt
-from django.views.generic.base import View, TemplateView
+from django.views.generic.base import TemplateView, View
 from honeypot.decorators import check_honeypot
+
 from pastebin.api.create import CreateSnippetApiController, SnippetValidationError
 from pastebin.forms import SnippetForm
 from pastebin.models import Snippet
@@ -65,11 +66,7 @@ def get(self, request):
     def _render_response(self, request, snippet_form):
         snippet_list = _get_snippet_list(no_content=True)
         template_context = dict(snippet_form=snippet_form, snippet_list=snippet_list)
-
-        return render_to_response(
-            self.template_name,
-            template_context,
-            RequestContext(request))
+        return render(request, self.template_name, template_context)
 
     #----------------------------------------------------------------------
     def post(self, request):
@@ -102,9 +99,9 @@ def get(self, request, snippet_id):
         # load snippet
         try:
             snippet = self._fetch_snippet(snippet_id)
-        except SnippetNotFoundError, e:
+        except SnippetNotFoundError as e:
             # 404 response with custom message
-            context = dict(message=unicode(e))
+            context = dict(message=e)
             return TemplateResponse(request, 'errors/404.html', context=context, status=404)
 
         new_snippet_initial = dict(content=snippet.content, lexer=snippet.lexer)
@@ -118,11 +115,7 @@ def get(self, request, snippet_id):
             'lines': range(snippet.get_linecount()),
         }
 
-        response = render_to_response(
-            self.template_name,
-            template_context,
-            RequestContext(request))
-        return response
+        return render(request, self.template_name, template_context)
 
     #----------------------------------------------------------------------
     def _clean_expired_snippets(self):
@@ -178,7 +171,7 @@ def get(self, request, snippet_id):
                 status=403)
 
         snippet.delete()
-        return HttpResponseRedirect(reverse('home'))
+        return HttpResponseRedirect(reverse('snippet_new'))
 
 
 ########################################################################
@@ -208,12 +201,12 @@ def post(self, request):
         try:
             controller = CreateSnippetApiController(request)
             snippet = controller.create()
-        except SnippetValidationError, e:
+        except SnippetValidationError as e:
             return HttpResponseBadRequest(unicode(e), content_type=u'text/plain')
 
         site = self._get_site(request)
         absolute_url = snippet.get_absolute_url()
-        result = u'http://%s%s/' % (site.domain, absolute_url)
+        result = u'https://%s%s/' % (site.domain, absolute_url)
         return HttpResponse(result, content_type=u'text/plain')
 
     #----------------------------------------------------------------------



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list