Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend Us views and urls #81

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions install/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,65 @@
"value": {
"default": "<p>Note: We don't have data for the country selected, so we could not adjust the GNI per capita accordingly, but you can still sign up! Please contact us for a custom quote.</p>"
}
},
{
"group": {
"name": "plugin:consortial_billing"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you'd want to use the plugin naming scheme for the group, but bear in mind these will not be seen as email templates elsewhere in Janeway (e.g. email template manager). setting the group as "email" is the only way to achieve that at the moment.

If you wanted this behaviour, every email setting will also need a "email_subject" group member as a counterpart.

},
"setting": {
"description": "General email for recommending the OLH",
"is_translatable": true,
"name": "recommend_us_general_email",
"pretty_name": "Recommend Us General Email",
"type": "rich-text"
},
"value": {
"default": "<p>Dear Librarian,</p><p>I am writing to ask if the library would be able to join the Open Library of Humanities please? I am very impressed with their <a href=\"https://www.openlibhums.org/site/become-a-supporter/\">excellent cause as a diamond open-access publisher</a>. Many thanks.</p>"
}
},
{
"group": {
"name": "plugin:consortial_billing"
},
"setting": {
"description": "Author email for recommending the OLH",
"is_translatable": true,
"name": "recommend_us_author_email",
"pretty_name": "Recommend Us Author Email",
"type": "rich-text"
},
"value": {
"default": "<p>Dear Librarian,</p><p>I am writing to ask if the library would be able to join the Open Library of Humanities please? I recently published my paper ‘<a href=\"{% if article.doi %}{{ article.doi }}{% else %}{{ article.url }}{% endif %}\">{{ article.title|safe }}</a>’ in <i>{{ article.journal.name }}</i> with the Open Library of Humanities, and I was very impressed with their publication process and <a href=\"https://www.openlibhums.org/site/become-a-supporter/\">excellent cause as a diamond open-access publisher</a>. Many thanks.</p>"
}
},
{
"group": {
"name": "plugin:consortial_billing"
},
"setting": {
"description": "Reader email for recommending the OLH",
"is_translatable": true,
"name": "recommend_us_reader_email",
"pretty_name": "Recommend Us Reader Email",
"type": "rich-text"
},
"value": {
"default": "<p>Dear Librarian,</p><p>I am writing to ask if the library would be able to join the Open Library of Humanities please? I recently read ‘<a href=\"{% if article.doi %}{{ article.doi }}{% else %}{{ article.url }}{% endif %}\">{{ article.title|safe }}</a>’ in <i>{{ article.journal.name }}</i>, and I was very impressed with their publication process and <a href=\"https://www.openlibhums.org/site/become-a-supporter/\">excellent cause as a diamond open-access publisher</a>. Many thanks.</p>"
}
},
{
"group": {
"name": "plugin:consortial_billing"
},
"setting": {
"description": "Editor email for recommending the OLH",
"is_translatable": true,
"name": "recommend_us_editor_email",
"pretty_name": "Recommend Us Editor Email",
"type": "rich-text"
},
"value": {
"default": "<p>Dear Librarian,</p><p>I am writing to ask if the library would be able to join the Open Library of Humanities please? I am an editor for <a href=\"{{ journal.site_url }}\"><i>{{ journal.name }}</i></a>, and I am in strong support of their <a href=\"https://www.openlibhums.org/site/become-a-supporter/\">excellent cause as a diamond open-access publisher</a>. Many thanks.</p>"
}
}
]
12 changes: 12 additions & 0 deletions templates/consortial_billing/requires_hourglass.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "core/base.html" %}

{% load static %}

{% block title %}
Requires Hourglass theme
{% endblock title %}

{% block body %}
<h1>Requires Hourglass theme</h1>
<p>To use this page, you need the Hourglass theme installed.</p>
{% endblock body %}
40 changes: 40 additions & 0 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,44 @@
views.edit_supporter_band,
name='edit_supporter_band',
),
re_path(
r'^recommend-us/$',
views.recommend_us,
name='recommend_us',
),
re_path(
r'^recommend-us/see-matching-supporters/$',
views.recommend_us_see_matching_supporters,
name='recommend_us_see_matching_supporters',
),
re_path(
r'^recommend-us/choose-role/$',
views.recommend_us_choose_role,
name='recommend_us_choose_role',
),
re_path(
r'^recommend-us/search-article/$',
views.recommend_us_search_article,
name='recommend_us_search_article',
),
re_path(
r'^recommend-us/search-journal/$',
views.recommend_us_search_journal,
name='recommend_us_search_journal',
),
re_path(
r'^recommend-us/choose-article/$',
views.recommend_us_choose_article,
name='recommend_us_choose_article',
),
re_path(
r'^recommend-us/choose-journal/$',
views.recommend_us_choose_journal,
name='recommend_us_choose_journal',
),
re_path(
r'^recommend-us/generate-email/$',
views.recommend_us_generate_email,
name='recommend_us_generate_email',
),
]
173 changes: 173 additions & 0 deletions views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,41 @@
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib import messages
from django.db.models import OuterRef, Subquery
from django.views.decorators.http import require_POST
from django.utils.decorators import method_decorator
from django.template import Template, RequestContext

