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

Basic support for corporate authors #1072

Merged
merged 1 commit into from Apr 5, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/press/models.py
Expand Up @@ -144,8 +144,9 @@ def journal_path_url(self, journal, path=None):
""" Returns a Journal's path mode url relative to its press """

_path = journal.code
if settings.DEBUG:
port = logic.get_current_request().get_port()
request = logic.get_current_request()
if settings.DEBUG and request:
port = request.get_port()
else:
port = None
if path is not None:
Expand Down
10 changes: 10 additions & 0 deletions src/submission/forms.py
Expand Up @@ -233,6 +233,15 @@ def __init__(self, *args, **kwargs):


class EditFrozenAuthor(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
instance = kwargs.pop("instance", None)
if instance:
del self.fields["is_corporate"]
if instance.is_corporate:
del self.fields["first_name"]
del self.fields["middle_name"]
del self.fields["last_name"]

class Meta:
model = models.FrozenAuthor
Expand All @@ -243,6 +252,7 @@ class Meta:
'institution',
'department',
'country',
'is_corporate',
)


Expand Down
20 changes: 20 additions & 0 deletions src/submission/migrations/0033_frozenauthor_is_corporate.py
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-04-03 16:20
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('submission', '0032_auto_20190304_0916'),
]

operations = [
migrations.AddField(
model_name='frozenauthor',
name='is_corporate',
field=models.BooleanField(default=False, help_text='If enabled, the institution and department fields will be used as the author full name'),
),
]
19 changes: 18 additions & 1 deletion src/submission/models.py
Expand Up @@ -1044,19 +1044,36 @@ class FrozenAuthor(models.Model):

order = models.PositiveIntegerField(default=1)

is_corporate = models.BooleanField(
default=False,
help_text="If enabled, the institution and department fields will "
"be used as the author full name",
)

class Meta:
ordering = ('order',)

def __str__(self):
return self.full_name()

def full_name(self):
if self.middle_name:
if self.is_corporate:
return self.corporate_name
elif self.middle_name:
return u"%s %s %s" % (self.first_name, self.middle_name, self.last_name)
else:
return u"%s %s" % (self.first_name, self.last_name)

@property
def corporate_name(self):
name = self.institution
if self.department:
name = "{}, {}".format(self.department, name)
return name

def citation_name(self):
if self.is_corporate:
return self.corporate_name
first_initial, middle_initial = '', ''

if self.middle_name:
Expand Down
2 changes: 1 addition & 1 deletion src/utils/logic.py
Expand Up @@ -137,6 +137,6 @@ def build_url(netloc, port=None, scheme=None, path="", query=None, fragment=""):
def get_current_request():
try:
return GlobalRequestMiddleware.get_current_request()
except KeyError:
except (KeyError, AttributeError):
return None

19 changes: 17 additions & 2 deletions src/utils/management/commands/reset_frozen_authors.py
Expand Up @@ -8,16 +8,31 @@ class Command(BaseCommand):

help = "Resets frozen author records with fresh data."

def add_arguments(self, parser):
"""Adds arguments to Django's management command-line parser.

:param parser: the parser to which the required arguments will be added
:return: None
"""
parser.add_argument("--hard",
action='store_true',
default=False,
help="Also deletes manually added frozen records"
)

def handle(self, *args, **options):
""" Resets all frozen author records with live profile records.
""" Resets frozen author records with live profile records.

:param args: None
:param options: None.
:return: None
"""
filters = {}
if options["hard"] is True:
filters["author__isnull"] = True

articles = submission_models.Article.objects.all()
submission_models.FrozenAuthor.objects.all().delete()
submission_models.FrozenAuthor.objects.filter(**filters).delete()

for article in articles:
for author in article.authors.all():
Expand Down