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.

This commit is contained in:
Martin Mahner 2013-03-22 19:33:11 +01:00
parent cad4589b0a
commit 368c8101ce
3 changed files with 52 additions and 21 deletions

View file

@ -1,10 +1,13 @@
{% extends "dpaste/base.html" %} {% extends "dpaste/base.html" %}
{% load i18n %}
{% block title %}About dpaste.de{% endblock %} {% block title %}About dpaste.de{% endblock %}
{% block headline %}About dpaste.de{% endblock %} {% block headline %}About dpaste.de{% endblock %}
{% block dpaste_nav_about %}active{% endblock %} {% block dpaste_nav_about %}active{% endblock %}
{% block page %} {% block page %}
<h3>API</h3> <h3>API</h3>
{# Just put the script in dpaste and copy the source node #} {# Just put the script in dpaste and copy the source node #}
@ -16,8 +19,9 @@
<p>Or you could use <code>curl</code>: <p>Or you could use <code>curl</code>:
<code>alias dpaste="curl -F 'content=&lt;-' http://dpaste.de/api/"</code></p> <code>alias dpaste="curl -F 'content=&lt;-' http://dpaste.de/api/"</code></p>
<hr>
<div class="row-fluid">
<div class="span5">
<h3>Applications using the API:</h3> <h3>Applications using the API:</h3>
<ul> <ul>
@ -25,10 +29,20 @@
<li><a href="https://github.com/bartTC/SubDpaste">a dpaste Sublime 2 plugin</a></li> <li><a href="https://github.com/bartTC/SubDpaste">a dpaste Sublime 2 plugin</a></li>
<li><a href="http://marmalade-repo.org/packages/dpaste_de">Marmalade</a>, a Emacs plugin</li> <li><a href="http://marmalade-repo.org/packages/dpaste_de">Marmalade</a>, a Emacs plugin</li>
</ul> </ul>
</div>
<div class="span4">
<p>{% blocktrans %}There are {{ total }} snippets in the database. The most popular languages are:{% endblocktrans %}</p>
<table class="table">
{% for s in stats %}
<tr>
<th>{{ s.lexer|upper }}</th>
<td>{{ s.count }}</th>
</tr>
{% endfor %}
</table>
</div>
<div class="span3">
<hr/>
<h3>Imprint</h3> <h3>Imprint</h3>
<p><strong>Address:</strong></p> <p><strong>Address:</strong></p>
@ -41,5 +55,7 @@
<p><strong>Jabber/E-Mail:</strong></p> <p><strong>Jabber/E-Mail:</strong></p>
<p><a href="mailto:martin@mahner.org">martin@mahner.org</a></p> <p><a href="mailto:martin@mahner.org">martin@mahner.org</a></p>
</div>
</div>
{% endblock %} {% endblock %}

View file

@ -3,7 +3,7 @@ from django.views.generic import TemplateView
urlpatterns = patterns( 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_api')),
url(r'^', include('dpaste.urls.dpaste')), url(r'^', include('dpaste.urls.dpaste')),
) )

View file

@ -7,6 +7,7 @@ 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
from django.db.models import Count
from django.views.defaults import page_not_found as django_page_not_found, \ from django.views.defaults import page_not_found as django_page_not_found, \
server_error as django_server_error server_error as django_server_error
@ -17,6 +18,19 @@ from dpaste.highlight import guess_code_lexer, \
import difflib 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'): def snippet_new(request, template_name='dpaste/snippet_new.html'):
if request.method == "POST": if request.method == "POST":
@ -169,6 +183,7 @@ def guess_lexer(request):
return HttpResponse(response) return HttpResponse(response)
def page_not_found(request, template_name='dpaste/404.html'): def page_not_found(request, template_name='dpaste/404.html'):
return django_page_not_found(request, template_name) return django_page_not_found(request, template_name)