SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 5e348440 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add ContactRole emailing facilities

parent 7b735c3a
No related branches found
No related tags found
No related merge requests found
......@@ -168,6 +168,15 @@ class Organization(models.Model):
"""
return self.subsidy_set.filter(date_until__gte=datetime.date.today()).exists()
@property
def latest_subsidy_date_until(self):
"""
Returns the end date of validity of the latest subsidy.
"""
if self.subsidy_set:
return self.subsidy_set.order_by('-date_until').first().date_until
return '-'
def get_total_subsidies_obtained(self, n_years_past=None):
"""
Computes the total amount received by SciPost, in the form
......
......@@ -191,6 +191,10 @@ $(document).ready(function($) {
<td>{% if contactrole.contact.user.is_active %}<i class="fa fa-check-circle text-success"></i>{% else %}<i class="fa fa-times-circle text-danger"></i>{% endif %}</td>
<td>
<ul>
{% if perms.scipost.can_manage_organizations %}
<li><a href="{% url 'organizations:email_contactrole' contactrole_id=contactrole.id %}">Email (generic)</a></li>
<li><a href="{% url 'organizations:email_contactrole' contactrole_id=contactrole.id mail='renewal' %}">Email (subsidy renewal)</a></li>
{% endif %}
{% if perms.scipost.can_manage_organizations or "can_view_org_contacts" in user_org_perms %}
<li><a href="{% url 'organizations:contactrole_update' pk=contactrole.id %}"><span class="text-warning">Update</span></a></li>
{% endif %}
......
......@@ -73,6 +73,16 @@ urlpatterns = [
views.organization_add_contact,
name='add_contact'
),
url(
r'^activate/(?P<activation_key>.+)$',
views.activate_account,
name='activate_account'
),
url(
r'^dashboard/$',
views.dashboard,
name='dashboard'
),
url(
r'^contactrole/(?P<pk>[0-9]+)/update/$',
views.ContactRoleUpdateView.as_view(),
......@@ -84,13 +94,13 @@ urlpatterns = [
name='contactrole_delete'
),
url(
r'^activate/(?P<activation_key>.+)$',
views.activate_account,
name='activate_account'
r'^contactrole/(?P<contactrole_id>[0-9]+)/email/(?P<mail>renewal)$',
views.email_contactrole,
name='email_contactrole'
),
url(
r'^dashboard/$',
views.dashboard,
name='dashboard'
r'^contactrole/(?P<contactrole_id>[0-9]+)/email/$',
views.email_contactrole,
name='email_contactrole'
),
]
......@@ -187,7 +187,8 @@ def email_contactperson(request, contactperson_id, mail=None):
suffix = ' (initial)'
mail_request = MailEditingSubView(request, mail_code=code, contactperson=contactperson)
if mail_request.is_valid():
comments = 'Email{suffix} sent to {name}.'.format(suffix=suffix, name=contactperson)
comments = 'Email{suffix} sent to ContactPerson {name}.'.format(
suffix=suffix, name=contactperson)
event = OrganizationEvent(
organization=contactperson.organization,
event=ORGANIZATION_EVENT_EMAIL_SENT,
......@@ -306,3 +307,33 @@ class ContactRoleDeleteView(PermissionsMixin, DeleteView):
def get_success_url(self):
return reverse_lazy('organizations:organization_details',
kwargs={'pk': self.object.organization.id})
@permission_required('scipost.can_manage_organizations', return_403=True)
@transaction.atomic
def email_contactrole(request, contactrole_id, mail=None):
contactrole = get_object_or_404(ContactRole, pk=contactrole_id)
suffix = ''
if mail == 'renewal':
code = 'org_contacts/contactrole_subsidy_renewal_mail'
suffix = ' (subsidy renewal query)'
else:
code = 'org_contacts/contactrole_generic_mail'
suffix = ' (generic)'
mail_request = MailEditingSubView(request, mail_code=code, contactrole=contactrole)
if mail_request.is_valid():
comments = 'Email{suffix} sent to Contact {name}.'.format(
suffix=suffix, name=contactrole.contact)
event = OrganizationEvent(
organization=contactrole.organization,
event=ORGANIZATION_EVENT_EMAIL_SENT,
comments=comments,
noted_on=timezone.now(),
noted_by=request.user)
event.save()
messages.success(request, 'Email successfully sent.')
mail_request.send()
return redirect(contactrole.organization.get_absolute_url())
else:
return mail_request.return_render()
<p>
Dear {{ contactrole.contact.get_title_display }} {{ contactrole.contact.user.last_name }},
</p>
<p>
On behalf of the SciPost Foundation,<br><br>
</p>
{
"subject": "SciPost: Sponsors",
"to_address": "contact.user.email",
"bcc_to": "sponsors@scipost.org",
"from_address_name": "SciPost Sponsors",
"from_address": "sponsors@scipost.org",
"context_object": "contactrole"
}
<p>
Dear {{ contactrole.contact.get_title_display }} {{ contactrole.contact.user.last_name }},
</p>
<p>
Your organization ({{ contactrole.organization }}) has been sponsoring SciPost (see details at <a href="https://scipost.org{{ contactrole.organization.get_absolute_url }}">this link</a>), for which we are extremely grateful.
</p>
<p>
Your latest sponsorship period ends on {{ contactrole.organization.latest_subsidy_date_until }}. We would be extremely grateful for your continued support, and would hereby like to enquire whether we can start the renewal procedure.
</p>
<p>
On behalf of the SciPost Foundation,<br><br>
</p>
{
"subject": "SciPost: Sponsorship renewal",
"to_address": "contact.user.email",
"bcc_to": "sponsors@scipost.org",
"from_address_name": "SciPost Sponsors",
"from_address": "sponsors@scipost.org",
"context_object": "contactrole"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment