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

Support for the Research Organization Registry (ROR) #4483

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
88 changes: 85 additions & 3 deletions src/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ class SettingAdmin(admin.ModelAdmin):
class AccountAdmin(UserAdmin):
"""Displays Account objects in the Django admin interface."""
list_display = ('id', 'email', 'orcid', 'first_name', 'middle_name',
'last_name', 'institution', '_roles_in', 'last_login')
'last_name', '_roles_in', 'last_login')
list_display_links = ('id', 'email')
list_filter = ('accountrole__journal',
'repositoryrole__repository__short_name',
'is_active', 'is_staff', 'is_admin', 'is_superuser',
'last_login')
search_fields = ('id', 'username', 'email', 'first_name', 'middle_name',
'last_name', 'orcid', 'institution',
'last_name', 'orcid',
'biography', 'signature')

fieldsets = UserAdmin.fieldsets + (
(None, {'fields': (
'name_prefix', 'middle_name', 'orcid',
'institution', 'department', 'country', 'twitter',
'twitter',
'linkedin', 'facebook', 'github', 'website', 'biography', 'enable_public_profile',
'signature', 'profile_image', 'interest', "preferred_timezone",
)}),
Expand Down Expand Up @@ -398,6 +398,84 @@ class AccessRequestAdmin(admin.ModelAdmin):
date_hierarchy = ('requested')


class OrganizationAdmin(admin.ModelAdmin):
list_display = ('pk', 'ror', '_ror_display', '_custom_label',
'website', '_locations', 'ror_status')
list_display_links = ('pk', 'ror')
list_filter = ('ror_status', 'locations__country')
search_fields = ('pk', 'ror_display__value', 'custom_label__value', 'labels__value',
'aliases__value', 'acronyms__value', 'website', 'ror')
raw_id_fields = ('locations', )

def _ror_display(self, obj):
return obj.ror_display if obj and obj.ror_display else ''

def _locations(self, obj):
return '; '.join([str(l) for l in obj.locations.all()]) if obj else ''

def _custom_label(self, obj):
return obj.custom_label if obj and obj.custom_label else ''


class OrganizationNameAdmin(admin.ModelAdmin):
list_display = ('pk', 'value', 'language')
list_display_links = ('pk', 'value')
search_fields = ('pk', 'value')
raw_id_fields = ('ror_display_for', 'custom_label_for',
'label_for', 'alias_for', 'acronym_for')

def _ror_display(self, obj):
return obj.ror_display if obj and obj.ror_display else ''

def _locations(self, obj):
return '; '.join([str(l) for l in obj.locations.all()]) if obj else ''

def _custom_label(self, obj):
return obj.custom_label if obj and obj.custom_label else ''


class LocationAdmin(admin.ModelAdmin):
list_display = ('pk', 'name', 'country', 'geonames_id')
list_display_links = ('pk', 'name')
list_filter = ('country',)
search_fields = ('pk', 'name', 'country__code', 'country__name',
'geonames_id')


class AffiliationAdmin(admin.ModelAdmin):
list_display = ('pk', '_person', 'organization',
'title', 'department', 'start', 'end')
list_display_links = ('pk', '_person')
list_filter = ('start', 'end', 'organization__locations__country')
search_fields = (
'pk',
'title',
'department',
'organization__ror_display__value',
'organization__custom_label__value',
'organization__labels__value',
'organization__aliases__value',
'organization__acronyms__value',
'account__first_name',
'account__last_name',
'account__email',
'frozen_author__first_name',
'frozen_author__last_name',
'frozen_author__frozen_email',
'preprint_author__account__first_name',
'preprint_author__account__last_name',
'preprint_author__account__email',
)
raw_id_fields = ('account', 'frozen_author',
'preprint_author', 'organization')

def _person(self, obj):
if obj:
return obj.account or obj.frozen_author or obj.preprint_author
else:
return ''


admin_list = [
(models.AccountRole, AccountRoleAdmin),
(models.Account, AccountAdmin),
Expand Down Expand Up @@ -427,6 +505,10 @@ class AccessRequestAdmin(admin.ModelAdmin):
(models.Contacts, ContactsAdmin),
(models.Contact, ContactAdmin),
(models.AccessRequest, AccessRequestAdmin),
(models.Organization, OrganizationAdmin),
(models.OrganizationName, OrganizationNameAdmin),
(models.Location, LocationAdmin),
(models.Affiliation, AffiliationAdmin),
]

[admin.site.register(*t) for t in admin_list]
1 change: 1 addition & 0 deletions src/core/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
AccessRequestForm,
AccountRoleForm,
AdminUserForm,
AffiliationForm,
ArticleMetaImageForm,
CBVFacetForm,
ConfirmableForm,
Expand Down
19 changes: 17 additions & 2 deletions src/core/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class RegistrationForm(forms.ModelForm, CaptchaForm):
class Meta:
model = models.Account
fields = ('email', 'salutation', 'first_name', 'middle_name',
'last_name', 'department', 'institution', 'country', 'orcid',)
'last_name', 'orcid',)
widgets = {'orcid': forms.HiddenInput() }

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -532,7 +532,7 @@ def __init__(self, *args, **kwargs):
class QuickUserForm(forms.ModelForm):
class Meta:
model = models.Account
fields = ('email', 'salutation', 'first_name', 'last_name', 'institution',)
fields = ('email', 'salutation', 'first_name', 'last_name',)