from plugins.consortial_billing import utils, \
logic, models as supporter_models, plugin_settings, forms
from plugins.consortial_billing.notifications import notify

from core.views import GenericFacetedListView
from core.models import Account
from journal.models import Journal
from core.model_utils import search_model_admin
from cms import models as cms_models
from core.models import SettingValue
from utils.logger import get_logger
from utils.logic import get_current_request
from security.decorators import base_check_required
from submission import models as submission_models


logger = get_logger(__name__)


def requires_hourglass(template):
"""
A helper for accessing templates that only exist in Hourglass,
with a fallback template to explain this if needed.
"""
request = get_current_request()
if request.press.theme == 'hourglass':
return template
else:
return 'consortial_billing/requires_hourglass.html'


@staff_member_required
def manager(request):

Expand Down Expand Up @@ -425,3 +444,157 @@ def edit_supporter_band(request, supporter_id=None):
return render(request, template, context)


def recommend_us(request):
"""
A view for authors, editors, readers, and others
to generate an email for recommending us to their librarian.
Depends on the subsequent views via HTMX.
"""
template = requires_hourglass('custom/recommend-us.html')
context = {
'step': '1',
}
return render(request, template, context)


@require_POST
def recommend_us_see_matching_supporters(request):
query = request.POST.get('supporter_query', '')
if query:
supporters = supporter_models.Supporter.objects.filter(name__icontains=query)
else:
supporters = supporter_models.Supporter.objects.none()
template = requires_hourglass(
'custom/recommend-us-see-matching-supporters.html'
)
context = {
'supporters': supporters,
'step': '2',
'query': query,
}
return render(request, template, context)


@require_POST
def recommend_us_choose_role(request):
template = requires_hourglass('custom/recommend-us-choose-role.html')
context = {
'step': '3',
}
return render(request, template, context)


@require_POST
def recommend_us_search_article(request):
context = {
'step': '4',
}
if 'author' in request.POST:
context['role'] = 'author'
elif 'reader' in request.POST:
context['role'] = 'reader'
template = requires_hourglass('custom/recommend-us-search-article.html')
return render(request, template, context)


@require_POST
def recommend_us_search_journal(request):
context = {
'role': 'editor',
'step': '4',
}
template = requires_hourglass('custom/recommend-us-search-journal.html')
return render(request, template, context)


@require_POST
def recommend_us_choose_article(request):
query = request.POST.get('article_query', '')
if query:
search_filters = {"title": True}
articles = submission_models.Article.objects.search(query, search_filters)
else:
articles = submission_models.Article.objects.none()
role = request.POST.get('role', '')
template = requires_hourglass('custom/recommend-us-choose-article.html')
context = {
'articles': articles,
'step': '5',
'role': role,
'query': query,
}
return render(request, template, context)


@require_POST
def recommend_us_choose_journal(request):
query = request.POST.get('journal_query', '')
if query:
journal_names = SettingValue.objects.filter(
setting__name='journal_name',
value__icontains=query,
journal__in=request.press.public_journals,
)
else:
journal_names = SettingValue.objects.none()
role = request.POST.get('role', '')
template = requires_hourglass('custom/recommend-us-choose-journal.html')
context = {
'journal_names': journal_names,
'step': '5',
'role': role,
'query': query,
}
return render(request, template, context)


@require_POST
def recommend_us_generate_email(request):
role = request.POST.get('role', '')
step = '6'
setting_name = 'recommend_us_general_email'

if role == 'author':
setting_name = 'recommend_us_author_email'
elif role == 'reader':
setting_name = 'recommend_us_reader_email'
elif role == 'editor':
setting_name = 'recommend_us_editor_email'
else:
# We assume this is "other" because no role input is available
# in the request data.
setting_name = 'recommend_us_general_email'
step = '4'

# An author, reader, or editor could not find the article or journal so
# selects general
if 'general' in request.POST:
setting_name = 'recommend_us_general_email'

template = Template(utils.setting(setting_name))
setting_context = RequestContext(request)

article_pk = request.POST.get('article_pk', '')
if article_pk:
try:
article = request.press.published_articles.get(pk=article_pk)
setting_context['article'] = article
except submission_models.Article.DoesNotExist:
article = None

journal_pk = request.POST.get('journal_pk', '')
if journal_pk:
try:
journal = request.press.public_journals.get(pk=journal_pk)
setting_context['journal'] = journal
except Journal.DoesNotExist:
journal = None

email = template.render(setting_context)
context = {
'email': email,
'step': step,
}

template = requires_hourglass('custom/recommend-us-generate-email.html')
return render(request, template, context)