From ed29279b0abae4945b84cb3a032e7c3ca6fc7528 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Thu, 21 Mar 2013 18:26:35 +0000 Subject: [PATCH 1/9] Added dpaste.org to ALLOWED_HOSTS --- dpaste/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpaste/settings.py b/dpaste/settings.py index 52b5d7b..7a4854f 100644 --- a/dpaste/settings.py +++ b/dpaste/settings.py @@ -19,8 +19,8 @@ SECRET_KEY = '' ALLOWED_HOSTS = ( 'dpaste.de', 'www.dpaste.de', - 'localhost', - '127.0.0.1', + 'dpaste.org', + 'www.dpaste.org', ) #============================================================================== From c922a30dcaf9eaac156ba16cb91b970f2b0babdd Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Thu, 21 Mar 2013 19:14:27 +0100 Subject: [PATCH 2/9] Removed Raven/Sentry --- dpaste/settings.py | 3 --- requirements.txt | 1 - 2 files changed, 4 deletions(-) diff --git a/dpaste/settings.py b/dpaste/settings.py index 7a4854f..1671a4f 100644 --- a/dpaste/settings.py +++ b/dpaste/settings.py @@ -122,9 +122,6 @@ INSTALLED_APPS = ( # stored in the user session. MAX_SNIPPETS_PER_USER = 25 -SENTRY_DSN = 'http://0afbf6df0a9749f9985059ed6c527b19:717d9800ba854149a7e7f6a501b2caa0@ohnoez.mahner.org/2' - - LOGGING = { 'version': 1, 'disable_existing_loggers': False, diff --git a/requirements.txt b/requirements.txt index 36b3c5b..9fd6ef0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,6 @@ django==1.5 django-mptt==0.4.2 django-piston==0.2.2 pygments==1.6 -raven mysql-python==1.2.2 south==0.7.6 gunicorn==0.17.2 \ No newline at end of file From 9b7a252bc9ac7bbb426cbf46e3211c559d1c2823 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Thu, 21 Mar 2013 19:16:20 +0100 Subject: [PATCH 3/9] Updated mysqldb --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9fd6ef0..e79fdc7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,6 @@ django==1.5 django-mptt==0.4.2 django-piston==0.2.2 pygments==1.6 -mysql-python==1.2.2 +mysql-python==1.2.4 south==0.7.6 gunicorn==0.17.2 \ No newline at end of file From ecf7653bf984911592e1fe0513ef2b6a2399b7a2 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Thu, 21 Mar 2013 19:25:28 +0100 Subject: [PATCH 4/9] Added a smtp comment --- dpaste/smtp.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dpaste/smtp.py b/dpaste/smtp.py index f773df6..2dbfcea 100644 --- a/dpaste/smtp.py +++ b/dpaste/smtp.py @@ -7,6 +7,10 @@ from subprocess import Popen, PIPE class EmailBackend(BaseEmailBackend): + """ + EmailBackend that uses a local 'sendmail' binary instead of a local + SMTP daemon. + """ def __init__(self, fail_silently=False, **kwargs): super(EmailBackend, self).__init__(fail_silently=fail_silently) self._lock = threading.RLock() From 22bce7a0080c18295e8199612b1eb79f8ab551b0 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Thu, 21 Mar 2013 19:40:48 +0100 Subject: [PATCH 5/9] Removed Django admin. It was never useful anyway. --- dpaste/admin.py | 10 ---------- dpaste/settings.py | 1 - dpaste/urls/__init__.py | 4 ---- 3 files changed, 15 deletions(-) delete mode 100644 dpaste/admin.py diff --git a/dpaste/admin.py b/dpaste/admin.py deleted file mode 100644 index 8057fc0..0000000 --- a/dpaste/admin.py +++ /dev/null @@ -1,10 +0,0 @@ -from django.contrib import admin -from dpaste.models import Snippet - -class SnippetAdmin(admin.ModelAdmin): - list_display = ('published', 'expires', 'lexer', 'get_absolute_url') - date_hierarchy = 'published' - list_filter = ('published',) - raw_id_fields = ('parent',) - -admin.site.register(Snippet, SnippetAdmin) diff --git a/dpaste/settings.py b/dpaste/settings.py index 1671a4f..5b02127 100644 --- a/dpaste/settings.py +++ b/dpaste/settings.py @@ -107,7 +107,6 @@ INSTALLED_APPS = ( 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.staticfiles', - 'django.contrib.admin', 'mptt', 'south', 'gunicorn', diff --git a/dpaste/urls/__init__.py b/dpaste/urls/__init__.py index 25b8fd5..c710b0f 100644 --- a/dpaste/urls/__init__.py +++ b/dpaste/urls/__init__.py @@ -1,13 +1,9 @@ from django.conf.urls.defaults import url, patterns, include -from django.contrib import admin from django.views.generic import TemplateView -admin.autodiscover() - urlpatterns = patterns( '', url(r'^about/$', TemplateView.as_view(template_name='dpaste/about.html'), name='about'), - url(r'^admin/', include(admin.site.urls)), url(r'^', include('dpaste.urls.dpaste_api')), url(r'^', include('dpaste.urls.dpaste')), ) From 4e4463faf76bf7bebf7ef1c1795750259b6b62da Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Thu, 21 Mar 2013 19:41:21 +0100 Subject: [PATCH 6/9] Removed auth, sites and content types. Without the admin we no longer need em. --- dpaste/settings.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/dpaste/settings.py b/dpaste/settings.py index 5b02127..4f1b189 100644 --- a/dpaste/settings.py +++ b/dpaste/settings.py @@ -89,23 +89,15 @@ MIDDLEWARE_CLASSES = ( 'dpaste.disable.DisableCSRF', 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', + #'django.contrib.messages.middleware.MessageMiddleware', ) TEMPLATE_CONTEXT_PROCESSORS += ( 'django.core.context_processors.request', ) -TEMPLATE_DIRS = ( - os.path.join(PROJECT_DIR, PROJECT_MODULE_NAME, 'templates'), -) - INSTALLED_APPS = ( - 'django.contrib.auth', - 'django.contrib.contenttypes', 'django.contrib.sessions', - 'django.contrib.sites', 'django.contrib.staticfiles', 'mptt', 'south', From 9321195ff4dcc9653e3113822c0ae3c4c21b6154 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Fri, 22 Mar 2013 19:33:11 +0100 Subject: [PATCH 7/9] Now that there is no admin anymore I need a quick way to check the total snippet count, to see if something goes wrong or I'm DOSed. --- dpaste/templates/dpaste/about.html | 56 +++++++++++++++++++----------- dpaste/urls/__init__.py | 2 +- dpaste/views.py | 15 ++++++++ 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/dpaste/templates/dpaste/about.html b/dpaste/templates/dpaste/about.html index 288e81a..8c9744f 100644 --- a/dpaste/templates/dpaste/about.html +++ b/dpaste/templates/dpaste/about.html @@ -1,10 +1,13 @@ {% extends "dpaste/base.html" %} +{% load i18n %} + {% block title %}About dpaste.de{% endblock %} {% block headline %}About dpaste.de{% endblock %} {% block dpaste_nav_about %}active{% endblock %} {% block page %} +

