Allow to delete all snippets at once.

This commit is contained in:
Martin Mahner 2013-11-24 18:16:29 +01:00
parent 5cea272b15
commit f1a0dbab49
2 changed files with 20 additions and 7 deletions

View file

@ -8,13 +8,20 @@
{% block dpaste_nav_history %}active{% endblock %} {% block dpaste_nav_history %}active{% endblock %}
{% block page %} {% block page %}
{% for snippet in snippet_list %} {% for snippet in snippet_list %}
<h4 style="margin-top: 50px;"> <h4 style="{% if not forloop.first %}margin-top: 50px;{% endif %}">
<a title="{{ snippet.published|date:_("DATETIME_FORMAT") }}" href="{{ snippet.get_absolute_url }}"> <a title="{{ snippet.published|date:_("DATETIME_FORMAT") }}" href="{{ snippet.get_absolute_url }}">
{% blocktrans with snippet.published|timesince as since %}{{ since }} ago{% endblocktrans %} {% blocktrans with snippet.published|timesince as since %}{{ since }} ago{% endblocktrans %}
</a> </a>
</h4> </h4>
{% include "dpaste/snippet_pre.html" %} {% include "dpaste/snippet_pre.html" %}
{% empty %} {% empty %}
<p>{% trans "No snippets saved. Either all your snippets are expired or your cookie has changed." %}</p> <div>
<p>{% trans "No snippets saved. Either all your snippets are expired or your cookie has changed." %}</p>
</div>
{% endfor %} {% endfor %}
<hr/>
<div>
<p><a href="?delete-all">Delete all your snippets.</a></p>
</div>
{% endblock %} {% endblock %}

View file

@ -116,7 +116,7 @@ def snippet_delete(request, snippet_id=None):
raise Http404('No snippet id given') 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') + '?delete=1') return HttpResponseRedirect(reverse('snippet_new'))
def snippet_history(request, template_name='dpaste/snippet_list.html'): def snippet_history(request, template_name='dpaste/snippet_list.html'):
@ -124,10 +124,16 @@ def snippet_history(request, template_name='dpaste/snippet_list.html'):
Display the last `n` snippets created by this user (and saved in his Display the last `n` snippets created by this user (and saved in his
session). session).
""" """
try: snippet_list = None
snippet_list = get_list_or_404(Snippet, pk__in=request.session.get('snippet_list', None)) snippet_id_list = request.session.get('snippet_list', None)
except ValueError: if snippet_id_list:
snippet_list = None snippet_list = Snippet.objects.filter(pk__in=snippet_id_list)
if 'delete-all' in request.GET:
if snippet_list:
for s in snippet_list:
s.delete()
return HttpResponseRedirect(reverse('snippet_history'))
template_context = { template_context = {
'snippets_max': getattr(settings, 'DPASTE_MAX_SNIPPETS_PER_USER', 10), 'snippets_max': getattr(settings, 'DPASTE_MAX_SNIPPETS_PER_USER', 10),