diff --git a/core/models.py b/core/models.py index 95ac9102..3961eee0 100755 --- a/core/models.py +++ b/core/models.py @@ -847,6 +847,10 @@ class Work(models.Model): def get_absolute_url(self): 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): created = models.DateTimeField(auto_now_add=True) name = models.CharField(max_length=500) @@ -970,9 +974,9 @@ class Edition(models.Model): class Publisher(models.Model): created = models.DateTimeField(auto_now_add=True) name = models.ForeignKey('PublisherName', related_name='key_publisher') - url = models.URLField(max_length=1024, null=True) - logo_url = models.URLField(max_length=1024, null=True) - description = models.TextField(default='', null=True) + url = models.URLField(max_length=1024, null=True, blank=True) + logo_url = models.URLField(max_length=1024, null=True, blank=True) + description = models.TextField(default='', null=True, blank=True) def __unicode__(self): return self.name.name diff --git a/frontend/forms.py b/frontend/forms.py index 9ac48114..6318680c 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -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,) minimum_target = settings.UNGLUEIT_MINIMUM_TARGET 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: model = Campaign - fields = 'description', 'details', 'license', 'target', 'deadline', 'paypal_receiver', 'edition' + fields = 'description', 'details', 'license', 'target', 'deadline', 'paypal_receiver', 'edition', 'email', 'publisher' widgets = { 'deadline': SelectDateWidget, } diff --git a/frontend/templates/ask_rh.html b/frontend/templates/ask_rh.html new file mode 100644 index 00000000..2ce66338 --- /dev/null +++ b/frontend/templates/ask_rh.html @@ -0,0 +1,34 @@ +{% extends "basedocumentation.html" %} + +{% block title %}Campaign questions{% endblock %} + +{% block doccontent %} +{% if campaign.email %} +

Questions about {{campaign}}? Ask away!

+ + To: {{campaign}}

+
+ {% csrf_token %} + {{ form.sender.errors }} + {{ form.sender.label_tag }}
+ {{ form.sender }}

+ {{ form.subject.errors }} + {{ form.subject.label_tag }}
+ {{ form.subject }}

+ {{ form.message.errors }} + {{ form.message.label_tag }}
+ {{ form.message }}

+ {{ form.notarobot.errors }} + {{ form.non_field_errors }} + Please prove you're not a robot. {{num1}} + {{num2}} = + {{ form.notarobot }}

+ {{ form.answer }} + {{ form.num1 }} + {{ form.num2 }} + {{ form.page }} + +
+{% else %} +

Sorry, this campaign isn't set up to answer emails at this time.

+{% endif %} +{% endblock %} \ No newline at end of file diff --git a/frontend/templates/ask_rh.txt b/frontend/templates/ask_rh.txt new file mode 100644 index 00000000..fe9a1225 --- /dev/null +++ b/frontend/templates/ask_rh.txt @@ -0,0 +1,4 @@ +{{ sender }} has a question about {{campaign}} +_____________________________________ + +{{ message }} \ No newline at end of file diff --git a/frontend/templates/feedback.txt b/frontend/templates/feedback.txt new file mode 100644 index 00000000..ca1aed78 --- /dev/null +++ b/frontend/templates/feedback.txt @@ -0,0 +1,5 @@ +This feedback is about {{ page }} +From {{ sender }}, ungluer name {{ request.user.username }} +user agent {{ request.META.HTTP_USER_AGENT }} +_____________________________________ +{{ message }} \ No newline at end of file diff --git a/frontend/templates/manage_campaign.html b/frontend/templates/manage_campaign.html index d03c7ef2..9dac0f80 100644 --- a/frontend/templates/manage_campaign.html +++ b/frontend/templates/manage_campaign.html @@ -246,12 +246,17 @@ Please fix the following before launching your campaign: {{ form.deadline.errors }}{{ form.deadline }} {% endifnotequal %} -

e-mail contact address

-

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!

- - +

e-mail contact addresses

+

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.

{{ form.paypal_receiver.errors }}{{ form.paypal_receiver }}

- +

