claim form now creates a claim

pull/1/head
eric 2011-11-16 00:22:22 -05:00
parent 2009e6d785
commit 6a2e690f18
5 changed files with 26 additions and 3 deletions

View File

@ -6,6 +6,7 @@ from decimal import Decimal as D
from regluit.core.models import UserProfile, RightsHolder, Claim
class ClaimForm(forms.ModelForm):
i_agree=forms.BooleanField()
class Meta:
model = Claim
widgets = { 'user': forms.HiddenInput, 'work': forms.HiddenInput }

View File

@ -6,9 +6,13 @@
<form method="POST" action="#">
{% csrf_token %}
<h2> Rightsholder making claim </h2>
{{ rights_holder.rights_holder_name }}
<h2> Work being claimed </h2>
{{ work.title }}<br />
{{ work.author }}
<h2> Terms and Conditions </h2>
{{ form.as_p }}
[legal stuff goes here]
<input type="submit" name="submit" value="Confirm Claim" id="submit">
</form>

View File

@ -124,7 +124,9 @@
<h4> Claim this work:</h4>
<form method="GET" action="{% url claim %}">
{% csrf_token %}
{{ claimform.as_p }}
{{ claimform.user }}
{{ claimform.work }}
{{ claimform.rights_holder }}
<input type="submit" name="submit" value="Claim" id="submit">
</form>
{% endif %}

View File

@ -17,8 +17,7 @@ urlpatterns = patterns(
name="privacy"),
url(r"^rightsholders/$", TemplateView.as_view(template_name="rhtools.html"),
name="rightsholders"),
url(r"^rightsholders/claim/$", TemplateView.as_view(template_name="claim.html"),
name="claim"),
url(r"^rightsholders/claim/$", "claim", name="claim"),
url(r"^rh_admin/$", "rh_admin", name="rh_admin"),
url(r"^faq/$", TemplateView.as_view(template_name="faq.html"),
name="faq"),

View File

@ -53,6 +53,7 @@ def stub(request):
def work(request, work_id, action='display'):
work = get_object_or_404(models.Work, id=work_id)
campaign = work.last_campaign()
claimform = ClaimForm(data={'work':work_id, 'user':request.user.id })
if campaign:
q = Q(campaign=campaign) | Q(campaign__isnull=True)
@ -106,6 +107,22 @@ def pledge(request,work_id):
return render(request,'pledge.html',{'work':work,'campaign':campaign, 'premiums':premiums, 'form':form})
def claim(request):
if request.method == 'GET':
data = request.GET
else:
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():
form.save()
return HttpResponseRedirect(reverse('work', kwargs={'work_id': data['work']}))
else:
work = models.Work.objects.get(id=data['work'])
rights_holder = models.RightsHolder.objects.get(id=data['rights_holder'])
context = {'form': form, 'work': work, 'rights_holder':rights_holder }
return render(request, "claim.html", context)
def rh_admin(request):
if not is_admin(request.user):
return render(request, "admins_only.html")