Skip to content
Open
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
7 changes: 7 additions & 0 deletions admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ class BillingStafferAdmin(admin.ModelAdmin):
raw_id_fields = ('journal', 'staffer')


class VoluntaryContributionAdmin(admin.ModelAdmin):
list_display = ('pk', 'article', 'value', 'currency', 'recorded', 'contacted')
list_filter = ('contacted', 'currency')
raw_id_fields = ('article', 'section_apc')


admin_list = [
(SectionAPC, SectionAPCAdmin),
(WaiverApplication, WaiverApplicationAdmin),
(ArticleAPC, ArticleAPCAdmin),
(BillingStaffer, BillingStafferAdmin),
(VoluntaryContribution, VoluntaryContributionAdmin),
(Discount,),
]

Expand Down
114 changes: 96 additions & 18 deletions forms.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from django import forms
from django.forms.forms import NON_FIELD_ERRORS

from plugins.apc import models
from plugins.apc import models, plugin_settings as apc_plugin_settings
from core import models as core_models
from utils import setting_handler as core_setting_handler


class APCForm(forms.ModelForm):
class Meta:
model = models.SectionAPC
exclude = ('section',)
exclude = ("section",)

def save(self, section, commit=True):
section_apc = super(APCForm, self).save(commit=False)
Expand All @@ -21,46 +22,123 @@ def save(self, section, commit=True):


class WaiverResponse(forms.ModelForm):

class Meta:
model = models.WaiverApplication
fields = ('response',)
fields = ("response",)


class WaiverApplication(forms.ModelForm):

class Meta:
model = models.WaiverApplication
fields = ('rationale',)
fields = ("rationale",)


class APCSettingsForm(forms.Form):
enable_apcs = forms.BooleanField(
required=False,
widget=forms.CheckboxInput(attrs={"id": "enable_apcs"}),
)
track_apcs = forms.BooleanField(
required=False,
widget=forms.CheckboxInput(attrs={"id": "track_apcs"}),
)
author_contribution_mode = forms.ChoiceField(
choices=[
("", "None"),
("waiver", "Waiver"),
("vac", "Voluntary Author Contribution (VAC)"),
],
required=False,
widget=forms.Select(attrs={"id": "author_contribution_mode"}),
)
waiver_text = forms.CharField(
required=False,
widget=forms.Textarea(attrs={"id": "waiver_text"}),
)
vac_text = forms.CharField(
required=False,
widget=forms.Textarea(attrs={"id": "vac_text"}),
)

def __init__(self, *args, plugin=None, journal=None, **kwargs):
super().__init__(*args, **kwargs)
self.plugin = plugin
self.journal = journal
for field_name, pretty in apc_plugin_settings.APC_SETTINGS.items():
setting = core_setting_handler.get_plugin_setting(
plugin,
field_name,
journal,
create=True,
pretty=pretty,
)
self.fields[field_name].label = setting.setting.pretty_name
self.fields[field_name].help_text = setting.setting.description
if not self.is_bound:
if field_name in apc_plugin_settings.APC_BOOLEAN_SETTINGS:
self.initial[field_name] = setting.value == "on"
else:
self.initial[field_name] = setting.value or ""

def save(self):
data = self.cleaned_data
for field_name in apc_plugin_settings.APC_SETTINGS:
if field_name in apc_plugin_settings.APC_BOOLEAN_SETTINGS:
value = "on" if data[field_name] else ""
else:
value = data[field_name]
core_setting_handler.save_plugin_setting(
self.plugin,
field_name,
value,
self.journal,
)


class BillingStafferForm(forms.ModelForm):
class VACFilterForm(forms.Form):
accepted = forms.ChoiceField(
choices=[("", "All"), ("yes", "Accepted"), ("no", "Not Accepted")],
required=False,
label="Filter by acceptance",
widget=forms.Select(attrs={"onchange": "this.form.submit()"}),
)
contacted = forms.ChoiceField(
choices=[("", "All"), ("yes", "Contacted"), ("no", "Not Contacted")],
required=False,
label="Filter by contacted",
widget=forms.Select(attrs={"onchange": "this.form.submit()"}),
)


class BillingStafferForm(forms.ModelForm):
class Meta:
model = models.BillingStaffer
fields = ('staffer', 'type_of_notification', 'receives_notifications')
fields = ("staffer", "type_of_notification", "receives_notifications")

def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')
self.request = kwargs.pop("request")
super(BillingStafferForm, self).__init__(*args, **kwargs)

