Merge branch 'master' into t4u_download

pull/1/head
Raymond Yee 2014-02-25 19:10:01 -08:00
commit ae531e0d7d
9 changed files with 74 additions and 55 deletions

View File

@ -146,8 +146,17 @@ class Claim(models.Model):
if campaign.status in ['ACTIVE','INITIALIZED', 'SUCCESSFUL']: if campaign.status in ['ACTIVE','INITIALIZED', 'SUCCESSFUL']:
return False return False
return True return True
def __unicode__(self): def __unicode__(self):
return self.work.title return self.work.title
@property
def campaign(self):
return self.work.last_campaign()
@property
def campaigns(self):
return self.work.campaigns.all()
def notify_claim(sender, created, instance, **kwargs): def notify_claim(sender, created, instance, **kwargs):
if 'example.org' in instance.user.email or hasattr(instance,'dont_notify'): if 'example.org' in instance.user.email or hasattr(instance,'dont_notify'):

View File

@ -23,10 +23,10 @@
{% block ce_content %} {% block ce_content %}
<h2>Kindle email change successful</h2> <h2>Kindle email change successful</h2>
<div id="content-main"> <div id="content-main">
<p>Hooray! We can now send unglued ebooks to you at {{ request.user.profile.kindle_email }}.</p> <p>Hooray! We can now send most unglued ebooks to you at {{ request.user.profile.kindle_email }}. Some ebooks are too big for us to send, though.</p>
{% if work %} {% if work %}
<p> <p>
We're emailing you the ebook you wanted, <i><a href="{% url work work.id %}">{{ work.title }}</a></i>... We're now emailing you the ebook you wanted, <i><a href="{% url work work.id %}">{{ work.title }}</a></i>...
</p> </p>
<span id="replace_me"><img src="{{ STATIC_URL }}images/loading.gif"></span> <span id="replace_me"><img src="{{ STATIC_URL }}images/loading.gif"></span>
{% else %} {% else %}

View File

@ -1,4 +1,4 @@
{% ifequal message 0 %}This ebook is too big to be sent by email. Please download the file and then sideload it to your device using the instructions under Ereaders or PC/Mac/Linux. {% ifequal message 0 %}It turns out that this ebook is too big for us to send by email. Using a computer, <a href="{{ebook_url}}">download the file</a>. Plug your Kindle into your computer using a USB cable. It will mount as a filesystem. Drag the downloaded {{ebook_format}} file into the documents folder on the Kindle, and then unmount the Kindle. (Kindle 1 owners: youll also need to unplug the USB cable to get your Kindle back into book-reading mode. Kindle 2 owners can leave the cable connected).
{% endifequal %} {% endifequal %}
{% ifequal message 1 %}Well, this is awkward. We can't seem to email that. Please download it using the instructions for your device, and we'll look into the error. {% ifequal message 1 %}Well, this is awkward. We can't seem to email that. Please download it using the instructions for your device, and we'll look into the error.
{% endifequal %} {% endifequal %}

View File

