Merge branch 'master' into develop

This commit is contained in:
Martin Mahner 2013-11-23 15:55:53 +01:00
commit 77c259ee39
8 changed files with 56 additions and 14 deletions

View file

@ -7,7 +7,6 @@ from django.utils.translation import ugettext_lazy as _
from dpaste.models import Snippet from dpaste.models import Snippet
from dpaste.highlight import LEXER_LIST, LEXER_DEFAULT from dpaste.highlight import LEXER_LIST, LEXER_DEFAULT
EXPIRE_CHOICES = ( EXPIRE_CHOICES = (
(3600, _(u'In one hour')), (3600, _(u'In one hour')),
(3600 * 24 * 7, _(u'In one week')), (3600 * 24 * 7, _(u'In one week')),
@ -17,7 +16,7 @@ EXPIRE_DEFAULT = EXPIRE_CHOICES[2][0]
MAX_CONTENT_LENGTH = getattr(settings, 'DPASTE_MAX_CONTENT_LENGTH', 250*1024*1024) MAX_CONTENT_LENGTH = getattr(settings, 'DPASTE_MAX_CONTENT_LENGTH', 250*1024*1024)
MAX_SNIPPETS_PER_USER = getattr(settings, 'DPASTE_MAX_SNIPPETS_PER_USER', 15) MAX_SNIPPETS_PER_USER = getattr(settings, 'DPASTE_MAX_SNIPPETS_PER_USER', 15)
\
class SnippetForm(forms.ModelForm): class SnippetForm(forms.ModelForm):
content = forms.CharField( content = forms.CharField(
label=_('Content'), label=_('Content'),

View file

@ -107,6 +107,9 @@ class NakedHtmlFormatter(HtmlFormatter):
yield i, t yield i, t
def pygmentize(code_string, lexer_name=LEXER_DEFAULT): def pygmentize(code_string, lexer_name=LEXER_DEFAULT):
lexer = lexer_name and get_lexer_by_name(lexer_name) \ try:
or PythonLexer() lexer = lexer_name and get_lexer_by_name(lexer_name) \
or PythonLexer()
except Exception as e:
lexer = PythonLexer()
return highlight(code_string, lexer, NakedHtmlFormatter()) return highlight(code_string, lexer, NakedHtmlFormatter())

View file

@ -7,6 +7,11 @@ body {
padding: 10px 0 40px 0; padding: 10px 0 40px 0;
} }
tt strong {
background-color: #ffe699;
outline: 3px solid #ffe699;
}
/* Custom container */ /* Custom container */
.container-fluid { .container-fluid {
margin: 0 auto; margin: 0 auto;

View file

@ -47,6 +47,33 @@
{% endfor %} {% endfor %}
</table> </table>
<h4>Snippets in the database</h4>
<script src="https://www.stathat.com/javascripts/embed.js"></script>
<script>StatHatEmbed.render({s1: '3ba1', w: 760, h: 235, tf: 'month'});</script>
<div class="clearfix"></div>
<hr class="clearfix">
<h3>Delete a snippet</h3>
<p>
If you created a snippet with the API you can't delete it on the webpage
since it's not in your history. You can delete a snippet here. Actually
you can delete any snippet of anybody, as long as you know the short code.
</p>
<p>
If you deleted a snippet because auf legal issues, please let me know
that, I want to keep track of such things and try to avoid in future.
</p>
<p>
Type the 4 letter code of your snippet in the field and submit.
Like this yellow one here: <tt>http://dpaste.de/<strong>SiZrT</strong></tt>
</p>
<form method="POST" action="{% url "snippet_delete" %}">
<input name="snippet_id"> <input type="Submit" value="Submit"/>
</form>
<div class="clearfix"></div> <div class="clearfix"></div>
<hr class="clearfix"> <hr class="clearfix">

View file

@ -4,8 +4,9 @@ urlpatterns = patterns('dpaste.views',
url(r'^$', 'snippet_new', name='snippet_new'), url(r'^$', 'snippet_new', name='snippet_new'),
url(r'^diff/$', 'snippet_diff', name='snippet_diff'), url(r'^diff/$', 'snippet_diff', name='snippet_diff'),
url(r'^history/$', 'snippet_history', name='snippet_history'), url(r'^history/$', 'snippet_history', name='snippet_history'),
url(r'^delete/$', 'snippet_delete', name='snippet_delete'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/?$', 'snippet_details', name='snippet_details'), url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/?$', 'snippet_details', name='snippet_details'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/delete/$', 'snippet_delete', name='snippet_delete'), url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/delete/$', 'snippet_delete', name='snippet_delete'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/gist/$', 'snippet_gist', name='snippet_gist'), url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/gist/$', 'snippet_gist', name='snippet_gist'),
url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/raw/$', 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'), url(r'^(?P<snippet_id>[a-zA-Z0-9]+)/raw/?$', 'snippet_details', {'template_name': 'dpaste/snippet_details_raw.html', 'is_raw': True}, name='snippet_details_raw'),
) )

View file

@ -8,7 +8,7 @@ from django.template.context import RequestContext
from django.http import (Http404, HttpResponseRedirect, HttpResponseBadRequest, from django.http import (Http404, HttpResponseRedirect, HttpResponseBadRequest,
HttpResponse, HttpResponseForbidden) HttpResponse, HttpResponseForbidden)
from django.conf import settings from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils import simplejson from django.utils import simplejson
@ -57,6 +57,10 @@ def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.h
""" """
try: try:
snippet = Snippet.objects.get(secret_id=snippet_id) snippet = Snippet.objects.get(secret_id=snippet_id)
except MultipleObjectsReturned:
raise Http404('Multiple snippets exist for this slug. This should never '
'happen but its likely that you are a spam bot, so I dont '
'care.')
except ObjectDoesNotExist: except ObjectDoesNotExist:
raise Http404('This snippet does not exist anymore. Its likely that its ' raise Http404('This snippet does not exist anymore. Its likely that its '
'lifetime is expired.') 'lifetime is expired.')
@ -80,8 +84,8 @@ def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.h
template_context = { template_context = {
'snippet_form': snippet_form, 'snippet_form': snippet_form,
'lexer_list': LEXER_LIST,
'snippet': snippet, 'snippet': snippet,
'lexers': LEXER_LIST,
'lines': range(snippet.get_linecount()), 'lines': range(snippet.get_linecount()),
'tree': tree, 'tree': tree,
'wordwrap': snippet.lexer in LEXER_WORDWRAP and 'True' or 'False', 'wordwrap': snippet.lexer in LEXER_WORDWRAP and 'True' or 'False',
@ -100,16 +104,19 @@ def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.h
return response return response
def snippet_delete(request, snippet_id): def snippet_delete(request, snippet_id=None):
""" """
Delete a snippet. This is allowed by anybody as long as he knows the Delete a snippet. This is allowed by anybody as long as he knows the
snippet id. I got too many manual requests to do this, mostly for legal snippet id. I got too many manual requests to do this, mostly for legal
reasons and the chance to abuse this is not given anyway, since snippets reasons and the chance to abuse this is not given anyway, since snippets
always expire. always expire.
""" """
snippet_id = snippet_id or request.POST.get('snippet_id')
if not snippet_id:
raise Http404('No snippet id given')
snippet = get_object_or_404(Snippet, secret_id=snippet_id) snippet = get_object_or_404(Snippet, secret_id=snippet_id)
snippet.delete() snippet.delete()
return HttpResponseRedirect(reverse('snippet_new')) return HttpResponseRedirect(reverse('snippet_new') + '?delete=1')
def snippet_history(request, template_name='dpaste/snippet_list.html'): def snippet_history(request, template_name='dpaste/snippet_list.html'):

View file

@ -25,7 +25,7 @@ server {
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
server { server {
listen 443; listen 443;
server_name dpaste.de; server_name dpaste.de www.dpaste.de;
ssl on; ssl on;
ssl_certificate /srv/dpaste.de/var/ssl/dpaste_de_unified.crt; ssl_certificate /srv/dpaste.de/var/ssl/dpaste_de_unified.crt;
@ -33,7 +33,7 @@ server {
# Rewrite www to non-www # Rewrite www to non-www
if ($host ~ /^www\./) { if ($host = www.dpaste.de) {
rewrite ^/(.*)$ https://dpaste.de/$1 permanent; rewrite ^/(.*)$ https://dpaste.de/$1 permanent;
} }
@ -44,7 +44,7 @@ server {
server { server {
listen 443; listen 443;
server_name dpaste.org; server_name dpaste.org www.dpaste.org;
ssl on; ssl on;
ssl_certificate /srv/dpaste.de/var/ssl/dpaste_org_unified.crt; ssl_certificate /srv/dpaste.de/var/ssl/dpaste_org_unified.crt;
@ -53,7 +53,7 @@ server {
add_header Strict-Transport-Security max-age=25200; add_header Strict-Transport-Security max-age=25200;
# Rewrite www to non-www # Rewrite www to non-www
if ($host ~ /^www\./) { if ($host = www.dpaste.org) {
rewrite ^/(.*)$ https://dpaste.org/$1 permanent; rewrite ^/(.*)$ https://dpaste.org/$1 permanent;
} }