user_pks = self.request.journal.journal_users(objects=False)
self.fields['staffer'].queryset = core_models.Account.objects.filter(
self.fields["staffer"].queryset = core_models.Account.objects.filter(
pk__in=user_pks,
)

def clean(self):
staffer = self.cleaned_data.get('staffer')
type_of_notification = self.cleaned_data.get('type_of_notification')
staffer = self.cleaned_data.get("staffer")
type_of_notification = self.cleaned_data.get("type_of_notification")
journal = self.request.journal

if not self.instance.pk and models.BillingStaffer.objects.filter(
staffer=staffer,
journal=journal,
type_of_notification=type_of_notification,
).exists():
if (
not self.instance.pk
and models.BillingStaffer.objects.filter(
staffer=staffer,
journal=journal,
type_of_notification=type_of_notification,
).exists()
):
self._errors[NON_FIELD_ERRORS] = self.error_class(
['A Billing Staffer with this user, journal and type already exists.']
["A Billing Staffer with this user, journal and type already exists."]
)

return self.cleaned_data
Expand Down
65 changes: 39 additions & 26 deletions hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,50 +43,64 @@ def waiver_info(context):
plugin = plugin_settings.get_self()
request = context['request']

waiver_text = setting_handler.get_plugin_setting(
author_contribution_mode = setting_handler.get_plugin_setting(
plugin,
'waiver_text',
'author_contribution_mode',
request.journal,
create=True,
pretty='Waiver Text',
)
enable_waivers = setting_handler.get_plugin_setting(
plugin,
'enable_waivers',
request.journal,
create=True,
pretty='Enable Waivers',
pretty='Author Contribution Mode',
)

if enable_waivers.value == 'on':
mode = author_contribution_mode.value if author_contribution_mode else ''

if mode == 'vac':
vac_text = setting_handler.get_plugin_setting(
plugin,
'vac_text',
request.journal,
create=True,
pretty='VAC Text',
)
return render_to_string(
'apc/vac_optin.html',
{'request': request, 'vac_text': vac_text.value if vac_text else ''},
)
elif mode == 'waiver':
waiver_text = setting_handler.get_plugin_setting(
plugin,
'waiver_text',
request.journal,
create=True,
pretty='Waiver Text',
)
return render_to_string(
'apc/waiver_info.html',
{'request': request, 'waiver_text': waiver_text.value},
)
else:
return ''
return ''


def waiver_application(context):
plugin = plugin_settings.get_self()
request = context['request']
article = context['article']

waiver_text = setting_handler.get_plugin_setting(
plugin,
'waiver_text',
request.journal,
create=True,
pretty='Waiver Text',
)
enable_waivers = setting_handler.get_plugin_setting(
author_contribution_mode = setting_handler.get_plugin_setting(
plugin,
'enable_waivers',
'author_contribution_mode',
request.journal,
create=True,
pretty='Enable Waivers',
pretty='Author Contribution Mode',
)
if enable_waivers.value == 'on':

if author_contribution_mode and author_contribution_mode.value == 'waiver':
waiver_text = setting_handler.get_plugin_setting(
plugin,
'waiver_text',
request.journal,
create=True,
pretty='Waiver Text',
)
return render_to_string(
'apc/article_waiver_app.html',
{
Expand All @@ -95,5 +109,4 @@ def waiver_application(context):
'article': article,
},
)
else:
return ''
return ''
60 changes: 60 additions & 0 deletions install/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,65 @@
"value": {
"default": "Article Waiver Application"
}
},
{
"group": {
"name": "plugin:apc"
},
"setting": {
"description": "Controls the author contribution mode: empty for none, 'waiver' for APC waivers, 'vac' for voluntary author contributions",
"is_translatable": false,
"name": "author_contribution_mode",
"pretty_name": "Author Contribution Mode",
"type": "char"
},
"value": {
"default": ""
}
},
{
"group": {
"name": "plugin:apc"
},
"setting": {
"description": "Controls the text displayed to authors on the submission review page when voluntary contributions are enabled",
"is_translatable": true,
"name": "vac_text",
"pretty_name": "VAC Text",
"type": "rich-text"
},
"value": {
"default": ""
}
},
{
"group": {
"name": "email"
},
"setting": {
"description": "Email sent to Billing Staffer when a voluntary author contribution is ready.",
"is_translatable": true,
"name": "apc_vac_contribution_ready",
"pretty_name": "APC Plugin: Voluntary Contribution Ready",
"type": "rich-text"
},
"value": {
"default": "<p>Dear {{ billing_staffer.staffer.full_name }},</p><p>This is a notification from {{ request.journal.name }}. Article #{{ article.pk }} '{{ article.title|safe }}' has been accepted and the author opted in to a voluntary contribution.</p><p>View the APC Dashboard {{ apc_index_value }}</p>"
}
},
{
"group": {
"name": "email_subject"
},
"setting": {
"description": "Email subject for email sent to Billing Staffer on voluntary contribution.",
"is_translatable": true,
"name": "subject_apc_vac_contribution_ready",
"pretty_name": "APC Plugin: Voluntary Contribution Ready Subject",
"type": "char"
},
"value": {
"default": "Voluntary Author Contribution Ready"
}
}
]
Loading