This commit is contained in:
Les Orchard 2012-12-23 15:45:16 -05:00
Родитель 32b3fe0b8c
Коммит b085b870c9
4 изменённых файлов: 74 добавлений и 0 удалений

Просмотреть файл

@ -676,6 +676,17 @@ class Award(models.Model):
# TODO: Need some logic here, someday. # TODO: Need some logic here, someday.
return True return True
def allows_delete_by(self, user):
if user.is_anonymous():
return False
if user == self.user:
return True
if user == self.creator:
return True
if user.has_perm('badger.change_award'):
return True
return False
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
# Signals and some bits of logic only happen on a new award. # Signals and some bits of logic only happen on a new award.

Просмотреть файл

@ -0,0 +1,40 @@
{% extends "badger/base.html" %}
{% set user = award.user %}
{% set award_url = request.build_absolute_uri(url('badger.views.award_detail', award.badge.slug, award.id)) %}
{% if award.image %}
{% set image_url = award.image.url %}
{% elif badge.image %}
{% set image_url = badge.image.url %}
{% else %}
{# TODO: Put the URL for default badge image in settings #}
{% set image_url = "/media/img/default-badge.png" %}
{% endif %}
{% block pageid %}award_delete{% endblock %}
{% block content %}
<header class="page-header">
<h2>{{ _("Delete Award") }}</h2>
</header>
<section class="row-fluid">
<section class="badge span4">
{% include "badger/includes/badge_full.html" %}
</section>
<section class="award span8">
<form id="delete_award" method="POST" action="" enctype="multipart/form-data">
{{ csrf() }}
<p><strong>{{ _("Delete this award, are you sure?") }}</strong></p>
<ul>
<li><input type="submit" class="btn btn-large btn-danger submit" value="{{ _("Yes, delete award") }}"></li>
</ul>
</form>
{% include "badger/includes/award_full.html" %}
</section>
</section>
{% endblock %}

Просмотреть файл

@ -24,6 +24,8 @@ urlpatterns = patterns('badger.views',
name='badger.award_detail_json'), name='badger.award_detail_json'),
url(r'^badge/(?P<slug>[^/]+)/awards/(?P<id>[^/]+)/?$', 'award_detail', url(r'^badge/(?P<slug>[^/]+)/awards/(?P<id>[^/]+)/?$', 'award_detail',
name='badger.award_detail'), name='badger.award_detail'),
url(r'^badge/(?P<slug>[^/]+)/awards/(?P<id>[^/]+)/delete$', 'award_delete',
name='badger.award_delete'),
url(r'^badge/(?P<slug>[^/]+)/claims/(?P<claim_group>.+)\.pdf$', 'claims_list', url(r'^badge/(?P<slug>[^/]+)/claims/(?P<claim_group>.+)\.pdf$', 'claims_list',
kwargs=dict(format='pdf'), kwargs=dict(format='pdf'),
name='badger.claims_list_pdf'), name='badger.claims_list_pdf'),

Просмотреть файл

@ -284,6 +284,27 @@ def award_detail(request, slug, id, format="html"):
), context_instance=RequestContext(request)) ), context_instance=RequestContext(request))
@require_http_methods(['GET', 'POST'])
@login_required
def award_delete(request, slug, id):
"""Delete an award"""
badge = get_object_or_404(Badge, slug=slug)
award = get_object_or_404(Award, badge=badge, pk=id)
if not award.allows_delete_by(request.user):
return HttpResponseForbidden('Award delete forbidden')
if request.method == "POST":
messages.info(request, _('Award for badge "%s" deleted.') %
badge.title)
award.delete()
url = reverse('badger.views.detail', kwargs=dict(slug=slug))
return HttpResponseRedirect(url)
return render_to_response('badger/award_delete.html', dict(
badge=badge, award=award
), context_instance=RequestContext(request))
@login_required @login_required
def _do_claim(request, deferred_award): def _do_claim(request, deferred_award):
"""Perform claim of a deferred award""" """Perform claim of a deferred award"""