Badge deletion
This commit is contained in:
Родитель
25d4e63f68
Коммит
4f6d036ccb
|
@ -0,0 +1,44 @@
|
|||
{% extends "badger/base.html" %}
|
||||
|
||||
{% block pageid %}badge_delete{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<section class="row-fluid">
|
||||
|
||||
<section class="span4">
|
||||
<header class="page-header">
|
||||
<h2>{{ _("Delete badge") }}</h2>
|
||||
</header>
|
||||
|
||||
<form id="nominate_badge" method="POST" action="" enctype="multipart/form-data">
|
||||
{{ csrf() }}
|
||||
{% if awards_count %}
|
||||
<p>{% trans badge_url=badge.get_absolute_url(), awards_count=awards_count %}
|
||||
<span class="label label-warning">Note:</span>
|
||||
Deleting this badge will also delete
|
||||
<a href="{{ badge_url }}"><span class="awards_count">{{awards_count}}</span> award(s)</a>
|
||||
{% endtrans %}</p>
|
||||
{% else %}
|
||||
<p>{% trans %}
|
||||
<span class="label label-success">Note:</span>
|
||||
No one has been awarded this badge, yet.
|
||||
{% endtrans %}</p>
|
||||
{% endif %}
|
||||
<p>{{ _("Are you sure?") }}</p>
|
||||
<ul>
|
||||
<li><input type="submit" class="btn btn-large btn-danger submit" value="{{ _("Delete badge") }}"></li>
|
||||
</ul>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="span8" id="detail">
|
||||
<header class="page-header">
|
||||
<h2>{{ _("Badge: {badge_title}") | f(badge_title=badge.title) }}</h2>
|
||||
</header>
|
||||
{% include "badger/includes/badge_full.html" %}
|
||||
</section>
|
||||
|
||||
</section>
|
||||
|
||||
{% endblock %}
|
|
@ -130,6 +130,40 @@ class BadgerViewsTest(BadgerTestCase):
|
|||
eq_(badge_title, badge.title)
|
||||
eq_(badge_desc, badge.description)
|
||||
|
||||
def test_delete(self):
|
||||
"""Can delete badge"""
|
||||
user = self._get_user()
|
||||
badge = Badge(creator=user, title="Test III",
|
||||
description="Another test")
|
||||
badge.save()
|
||||
slug = badge.slug
|
||||
|
||||
badge.award_to(user)
|
||||
|
||||
self.client.login(username="tester", password="trustno1")
|
||||
|
||||
r = self.client.get(reverse('badger.views.detail',
|
||||
args=(badge.slug,)), follow=True)
|
||||
doc = pq(r.content)
|
||||
|
||||
eq_('badge_detail', doc.find('body').attr('id'))
|
||||
delete_url = doc.find('a.delete_badge').attr('href')
|
||||
ok_(delete_url is not None)
|
||||
|
||||
r = self.client.get(delete_url)
|
||||
doc = pq(r.content)
|
||||
eq_('badge_delete', doc.find('body').attr('id'))
|
||||
eq_("1", doc.find('.awards_count').text())
|
||||
|
||||
r = self.client.post(delete_url, {}, follow=True)
|
||||
doc = pq(r.content)
|
||||
|
||||
try:
|
||||
badge = Badge.objects.get(slug=slug)
|
||||
ok_(False)
|
||||
except Badge.DoesNotExist:
|
||||
ok_(True)
|
||||
|
||||
def _get_user(self, username="tester", email="tester@example.com",
|
||||
password="trustno1"):
|
||||
(user, created) = User.objects.get_or_create(username=username,
|
||||
|
|
|
@ -14,6 +14,8 @@ urlpatterns = patterns('badger_multiplayer.views',
|
|||
name='badger_multiplayer.nominate_for'),
|
||||
url(r'^badge/(?P<slug>[^/]+)/edit$', 'edit',
|
||||
name='badger_multiplayer.badge_edit'),
|
||||
url(r'^badge/(?P<slug>[^/]+)/delete$', 'delete',
|
||||
name='badger_multiplayer.badge_delete'),
|
||||
url(r'^badge/(?P<slug>[^/]+)/nominations/(?P<id>[^/]+)/?$', 'nomination_detail',
|
||||
name='badger.nomination_detail'),
|
||||
url(r'^users/(?P<username>[^/]+)/badges/?$', 'badges_by_user',
|
||||
|
|
|
@ -102,6 +102,26 @@ def edit(request, slug):
|
|||
), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@require_http_methods(['GET', 'POST'])
|
||||
@login_required
|
||||
def delete(request, slug):
|
||||
"""Delete a badge"""
|
||||
badge = get_object_or_404(Badge, slug=slug)
|
||||
if not badge.allows_delete_by(request.user):
|
||||
return HttpResponseForbidden()
|
||||
|
||||
awards_count = badge.award_set.count()
|
||||
|
||||
if request.method == "POST":
|
||||
messages.info(request, _('Badge "%s" deleted.') % badge.title)
|
||||
badge.delete()
|
||||
return HttpResponseRedirect(reverse('badger.views.badges_list'))
|
||||
|
||||
return render_to_response('badger_multiplayer/badge_delete.html', dict(
|
||||
badge=badge, awards_count=awards_count,
|
||||
), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@require_http_methods(['GET', 'POST'])
|
||||
@login_required
|
||||
def nomination_detail(request, slug, id, format="html"):
|
||||
|
|
Загрузка…
Ссылка в новой задаче