unglue it admin users can now approve rightsholder claims!
parent
603fa59906
commit
a720089525
|
@ -43,9 +43,9 @@ class CeleryTask(models.Model):
|
|||
|
||||
class Claim(models.Model):
|
||||
STATUSES = ((
|
||||
u'Active', u'Claim has been registered and approved.'),
|
||||
(u'Pending', u'Claim is pending approval.'),
|
||||
(u'Released', u'Claim has been released.'),
|
||||
u'active', u'Claim has been registered and approved.'),
|
||||
(u'pending', u'Claim is pending approval.'),
|
||||
(u'release', u'Claim has been released.'),
|
||||
)
|
||||
rights_holder = models.ForeignKey("RightsHolder", related_name="claim", null=False )
|
||||
work = models.ForeignKey("Work", related_name="claim", null=False )
|
||||
|
|
|
@ -16,6 +16,14 @@ class RightsHolderForm(forms.ModelForm):
|
|||
class Meta:
|
||||
model = RightsHolder
|
||||
|
||||
def clean_rights_holder_name(self):
|
||||
rights_holder_name = self.data["rights_holder_name"]
|
||||
try:
|
||||
RightsHolder.objects.get(rights_holder_name__iexact=rights_holder_name)
|
||||
except User.DoesNotExist:
|
||||
return rights_holder_name
|
||||
raise forms.ValidationError(_("Another rights holder with that name already exists."))
|
||||
|
||||
class ProfileForm(forms.ModelForm):
|
||||
clear_facebook=forms.BooleanField(required=False)
|
||||
clear_twitter=forms.BooleanField(required=False)
|
||||
|
@ -43,7 +51,7 @@ class UserData(forms.Form):
|
|||
oldusername = self.data["oldusername"]
|
||||
if username != oldusername:
|
||||
try:
|
||||
User.objects.get(username=username)
|
||||
User.objects.get(username__iexact=username)
|
||||
except User.DoesNotExist:
|
||||
return username
|
||||
raise forms.ValidationError(_("Another user with that username already exists."))
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<form method="POST" action="#">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" name="submit" value="Create" id="submit">
|
||||
<input type="submit" name="create_rights_holder" value="Create" id="submit">
|
||||
</form>
|
||||
|
||||
<h2> Accepted Rights Holders </h2>
|
||||
|
@ -19,8 +19,28 @@
|
|||
owner: <a href="{% url supporter supporter_username=rights_holder.owner %}">{{ rights_holder.owner }}</a><br/>
|
||||
{% endfor %}
|
||||
|
||||
{% if pending %}
|
||||
<h2> Pending Claims </h2>
|
||||
{% for claim in pending %}
|
||||
<form method="POST" action="#">
|
||||
{{ pending_formset.management_form }}
|
||||
{% csrf_token %}
|
||||
{% for claim, claim_form in pending %}
|
||||
<h3>Title: <a href="{% url work work_id=claim.work.id %}">{{claim.work.title }}</a></h3>
|
||||
<p>Author: {{claim.work.author }}</p>
|
||||
<p>By: {{ claim.user.username }}
|
||||
<p>On Behalf of: {{ claim.rights_holder.rights_holder_name }}</p>
|
||||
<p>PSA #: {{ claim.rights_holder.id }}</p>
|
||||
<p>Date of Claim : {{ claim.created }}</p>
|
||||
<p>Status: {{ claim.status }}</p>
|
||||
<p> Change to:</p> {{ claim_form.as_p }}
|
||||
<input type="submit" name="set_claim_status" value="Set Claim Status" id="submit">
|
||||
{% endfor %}
|
||||
</form>
|
||||
{% endif %}
|
||||
active:{{ active_data.count }}
|
||||
{% if active_data.count %}
|
||||
<h2> Active Claims </h2>
|
||||
{% for claim in active_data %}
|
||||
<h3>Title: <a href="{% url work work_id=claim.work.id %}">{{claim.work.title }}</a></h3>
|
||||
<p>Author: {{claim.work.author }}</p>
|
||||
<p>By: {{ claim.user.username }}
|
||||
|
@ -29,5 +49,6 @@
|
|||
<p>Date of Claim : {{ claim.created }}</p>
|
||||
<p>Status: {{ claim.status }}</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
|
@ -7,6 +7,7 @@ from django.contrib.auth.models import User
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.forms import Select
|
||||
from django.forms.models import modelformset_factory
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.http import HttpResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
@ -114,7 +115,7 @@ def claim(request):
|
|||
data = request.POST
|
||||
form = ClaimForm(data=data)
|
||||
if form.is_valid():
|
||||
if not models.Claim.objects.filter(work=data['work'], rights_holder=data['rights_holder']).count():
|
||||
if not models.Claim.objects.filter(work=data['work'], rights_holder=data['rights_holder'], status='pending').count():
|
||||
form.save()
|
||||
return HttpResponseRedirect(reverse('work', kwargs={'work_id': data['work']}))
|
||||
else:
|
||||
|
@ -126,19 +127,32 @@ def claim(request):
|
|||
def rh_admin(request):
|
||||
if not request.user.profile.is_admin:
|
||||
return render(request, "admins_only.html")
|
||||
PendingFormSet = modelformset_factory(models.Claim, fields=['status'], extra=0)
|
||||
pending_data = models.Claim.objects.filter(status = 'pending')
|
||||
active_data = models.Claim.objects.filter(status = 'active')
|
||||
if request.method == 'POST':
|
||||
if 'create_rights_holder' in request.POST.keys():
|
||||
form = RightsHolderForm(data=request.POST)
|
||||
pending_formset = PendingFormSet (queryset=pending_data)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
if 'set_claim_status' in request.POST.keys():
|
||||
pending_formset = PendingFormSet (request.POST, request.FILES, queryset=pending_data)
|
||||
form = RightsHolderForm()
|
||||
if pending_formset.is_valid():
|
||||
pending_formset.save()
|
||||
else:
|
||||
form = RightsHolderForm()
|
||||
pending_formset = PendingFormSet(queryset=pending_data)
|
||||
rights_holders = models.RightsHolder.objects.all()
|
||||
pending = models.Claim.objects.filter(status = 'pending')
|
||||
|
||||
context = {
|
||||
'request': request,
|
||||
'rights_holders': rights_holders,
|
||||
'form': form,
|
||||
'pending': pending,
|
||||
'pending': zip(pending_data,pending_formset),
|
||||
'pending_formset': pending_formset,
|
||||
'active_data': active_data,
|
||||
}
|
||||
return render(request, "rights_holders.html", context)
|
||||
|
||||
|
|
Loading…
Reference in New Issue