(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.

+

{{ form.email.errors }}{{ form.email }}

+ + {% if work.publishers %} +

Publisher

+

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: +

{{ form.publisher.errors }}{{ form.publisher }}

+ {% endif %} {% ifequal campaign_status 'ACTIVE' %}
When you click this button, your changes will be visible to supporters immediately. Make sure to proofread!

diff --git a/frontend/templates/work.html b/frontend/templates/work.html index 9dcfa196..a3b8ef72 100644 --- a/frontend/templates/work.html +++ b/frontend/templates/work.html @@ -73,7 +73,12 @@
- +

+ {% if work.last_campaign.publisher %} + {{ work.last_campaign.publisher }} + {% endif %} + +

@@ -412,6 +417,16 @@
+ {% ifequal status 'ACTIVE' %}{% if work.last_campaign.email %} +
+

Ask Questions

+ +
+ {% endif %}{% endifequal %}

Share

diff --git a/frontend/urls.py b/frontend/urls.py index ac9f8c24..bb70f23d 100644 --- a/frontend/urls.py +++ b/frontend/urls.py @@ -81,6 +81,7 @@ urlpatterns = patterns( url('^500testing/$', direct_to_template, {'template': '500.html'}), url('^robots.txt$', direct_to_template, {'template': 'robots.txt', 'mimetype': 'text/plain'}), url(r"^emailshare/(?P\w*)/?$", "emailshare", name="emailshare"), + url(r"^feedback/campaign/(?P\d+)/?$", "ask_rh", name="ask_rh"), url(r"^feedback/$", "feedback", name="feedback"), url(r"^feedback/thanks/$", TemplateView.as_view(template_name="thanks.html")), url(r"^press/$", TemplateView.as_view(template_name="press.html"), diff --git a/frontend/views.py b/frontend/views.py index bf3e7a9b..9ab7e6be 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -533,7 +533,7 @@ class ByPubView(WorkListView): self.set_publisher() 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] elif 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}) -def feedback(request): - num1 = randint(0,10) - num2 = randint(0,10) - sum = num1 + num2 +def ask_rh(request, campaign_id): + campaign = get_object_or_404(models.Campaign, id=campaign_id) + return feedback(request, recipient=campaign.email, template="ask_rh.html", + 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': form=FeedbackForm(request.POST) if form.is_valid(): - subject = form.cleaned_data['subject'] - message = form.cleaned_data['message'] - sender = form.cleaned_data['sender'] - recipient = 'support@gluejar.com' - page = form.cleaned_data['page'] - useragent = request.META['HTTP_USER_AGENT'] - if request.user.is_anonymous(): - ungluer = "(not logged in)" + context.update(form.cleaned_data) + context['request']=request + if extra_context: + context.update(extra_context) + message = render_to_string(message_template,context) + send_mail_task.delay(context['subject'], message, context['sender'], [recipient]) + if redirect_url: + return HttpResponseRedirect(redirect_url) else: - ungluer = request.user.username - message = "<<>>\n"+message - send_mail_task.delay(subject, message, sender, [recipient]) - - return render(request, "thanks.html", {"page":page}) + return render(request, "thanks.html", context) else: - num1 = request.POST['num1'] - num2 = request.POST['num2'] + context['num1'] = request.POST['num1'] + context['num2'] = request.POST['num2'] else: if request.user.is_authenticated(): - sender=request.user.email; - else: - sender='' + context['sender']=request.user.email; try: - page = request.GET['page'] + context['page'] = request.GET['page'] except: - page='/' - form = FeedbackForm(initial={"sender":sender, "subject": "Feedback on page "+page, "page":page, "num1":num1, "num2":num2, "answer":sum}) - - return render(request, "feedback.html", {'form':form, 'num1':num1, 'num2':num2}) + context['page'] = '/' + if not context.has_key('subject'): + context['subject'] = "Feedback on page "+context['page'] + form = FeedbackForm(initial=context) + context['form'] = form + return render(request, template, context) def comment(request): latest_comments = Comment.objects.all().order_by('-submit_date')[:20]