From 354b46085f92f1088684173677c76ba2d2fecaf8 Mon Sep 17 00:00:00 2001 From: eric Date: Tue, 15 Nov 2011 18:20:29 -0500 Subject: [PATCH] Approved rights holders get a claim form on work pages; still need to make a view that does the actual claiming --- core/models.py | 2 ++ frontend/forms.py | 7 ++++++- frontend/templates/claim.html | 16 +++++++++++++++ frontend/templates/rights_holders.html | 2 +- frontend/templates/work.html | 19 ++++++++++++++++- frontend/urls.py | 2 ++ frontend/views.py | 28 ++++++++++++++++---------- 7 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 frontend/templates/claim.html diff --git a/core/models.py b/core/models.py index d0dc4e94..add852e7 100755 --- a/core/models.py +++ b/core/models.py @@ -50,6 +50,8 @@ class RightsHolder(models.Model): email = models.CharField(max_length=100, blank=True) rights_holder_name = models.CharField(max_length=100, blank=True) owner = models.ForeignKey(User, related_name="rights_holder", null=False ) + def __unicode__(self): + return self.rights_holder_name class Premium(models.Model): PREMIUM_TYPES = ((u'00', u'Default'),(u'CU', u'Custom')) diff --git a/frontend/forms.py b/frontend/forms.py index 652a8a5d..4bf9afc7 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -1,9 +1,14 @@ from django import forms from django.db import models -from regluit.core.models import UserProfile, RightsHolder from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ from decimal import Decimal as D +from regluit.core.models import UserProfile, RightsHolder, Claim + +class ClaimForm(forms.ModelForm): + class Meta: + model = Claim + widgets = { 'user': forms.HiddenInput, 'work': forms.HiddenInput } class RightsHolderForm(forms.ModelForm): class Meta: diff --git a/frontend/templates/claim.html b/frontend/templates/claim.html new file mode 100644 index 00000000..2da46cf7 --- /dev/null +++ b/frontend/templates/claim.html @@ -0,0 +1,16 @@ +{% extends "basedocumentation.html" %} + +{% block doccontent %} + +

Rights Holder Claim Form

+
+ {% csrf_token %} +

Rightsholder making claim

+

Work being claimed

+

Terms and Conditions

+ {{ form.as_p }} + +
+ + +{% endblock %} \ No newline at end of file diff --git a/frontend/templates/rights_holders.html b/frontend/templates/rights_holders.html index 7a7e3e7b..9ead80fd 100644 --- a/frontend/templates/rights_holders.html +++ b/frontend/templates/rights_holders.html @@ -10,7 +10,7 @@ {{ form.as_p }} - +

Accepted Rights Holders

{% for rights_holder in rights_holders %}

{{ rights_holder.rights_holder_name }}

diff --git a/frontend/templates/work.html b/frontend/templates/work.html index 190e76a9..128d6d97 100644 --- a/frontend/templates/work.html +++ b/frontend/templates/work.html @@ -110,7 +110,24 @@
- Want to Unglue infomation xxx +

Details for {{ work.title }}

+ {% if work.claim.count %} +

Rights Information

+

This work has been claimed by:

+
    + {% for claim in work.claim.all %} +
  • {{ claim.rights_holder.rights_holder_name }}
  • + {% endfor %} +
+ {% endif %} + {% if request.user.rights_holder %} +

Claim this work:

+
+ {% csrf_token %} + {{ claimform.as_p }} + +
+ {% endif %}
diff --git a/frontend/urls.py b/frontend/urls.py index 8ffdbb18..3059fcb8 100644 --- a/frontend/urls.py +++ b/frontend/urls.py @@ -17,6 +17,8 @@ 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"^rh_admin/$", "rh_admin", name="rh_admin"), url(r"^faq/$", TemplateView.as_view(template_name="faq.html"), name="faq"), diff --git a/frontend/views.py b/frontend/views.py index 8069b67a..770fe680 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -26,7 +26,7 @@ from regluit.core import models, bookloader from regluit.core import userlists from regluit.core.search import gluejar_search from regluit.core.goodreads import GoodreadsClient -from regluit.frontend.forms import UserData, ProfileForm, CampaignPledgeForm, GoodreadsShelfLoadingForm, RightsHolderForm +from regluit.frontend.forms import UserData, ProfileForm, CampaignPledgeForm, GoodreadsShelfLoadingForm, RightsHolderForm, ClaimForm from regluit.payment.manager import PaymentManager from regluit.payment.parameters import TARGET_TYPE_CAMPAIGN @@ -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) premiums = models.Premium.objects.filter(q) @@ -61,15 +62,20 @@ def work(request, work_id, action='display'): if action == 'setup_campaign': return render(request, 'setup_campaign.html', {'work': work}) else: - return render(request, 'work.html', {'work': work, 'premiums': premiums, 'ungluers': userlists.supporting_users(work, 5)}) + return render(request, 'work.html', { + 'work': work, + 'premiums': premiums, + 'ungluers': userlists.supporting_users(work, 5), + 'claimform': claimform, + }) def workstub(request, title, imagebase, image, author, googlebooks_id, action='display'): - premiums = None - title = urllib.unquote_plus(title) - imagebase = urllib.unquote_plus(imagebase) - image = urllib.unquote_plus(image) - author = urllib.unquote_plus(author) - return render(request, 'workstub.html', {'title': title, 'image': image, 'imagebase': imagebase, 'author': author, 'googlebooks_id': googlebooks_id, 'premiums': premiums, 'ungluers': userlists.other_users(supporter, 5)}) + premiums = None + title = urllib.unquote_plus(title) + imagebase = urllib.unquote_plus(imagebase) + image = urllib.unquote_plus(image) + author = urllib.unquote_plus(author) + return render(request, 'workstub.html', {'title': title, 'image': image, 'imagebase': imagebase, 'author': author, 'googlebooks_id': googlebooks_id, 'premiums': premiums, 'ungluers': userlists.other_users(supporter, 5)}) def subjects(request): order = request.GET.get('order') @@ -225,9 +231,9 @@ def search(request): # also urlencode some parameters we'll need to pass to workstub in the title links # needs to be done outside the if condition for result in results: - result['urlimage'] = urllib.quote_plus(sub('^https?:\/\/','', result['image']).encode("utf-8"), safe='') - result['urlauthor'] = urllib.quote_plus(result['author'].encode("utf-8"), safe='') - result['urltitle'] = urllib.quote_plus(result['title'].encode("utf-8"), safe='') + result['urlimage'] = urllib.quote_plus(sub('^https?:\/\/','', result['image']).encode("utf-8"), safe='') + result['urlauthor'] = urllib.quote_plus(result['author'].encode("utf-8"), safe='') + result['urltitle'] = urllib.quote_plus(result['title'].encode("utf-8"), safe='') context = { "q": q,