Implement publisher and feedback email in campaign management

(feedback view made more flexible)
pull/1/head
eric 2013-03-27 12:22:30 -04:00
parent 2b28add6a8
commit 3a81db3804
9 changed files with 111 additions and 38 deletions

View File

@ -847,6 +847,10 @@ class Work(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('work', args=[str(self.id)]) return reverse('work', args=[str(self.id)])
def publishers(self):
# returns a set of publishers associated with this Work
return Publisher.objects.filter(name__editions__work=self).distinct()
class Author(models.Model): class Author(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=500) name = models.CharField(max_length=500)
@ -970,9 +974,9 @@ class Edition(models.Model):
class Publisher(models.Model): class Publisher(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
name = models.ForeignKey('PublisherName', related_name='key_publisher') name = models.ForeignKey('PublisherName', related_name='key_publisher')
url = models.URLField(max_length=1024, null=True) url = models.URLField(max_length=1024, null=True, blank=True)
logo_url = models.URLField(max_length=1024, null=True) logo_url = models.URLField(max_length=1024, null=True, blank=True)
description = models.TextField(default='', null=True) description = models.TextField(default='', null=True, blank=True)
def __unicode__(self): def __unicode__(self):
return self.name.name return self.name.name

View File

@ -303,10 +303,11 @@ def getManageCampaignForm ( instance, data=None, *args, **kwargs ):
edition = forms.ModelChoiceField(get_queryset(), widget=RadioSelect(),empty_label='no edition selected',required = False,) edition = forms.ModelChoiceField(get_queryset(), widget=RadioSelect(),empty_label='no edition selected',required = False,)
minimum_target = settings.UNGLUEIT_MINIMUM_TARGET minimum_target = settings.UNGLUEIT_MINIMUM_TARGET
latest_ending = (timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE)) + now()).date latest_ending = (timedelta(days=int(settings.UNGLUEIT_LONGEST_DEADLINE)) + now()).date
publisher = forms.ModelChoiceField(instance.work.publishers(), empty_label='no publisher selected', required = False,)
class Meta: class Meta:
model = Campaign model = Campaign
fields = 'description', 'details', 'license', 'target', 'deadline', 'paypal_receiver', 'edition' fields = 'description', 'details', 'license', 'target', 'deadline', 'paypal_receiver', 'edition', 'email', 'publisher'
widgets = { widgets = {
'deadline': SelectDateWidget, 'deadline': SelectDateWidget,
} }

View File

@ -0,0 +1,34 @@
{% extends "basedocumentation.html" %}
{% block title %}Campaign questions{% endblock %}
{% block doccontent %}
{% if campaign.email %}
<p>Questions about {{campaign}}? Ask away!</p>
To: {{campaign}}<br /><br />
<form method="POST" action="#">
{% csrf_token %}
{{ form.sender.errors }}
{{ form.sender.label_tag }}<br />
{{ form.sender }}<br /><br />
{{ form.subject.errors }}
{{ form.subject.label_tag }}<br />
{{ form.subject }}<br /><br />
{{ form.message.errors }}
{{ form.message.label_tag }}<br />
{{ form.message }}<br /><br />
{{ form.notarobot.errors }}
{{ form.non_field_errors }}
Please prove you're not a robot. {{num1}} + {{num2}} =
{{ form.notarobot }}</br /><br />
{{ form.answer }}
{{ form.num1 }}
{{ form.num2 }}
{{ form.page }}
<input type="submit" value="Submit" />
</form>
{% else %}
<p>Sorry, this campaign isn't set up to answer emails at this time.</p>
{% endif %}
{% endblock %}

View File

@ -0,0 +1,4 @@
{{ sender }} has a question about {{campaign}}
_____________________________________
{{ message }}

View File

@ -0,0 +1,5 @@
This feedback is about {{ page }}
From {{ sender }}, ungluer name {{ request.user.username }}
user agent {{ request.META.HTTP_USER_AGENT }}
_____________________________________
{{ message }}

View File