API

{# Just put the script in dpaste and copy the source node #} @@ -16,30 +19,43 @@

Or you could use curl: alias dpaste="curl -F 'content=<-' http://dpaste.de/api/"

-
-

Applications using the API:

+
+
+

Applications using the API:

- + +
+
+

{% blocktrans %}There are {{ total }} snippets in the database. The most popular languages are:{% endblocktrans %}

+ + {% for s in stats %} + + + + {% endfor %} +
{{ s.lexer|upper }}{{ s.count }} +
+
+
+

Imprint

-
+

Address:

+

+ Martin Mahner
+ Lauterbacher Str. 4
+ DE-18581 Putbus
+ Germany +

-

Imprint

- -

Address:

-

- Martin Mahner
- Lauterbacher Str. 4
- DE-18581 Putbus
- Germany -

- -

Jabber/E-Mail:

-

martin@mahner.org

+

Jabber/E-Mail:

+

martin@mahner.org

+
+
{% endblock %} diff --git a/dpaste/urls/__init__.py b/dpaste/urls/__init__.py index c710b0f..fe696fb 100644 --- a/dpaste/urls/__init__.py +++ b/dpaste/urls/__init__.py @@ -3,7 +3,7 @@ from django.views.generic import TemplateView urlpatterns = patterns( '', - url(r'^about/$', TemplateView.as_view(template_name='dpaste/about.html'), name='about'), + url(r'^about/$', 'dpaste.views.about', name='about'), url(r'^', include('dpaste.urls.dpaste_api')), url(r'^', include('dpaste.urls.dpaste')), ) diff --git a/dpaste/views.py b/dpaste/views.py index 0520de2..2611355 100644 --- a/dpaste/views.py +++ b/dpaste/views.py @@ -7,6 +7,7 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse from django.utils import simplejson +from django.db.models import Count from django.views.defaults import page_not_found as django_page_not_found, \ server_error as django_server_error @@ -17,6 +18,19 @@ from dpaste.highlight import guess_code_lexer, \ import difflib +def about(request, template_name='dpaste/about.html'): + template_context = { + 'total': Snippet.objects.count(), + 'stats': Snippet.objects.values('lexer').annotate( + count=Count('lexer')).order_by('-count')[:5], + } + + return render_to_response( + template_name, + template_context, + RequestContext(request) + ) + def snippet_new(request, template_name='dpaste/snippet_new.html'): if request.method == "POST": @@ -169,6 +183,7 @@ def guess_lexer(request): return HttpResponse(response) + def page_not_found(request, template_name='dpaste/404.html'): return django_page_not_found(request, template_name) From e9770293bbdd14ea014a41a7b59044c1f79719f5 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Fri, 22 Mar 2013 19:40:31 +0100 Subject: [PATCH 8/9] Autofocus the textfield for a new snippet. --- dpaste/forms.py | 5 +++++ dpaste/templates/dpaste/base.html | 2 ++ dpaste/templates/dpaste/snippet_form.html | 4 ++-- dpaste/templates/dpaste/snippet_new.html | 4 +--- dpaste/views.py | 1 + 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dpaste/forms.py b/dpaste/forms.py index 426a13b..04f9704 100644 --- a/dpaste/forms.py +++ b/dpaste/forms.py @@ -19,6 +19,11 @@ EXPIRE_DEFAULT = 3600 * 24 * 30 class SnippetForm(forms.ModelForm): + content = forms.CharField( + label=_('Content'), + widget=forms.Textarea(attrs={'placeholder': _('Awesome code goes here...')}), + ) + lexer = forms.ChoiceField( label=_(u'Lexer'), initial=LEXER_DEFAULT, diff --git a/dpaste/templates/dpaste/base.html b/dpaste/templates/dpaste/base.html index 0d8037a..c85fd74 100644 --- a/dpaste/templates/dpaste/base.html +++ b/dpaste/templates/dpaste/base.html @@ -44,6 +44,8 @@ $(document).ready(function(){ } }); }); + + $('.autofocus input:text, .autofocus textarea').first().focus(); }); {% endblock %} diff --git a/dpaste/templates/dpaste/snippet_form.html b/dpaste/templates/dpaste/snippet_form.html index 4702367..0670f26 100644 --- a/dpaste/templates/dpaste/snippet_form.html +++ b/dpaste/templates/dpaste/snippet_form.html @@ -5,7 +5,7 @@ {{ snippet_form.non_field_errors }}
{{ snippet_form.title }}
-
+
{{ snippet_form.content }}
@@ -26,7 +26,7 @@
- {% if follow_button %} + {% if is_new %}