mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-12-19 00:09:21 +11:00
Allow to delete all snippets at once.
This commit is contained in:
parent
5cea272b15
commit
f1a0dbab49
2 changed files with 20 additions and 7 deletions
|
@ -8,13 +8,20 @@
|
|||
{% block dpaste_nav_history %}active{% endblock %}
|
||||
{% block page %}
|
||||
{% 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 }}">
|
||||
{% blocktrans with snippet.published|timesince as since %}{{ since }} ago{% endblocktrans %}
|
||||
</a>
|
||||
</h4>
|
||||
{% include "dpaste/snippet_pre.html" %}
|
||||
{% 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 %}
|
||||
|
||||
<hr/>
|
||||
<div>
|
||||
<p><a href="?delete-all">Delete all your snippets.</a></p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -116,7 +116,7 @@ def snippet_delete(request, snippet_id=None):
|
|||
raise Http404('No snippet id given')
|
||||
snippet = get_object_or_404(Snippet, secret_id=snippet_id)
|
||||
snippet.delete()
|
||||
return HttpResponseRedirect(reverse('snippet_new') + '?delete=1')
|
||||
return HttpResponseRedirect(reverse('snippet_new'))
|
||||
|
||||
|
||||
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
|
||||
session).
|
||||
"""
|
||||
try:
|
||||
snippet_list = get_list_or_404(Snippet, pk__in=request.session.get('snippet_list', None))
|
||||
except ValueError:
|
||||
snippet_list = None
|
||||
snippet_list = None
|
||||
snippet_id_list = request.session.get('snippet_list', None)
|
||||
if snippet_id_list:
|
||||
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 = {
|
||||
'snippets_max': getattr(settings, 'DPASTE_MAX_SNIPPETS_PER_USER', 10),
|
||||
|
|
Loading…
Reference in a new issue