@ -246,12 +246,17 @@ Please fix the following before launching your campaign:
{{ form.deadline.errors }}<span style="display: none">{{ form.deadline }}</span> {{ form.deadline.errors }}<span style="display: none">{{ form.deadline }}</span>
{% endifnotequal %} {% endifnotequal %}
<h3>e-mail contact address</h3> <h3>e-mail contact addresses</h3>
<p>Enter the email address where notifications about this campaign should be sent. If your campaign succeeds, this email needs to work if you want to get paid!</p> <p>Enter the email address where notifications about this campaign should be sent. If your campaign succeeds, this email needs to work if you want to get paid! This address will not be exposed on the website.</p>
<p>{{ form.paypal_receiver.errors }}{{ form.paypal_receiver }}</p> <p>{{ form.paypal_receiver.errors }}{{ form.paypal_receiver }}</p>
<p>(Optional, but highly recommended). Enter an email address where ungluers with questions about the book or the campaign can contact you or someone involved. This address will not be exposed on the website.</p>
<p>{{ form.email.errors }}{{ form.email }}</p>
{% if work.publishers %}
<h3>Publisher</h3>
<p>If you are set up as an unglue.it publisher (send us a url, logo, description and list of ways your name might appear) you can link your campaign by selecting the publisher here:
<p>{{ form.publisher.errors }}{{ form.publisher }}</p>
{% endif %}
{% ifequal campaign_status 'ACTIVE' %} {% ifequal campaign_status 'ACTIVE' %}
<div class="yikes">When you click this button, your changes will be visible to supporters immediately. Make sure to proofread!</div><br /> <div class="yikes">When you click this button, your changes will be visible to supporters immediately. Make sure to proofread!</div><br />
<input type="submit" name="save" value="Modify Campaign" /> <input type="submit" name="save" value="Modify Campaign" />

View File

@ -73,7 +73,12 @@
<div> <div>
<div class="pubinfo"> <div class="pubinfo">
<h3 class="book-author" itemprop="author">{{ work.author }}</h3> <h3 class="book-author" itemprop="author">{{ work.author }}</h3>
<h3 class="book-year" itemprop="datePublished">{{ work.publication_date_year }}</h3> <h3 class="book-year">
{% if work.last_campaign.publisher %}
<span itemprop="publisher"><a href="{% url bypubname_list work.last_campaign.publisher.name.id %}">{{ work.last_campaign.publisher }}</a></span>
{% endif %}
<span itemprop="datePublished">{{ work.publication_date_year }}</span>
</h3>
</div> </div>
</div> </div>
</div> </div>
@ -412,6 +417,16 @@
</div> </div>
<br /> <br />
<div class="js-rightcol-pad rounded"> <div class="js-rightcol-pad rounded">
{% ifequal status 'ACTIVE' %}{% if work.last_campaign.email %}
<div class="jsmodule">
<h3 class="jsmod-title"><span>Ask Questions</span></h3>
<div class="jsmod-content">
<ul class="social menu">
<a href="{% url ask_rh work.last_campaign.id %}"><li class="email"><span>Email the Rights Holder</span></li></a>
</ul>
</div>
</div>
{% endif %}{% endifequal %}
<div class="jsmodule"> <div class="jsmodule">
<h3 class="jsmod-title"><span>Share</span></h3> <h3 class="jsmod-title"><span>Share</span></h3>
<div class="jsmod-content"> <div class="jsmod-content">

View File