@ -14,10 +14,10 @@ Finally, think about how you're going to publicize your campaign: social media,
We're thrilled to be working with you. We're thrilled to be working with you.
{% endifequal %} {% endifequal %}
{% ifequal claim.status 'pending' %} {% ifequal claim.status 'pending' %}
{{ claim.rights_holder }}'s claim to {{ claim.work }} on Unglue.it has been entered. Our team will examine the claim and get back to you soon. {{ claim.rights_holder }}'s claim to {{ claim.work }} (https://{{ current_site.domain }}{% url work claim.work.id %}) on Unglue.it has been entered. Our team will examine the claim and get back to you soon.
{% endifequal %} {% endifequal %}
{% ifequal claim.status 'release' %} {% ifequal claim.status 'release' %}
{{ claim.rights_holder }}'s claim to {{ claim.work }} on Unglue.it has been released. email us (rights@gluejar.com) if you have any questions about this. {{ claim.rights_holder }}'s claim to {{ claim.work }} (https://{{ current_site.domain }}{% url work claim.work.id %}) on Unglue.it has been released. email us (rights@gluejar.com) if you have any questions about this.
{% endifequal %} {% endifequal %}
The Unglue.it team The Unglue.it team

View File

@ -27,9 +27,9 @@ Finally, think about how you're going to publicize your campaign: social media,
We're thrilled to be working with you. We're thrilled to be working with you.
{% endifequal %} {% endifequal %}
{% ifequal claim.status 'pending' %} {% ifequal claim.status 'pending' %}
The claim will be examined, and we'll email you. Contact us at support@gluejar.com if you need any help. The claim for <a href="{% url work claim.work.id %}">{{ claim.work }}</a> will be examined, and we'll email you. Contact us at support@gluejar.com if you need any help.
{% endifequal %} {% endifequal %}
{% ifequal claim.status 'release' %} {% ifequal claim.status 'release' %}
The claim has been released. Contact us at rights@gluejar.com if you have questions. The claim for <a href="{% url work claim.work.id %}">{{ claim.work }}</a> has been released. Contact us at rights@gluejar.com if you have questions.
{% endifequal %} {% endifequal %}
{% endblock %} {% endblock %}

View File

@ -104,11 +104,12 @@ Any questions not covered here? Please email us at <a href="mailto:rights@gluej
<br />PSA #: {{ claim.rights_holder.id }} <br />PSA #: {{ claim.rights_holder.id }}
<br />Date of Claim : {{ claim.created }} <br />Date of Claim : {{ claim.created }}
<br />Status of Claim: {{ claim.get_status_display }} <br />Status of Claim: {{ claim.get_status_display }}
{% if claim.can_open_new %} {% if claim.campaign_form %}
<h3>Open a blank campaign for this work</h3> <h3>Open a blank campaign for this work</h3>
<div class="work_campaigns clearfix" style="padding: 5px;">
<form method="POST" action="#"> <form method="POST" action="#">
{% csrf_token %} <p>{% csrf_token %}
<p>Name the Campaign: {{ claim.campaign_form.name }}{{ claim.campaign_form.name.errors }}</p> Name the Campaign: {{ claim.campaign_form.name }}{{ claim.campaign_form.name.errors }}</p>
{% if claim.rights_holder.can_sell %} {% if claim.rights_holder.can_sell %}
<p>Choose the Campaign Type: {{ claim.campaign_form.type }}{{ claim.campaign_form.type.errors }}</p> <p>Choose the Campaign Type: {{ claim.campaign_form.type }}{{ claim.campaign_form.type.errors }}</p>
<ol> <ol>
@ -119,18 +120,21 @@ Any questions not covered here? Please email us at <a href="mailto:rights@gluej
{% else %} {% else %}
<input type="hidden" id="type" name="type" value="1" /> <input type="hidden" id="type" name="type" value="1" />
{% endif %} {% endif %}
<div style="width:200px" >Choose your Campaign Manager(s): {{ claim.campaign_form.managers }}{{ claim.campaign_form.managers.errors }}</div> <p>Add a Campaign Manager(s) by their Unglue.it username: </p>
<div style="width:220px; padding-left:20px" >{{ claim.campaign_form.managers }}{{ claim.campaign_form.managers.errors }}
<br />
<input type="submit" name="submit" value="Open Campaign">
</div>
<p> <p>
{{ claim.campaign_form.work }}{{ claim.campaign_form.work.errors }} {{ claim.campaign_form.work }}{{ claim.campaign_form.work.errors }}
{{ claim.campaign_form.userid }}{{ claim.campaign_form.userid.errors }} {{ claim.campaign_form.userid }}{{ claim.campaign_form.userid.errors }}
</p> </p>
<input type="submit" name="submit" value="Open Campaign">
</form> </form>
{% else %}{%if claim.campaigns %} </div>
<h3>Campaigns for this work</h3> {% else %}{%if claim.campaign %}
<h3>Campaign for this work</h3>
{% for campaign in claim.campaigns %} {% with claim.campaign as campaign %}
<div class="work_campaigns clearfix"> <div class="work_campaigns clearfix">
{% if campaign.status = 'ACTIVE' or campaign.status = 'INITIALIZED' %} {% if campaign.status = 'ACTIVE' or campaign.status = 'INITIALIZED' %}
<div class="campaign_info"> <div class="campaign_info">
@ -138,8 +142,11 @@ Any questions not covered here? Please email us at <a href="mailto:rights@gluej
Created: {{ campaign.created }}<br /> Created: {{ campaign.created }}<br />
Manager(s): {% for user in campaign.managers.all %} <a href="{% url supporter user.username %}">{{ user.username }} </a> {% endfor %} Manager(s): {% for user in campaign.managers.all %} <a href="{% url supporter user.username %}">{{ user.username }} </a> {% endfor %}
<form method="POST" action="#">{% csrf_token %} <form method="POST" action="#">{% csrf_token %}
Add/Remove Managers: {{ campaign.edit_managers_form.managers }}{{ campaign.edit_managers_form.managers.errors }} <div style="width:220px; padding-left:20px" >
Add/Remove Managers:
{{ campaign.edit_managers_form.managers }}{{ campaign.edit_managers_form.managers.errors }}
<input type="submit" name="edit_managers_{{campaign.id}}" value="Save Managers"> <input type="submit" name="edit_managers_{{campaign.id}}" value="Save Managers">
</div>
</form> </form>
</div> </div>
{% if request.user in campaign.managers.all %} {% if request.user in campaign.managers.all %}
@ -162,7 +169,7 @@ Any questions not covered here? Please email us at <a href="mailto:rights@gluej
</div> </div>
{% endif %} {% endif %}
</div> </div>
{% endfor %} {% endwith %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if claim.work.first_ebook %} {% if claim.work.first_ebook %}

View File

@ -13,7 +13,14 @@
<li><a href="/admin/">Admin</a></li> <li><a href="/admin/">Admin</a></li>
<li><a href="{% url new_libraries %}">Libraries Needing Approval</a></li> <li><a href="{% url new_libraries %}">Libraries Needing Approval</a></li>
<li><a href="{% url press_submitterator %}">Press Coverage</a></li> <li><a href="{% url press_submitterator %}">Press Coverage</a></li>
{% if facet = 'top' %}
<li><a href="{% url accepted %}">Accepted Rights Holders</a></li>
<li><a href="{% url claims %}">Active Claims</a></li>
{% else %}
<li><a href="{% url rh_admin %}">Unglue.it Admin</a></li>
{% endif %}
</ul> </ul>
{% if facet = 'top' %}
<h2>Rights Holder Admin</h2> <h2>Rights Holder Admin</h2>
<h3> Create New Rights Holder </h3> <h3> Create New Rights Holder </h3>
@ -22,7 +29,8 @@
{{ form.as_p }} {{ form.as_p }}
<input type="submit" name="create_rights_holder" value="Create" id="submit"> <input type="submit" name="create_rights_holder" value="Create" id="submit">
</form> </form>
{% endif %}
{% if facet = 'accepted' %}
<h3> Accepted Rights Holders </h3> <h3> Accepted Rights Holders </h3>
<dl> <dl>
{% for rights_holder in rights_holders %} {% for rights_holder in rights_holders %}
@ -34,8 +42,9 @@
<p>No rights holders have been accepted yet</p> <p>No rights holders have been accepted yet</p>
{% endfor %} {% endfor %}
</dl> </dl>
{% endif %}
{% if pending %} {% if pending and facet = 'top' %}
<h3> Pending Claims </h3> <h3> Pending Claims </h3>
<form method="POST" action="#"> <form method="POST" action="#">
{{ pending_formset.management_form }} {{ pending_formset.management_form }}
@ -56,7 +65,7 @@
</form> </form>
{% endif %} {% endif %}
{% if active_data.count %} {% if active_data.count and facet = 'claims' %}
<h3> Active Claims: {{ active_data.count }} </h3> <h3> Active Claims: {{ active_data.count }} </h3>
<dl> <dl>
{% for claim in active_data %} {% for claim in active_data %}

View File

@ -36,7 +36,6 @@ from regluit.frontend.views import (
ByPubView, ByPubView,
kindle_config, kindle_config,
send_to_kindle, send_to_kindle,
send_to_kindle_graceful,
MARCUngluifyView, MARCUngluifyView,
MARCConfigView, MARCConfigView,
DownloadView, DownloadView,
@ -63,6 +62,8 @@ urlpatterns = patterns(
url(r"^rightsholders/edition/(?P<edition_id>\d*)/upload/$", "edition_uploads", name="edition_uploads"), url(r"^rightsholders/edition/(?P<edition_id>\d*)/upload/$", "edition_uploads", name="edition_uploads"),
url(r"^rightsholders/claim/$", "claim", name="claim"), url(r"^rightsholders/claim/$", "claim", name="claim"),
url(r"^rh_admin/$", "rh_admin", name="rh_admin"), url(r"^rh_admin/$", "rh_admin", name="rh_admin"),
url(r"^rh_admin/accepted/$", "rh_admin", {'facet': 'accepted'}, name="accepted"),
url(r"^rh_admin/claims/$", "rh_admin", {'facet': 'claims'}, name="claims"),
url(r"^campaign_admin/$", "campaign_admin", name="campaign_admin"), url(r"^campaign_admin/$", "campaign_admin", name="campaign_admin"),
url(r"^faq/$", FAQView.as_view(), {'location':'faq', 'sublocation':'all'}, name="faq"), url(r"^faq/$", FAQView.as_view(), {'location':'faq', 'sublocation':'all'}, name="faq"),
url(r"^faq/(?P<location>\w*)/$", FAQView.as_view(), {'sublocation':'all'}, name="faq_location"), url(r"^faq/(?P<location>\w*)/$", FAQView.as_view(), {'sublocation':'all'}, name="faq_location"),
@ -147,7 +148,6 @@ urlpatterns = patterns(
url(r"^accounts/edit/kindle_config/$", "kindle_config", name="kindle_config"), url(r"^accounts/edit/kindle_config/$", "kindle_config", name="kindle_config"),
url(r"^accounts/edit/kindle_config/(?P<work_id>\d+)/$", "kindle_config", name="kindle_config_download"), url(r"^accounts/edit/kindle_config/(?P<work_id>\d+)/$", "kindle_config", name="kindle_config_download"),
url(r"^send_to_kindle/(?P<work_id>\d+)/(?P<javascript>\d)/$", "send_to_kindle", name="send_to_kindle"), url(r"^send_to_kindle/(?P<work_id>\d+)/(?P<javascript>\d)/$", "send_to_kindle", name="send_to_kindle"),
url(r"^send_to_kindle/result/(?P<message>\d)/$", "send_to_kindle_graceful", name="send_to_kindle_graceful"),
url(r"^marc/$", "marc", name="marc"), url(r"^marc/$", "marc", name="marc"),
url(r"^marc/ungluify/$", staff_member_required(MARCUngluifyView.as_view()), name="MARCUngluify"), url(r"^marc/ungluify/$", staff_member_required(MARCUngluifyView.as_view()), name="MARCUngluify"),
url(r"^marc/concatenate/$", "marc_concatenate", name="marc_concatenate"), url(r"^marc/concatenate/$", "marc_concatenate", name="marc_concatenate"),

View File

@ -1631,19 +1631,6 @@ def rh_tools(request):
if not claims: if not claims:
return render(request, "rh_tools.html") return render(request, "rh_tools.html")
for claim in claims: for claim in claims:
if claim.status == 'active':
claim.campaigns = claim.work.campaigns.all()
else:
claim.campaigns = []
for campaign in claim.campaigns:
if campaign.status in ['ACTIVE','INITIALIZED']:
if request.method == 'POST' and request.POST.has_key('edit_managers_%s'% campaign.id) :
campaign.edit_managers_form=EditManagersForm( instance=campaign, data=request.POST, prefix=campaign.id)
if campaign.edit_managers_form.is_valid():
campaign.edit_managers_form.save()
campaign.edit_managers_form = EditManagersForm(instance=campaign, prefix=campaign.id)
else:
campaign.edit_managers_form=EditManagersForm(instance=campaign, prefix=campaign.id)
if claim.can_open_new: if claim.can_open_new:
if request.method == 'POST' and request.POST.has_key('cl_%s-work' % claim.id) and int(request.POST['cl_%s-work' % claim.id]) == claim.work.id : if request.method == 'POST' and request.POST.has_key('cl_%s-work' % claim.id) and int(request.POST['cl_%s-work' % claim.id]) == claim.work.id :
claim.campaign_form = OpenCampaignForm(data = request.POST, prefix = 'cl_'+str(claim.id),) claim.campaign_form = OpenCampaignForm(data = request.POST, prefix = 'cl_'+str(claim.id),)
@ -1659,12 +1646,22 @@ def rh_tools(request):
new_campaign.target = D(settings.UNGLUEIT_MINIMUM_TARGET) new_campaign.target = D(settings.UNGLUEIT_MINIMUM_TARGET)
new_campaign.save() new_campaign.save()
claim.campaign_form.save_m2m() claim.campaign_form.save_m2m()
claim.campaign_form = None
else: else:
c_type = 2 if claim.rights_holder.can_sell else 1 c_type = 2 if claim.rights_holder.can_sell else 1
claim.campaign_form = OpenCampaignForm( claim.campaign_form = OpenCampaignForm(
initial={'work': claim.work, 'name': claim.work.title, 'userid': request.user.id, 'managers_1': request.user.id, 'type': c_type}, initial={'work': claim.work, 'name': claim.work.title, 'userid': request.user.id, 'managers': [request.user.id], 'type': c_type},
prefix = 'cl_'+str(claim.id), prefix = 'cl_'+str(claim.id),
) )
if claim.campaign:
if claim.campaign.status in ['ACTIVE','INITIALIZED']:
if request.method == 'POST' and request.POST.has_key('edit_managers_%s'% claim.campaign.id) :
claim.campaign.edit_managers_form=EditManagersForm( instance=claim.campaign, data=request.POST, prefix=claim.campaign.id)
if claim.campaign.edit_managers_form.is_valid():
claim.campaign.edit_managers_form.save()
claim.campaign.edit_managers_form = EditManagersForm(instance=claim.campaign, prefix=claim.campaign.id)
else:
claim.campaign.edit_managers_form=EditManagersForm(instance=claim.campaign, prefix=claim.campaign.id)
campaigns = request.user.campaigns.all() campaigns = request.user.campaigns.all()
new_campaign = None new_campaign = None
for campaign in campaigns: for campaign in campaigns:
@ -1677,7 +1674,7 @@ def rh_tools(request):
campaign.clone_form= CloneCampaignForm(initial={'campaign_id':campaign.id}, prefix = 'c%s' % campaign.id) campaign.clone_form= CloneCampaignForm(initial={'campaign_id':campaign.id}, prefix = 'c%s' % campaign.id)
return render(request, "rh_tools.html", {'claims': claims ,'campaigns': campaigns}) return render(request, "rh_tools.html", {'claims': claims ,'campaigns': campaigns})
def rh_admin(request): def rh_admin(request, facet='top'):
if not request.user.is_authenticated() : if not request.user.is_authenticated() :
return render(request, "admins_only.html") return render(request, "admins_only.html")
if not request.user.is_staff : if not request.user.is_staff :
@ -1710,6 +1707,7 @@ def rh_admin(request):
'pending': zip(pending_data,pending_formset), 'pending': zip(pending_data,pending_formset),
'pending_formset': pending_formset, 'pending_formset': pending_formset,
'active_data': active_data, 'active_data': active_data,
'facet': facet,
} }
return render(request, "rights_holders.html", context) return render(request, "rights_holders.html", context)
@ -2856,15 +2854,15 @@ def kindle_config(request, work_id=None):
def send_to_kindle(request, work_id, javascript='0'): def send_to_kindle(request, work_id, javascript='0'):
# make sure to gracefully communicate with both js and non-js (kindle!) users # make sure to gracefully communicate with both js and non-js (kindle!) users
def local_response(request, javascript, message): def local_response(request, javascript, context, message):
context['message'] = message
if javascript == '1': if javascript == '1':
return render(request,'kindle_response_message.html',{'message': message} ) return render(request,'kindle_response_message.html',context )
else: else:
# can't pass context with HttpResponseRedirect return render(request, 'kindle_response_graceful_degradation.html', context)
# must use an HttpResponse, not a render(), after POST
return HttpResponseRedirect(reverse('send_to_kindle_graceful', args=(message,)))
work=safe_get_work(work_id) work=safe_get_work(work_id)
context= {'work':work}
acq = None acq = None
if request.user.is_authenticated(): if request.user.is_authenticated():
try: try:
@ -2893,17 +2891,19 @@ def send_to_kindle(request, work_id, javascript='0'):
logger.info('ebook: {0}, user_ip: {1}'.format(work_id, request.META['REMOTE_ADDR'])) logger.info('ebook: {0}, user_ip: {1}'.format(work_id, request.META['REMOTE_ADDR']))
title = ebook.edition.title title = ebook.edition.title
title = title.replace(' ', '_') title = title.replace(' ', '_')
context['ebook_url']=ebook_url
context['ebook_format']=ebook_format
if request.POST.has_key('kindle_email'): if request.POST.has_key('kindle_email'):
kindle_email = request.POST['kindle_email'] kindle_email = request.POST['kindle_email']
try: try:
validate_email(kindle_email) validate_email(kindle_email)
except ValidationError: except ValidationError:
return local_response(request, javascript, 3) return local_response(request, javascript, context, 3)
request.session['kindle_email'] = kindle_email request.session['kindle_email'] = kindle_email
elif request.user.is_authenticated(): elif request.user.is_authenticated():
kindle_email = request.user.profile.kindle_email kindle_email = request.user.profile.kindle_email
context['kindle_email'] = kindle_email
""" """
@ -2923,7 +2923,7 @@ def send_to_kindle(request, work_id, javascript='0'):
filesize = int(filehandle.info().getheaders("Content-Length")[0]) filesize = int(filehandle.info().getheaders("Content-Length")[0])
if filesize > 7492232: if filesize > 7492232:
logger.info('ebook %s is too large to be emailed' % work.id) logger.info('ebook %s is too large to be emailed' % work.id)
return local_response(request, javascript, 0) return local_response(request, javascript, context, 0)
try: try:
email = EmailMessage(from_email='notices@gluejar.com', email = EmailMessage(from_email='notices@gluejar.com',
@ -2932,18 +2932,12 @@ def send_to_kindle(request, work_id, javascript='0'):
email.send() email.send()
except: except:
logger.warning('Unexpected error: %s', sys.exc_info()) logger.warning('Unexpected error: %s', sys.exc_info())
return local_response(request, javascript, 1) return local_response(request, javascript, context, 1)
if request.POST.has_key('kindle_email') and not request.user.is_authenticated(): if request.POST.has_key('kindle_email') and not request.user.is_authenticated():
return HttpResponseRedirect(reverse('superlogin')) return HttpResponseRedirect(reverse('superlogin'))
return local_response(request, javascript, 2) return local_response(request, javascript, context, 2)
def send_to_kindle_graceful(request, message):
return render(
request,
'kindle_response_graceful_degradation.html',
{'message': int(message)}
)
def marc(request, userlist=None): def marc(request, userlist=None):
link_target = 'UNGLUE' link_target = 'UNGLUE'