class LoginForm(CaptchaForm):
Expand Down Expand Up @@ -940,3 +940,18 @@ class AccountRoleForm(forms.ModelForm):
class Meta:
model = models.AccountRole
fields = '__all__'


class AffiliationForm(forms.ModelForm):

class Meta:
model = models.Affiliation
fields = '__all__'
widgets = {
'account': forms.HiddenInput,
'frozen_author': forms.HiddenInput,
'preprint_author': forms.HiddenInput,
'organization': forms.HiddenInput,
'start': HTMLDateInput,
'end': HTMLDateInput,
}
32 changes: 32 additions & 0 deletions src/core/include_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,38 @@
re_path(r'^manager/user/(?P<user_id>\d+)/edit/$', core_views.user_edit, name='core_user_edit'),
re_path(r'^manager/user/(?P<user_id>\d+)/history/$', core_views.user_history, name='core_user_history'),

## Affiliations
re_path(
r'^profile/organization/search/$',
core_views.OrganizationListView.as_view(),
name='core_organization_search'
),
re_path(
r'^profile/organization_name/create/$',
core_views.OrganizationNameCreateView.as_view(),
name='core_organization_name_create'
),
re_path(
r'^profile/organization_name/(?P<organization_name_id>\d+)/update/$',
core_views.OrganizationNameUpdateView.as_view(),
name='core_organization_name_update'
),
re_path(
r'^profile/organization/(?P<organization_id>\d+)/affiliation/create/$',
core_views.AffiliationCreateView.as_view(),
name='core_affiliation_create'
),
re_path(
r'^profile/affiliation/(?P<affiliation_id>\d+)/update/$',
core_views.AffiliationUpdateView.as_view(),
name='core_affiliation_update'
),
re_path(
r'^profile/affiliation/(?P<affiliation_id>\d+)/delete/$',
core_views.AffiliationDeleteView.as_view(),
name='core_affiliation_delete'
),

# Templates
re_path(r'^manager/templates/$', core_views.email_templates, name='core_email_templates'),

Expand Down
2 changes: 1 addition & 1 deletion src/core/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def check_for_bad_login_attempts(request):
time = timezone.now() - timedelta(minutes=10)

attempts = models.LoginAttempt.objects.filter(user_agent=user_agent, ip_address=ip_address, timestamp__gte=time)
print(time, attempts.count())
logger.info(time, attempts.count())
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this message be more explicit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes probably, though I'm just removing the noisy print statement here, not changing this feature on this branch.

return attempts.count()


Expand Down
Loading