@ -81,6 +81,7 @@ urlpatterns = patterns(
url('^500testing/$', direct_to_template, {'template': '500.html'}), url('^500testing/$', direct_to_template, {'template': '500.html'}),
url('^robots.txt$', direct_to_template, {'template': 'robots.txt', 'mimetype': 'text/plain'}), url('^robots.txt$', direct_to_template, {'template': 'robots.txt', 'mimetype': 'text/plain'}),
url(r"^emailshare/(?P<action>\w*)/?$", "emailshare", name="emailshare"), url(r"^emailshare/(?P<action>\w*)/?$", "emailshare", name="emailshare"),
url(r"^feedback/campaign/(?P<campaign_id>\d+)/?$", "ask_rh", name="ask_rh"),
url(r"^feedback/$", "feedback", name="feedback"), url(r"^feedback/$", "feedback", name="feedback"),
url(r"^feedback/thanks/$", TemplateView.as_view(template_name="thanks.html")), url(r"^feedback/thanks/$", TemplateView.as_view(template_name="thanks.html")),
url(r"^press/$", TemplateView.as_view(template_name="press.html"), url(r"^press/$", TemplateView.as_view(template_name="press.html"),

View File

@ -533,7 +533,7 @@ class ByPubView(WorkListView):
self.set_publisher() self.set_publisher()
def set_publisher(self): def set_publisher(self):
if self.publisher_name.key_publisher: if self.publisher_name.key_publisher.count():
self.publisher = self.publisher_name.key_publisher.all()[0] self.publisher = self.publisher_name.key_publisher.all()[0]
elif self.publisher_name.publisher: elif self.publisher_name.publisher:
self.publisher = self.publisher_name.publisher self.publisher = self.publisher_name.publisher
@ -2131,45 +2131,49 @@ def emailshare(request, action):
return render(request, "emailshare.html", {'form':form}) return render(request, "emailshare.html", {'form':form})
def feedback(request): def ask_rh(request, campaign_id):
num1 = randint(0,10) campaign = get_object_or_404(models.Campaign, id=campaign_id)
num2 = randint(0,10) return feedback(request, recipient=campaign.email, template="ask_rh.html",
sum = num1 + num2 message_template="ask_rh.txt",
redirect_url = reverse('work', args=[campaign.work.id]),
extra_context={'campaign':campaign, 'subject':campaign })
def feedback(request, recipient='support@gluejar.com', template='feedback.html', message_template='feedback.txt', extra_context=None, redirect_url=None):
context = extra_context or {}
context['num1'] = randint(0,10)
context['num2'] = randint(0,10)
context['answer'] = context['num1'] + context['num2']
if request.method == 'POST': if request.method == 'POST':
form=FeedbackForm(request.POST) form=FeedbackForm(request.POST)
if form.is_valid(): if form.is_valid():
subject = form.cleaned_data['subject'] context.update(form.cleaned_data)
message = form.cleaned_data['message'] context['request']=request
sender = form.cleaned_data['sender'] if extra_context:
recipient = 'support@gluejar.com' context.update(extra_context)
page = form.cleaned_data['page'] message = render_to_string(message_template,context)
useragent = request.META['HTTP_USER_AGENT'] send_mail_task.delay(context['subject'], message, context['sender'], [recipient])
if request.user.is_anonymous(): if redirect_url:
ungluer = "(not logged in)" return HttpResponseRedirect(redirect_url)
else: else:
ungluer = request.user.username return render(request, "thanks.html", context)
message = "<<<This feedback is about "+page+". Original user message follows\nfrom "+sender+", ungluer name "+ungluer+"\nwith user agent "+useragent+"\n>>>\n"+message
send_mail_task.delay(subject, message, sender, [recipient])
return render(request, "thanks.html", {"page":page})
else: else:
num1 = request.POST['num1'] context['num1'] = request.POST['num1']
num2 = request.POST['num2'] context['num2'] = request.POST['num2']
else: else:
if request.user.is_authenticated(): if request.user.is_authenticated():
sender=request.user.email; context['sender']=request.user.email;
else:
sender=''
try: try:
page = request.GET['page'] context['page'] = request.GET['page']
except: except:
page='/' context['page'] = '/'
form = FeedbackForm(initial={"sender":sender, "subject": "Feedback on page "+page, "page":page, "num1":num1, "num2":num2, "answer":sum}) if not context.has_key('subject'):
context['subject'] = "Feedback on page "+context['page']
return render(request, "feedback.html", {'form':form, 'num1':num1, 'num2':num2}) form = FeedbackForm(initial=context)
context['form'] = form
return render(request, template, context)
def comment(request): def comment(request):
latest_comments = Comment.objects.all().order_by('-submit_date')[:20] latest_comments = Comment.objects.all().order_by('-submit_date')[:20]