SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SciPost
SciPost
Commits
bdbd8406
Commit
bdbd8406
authored
6 years ago
by
Jean-Sébastien Caux
Browse files
Options
Downloads
Patches
Plain Diff
Add has_contributor property to Profile
parent
55beb5d3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
profiles/forms.py
+15
-0
15 additions, 0 deletions
profiles/forms.py
profiles/models.py
+10
-0
10 additions, 0 deletions
profiles/models.py
with
25 additions
and
0 deletions
profiles/forms.py
+
15
−
0
View file @
bdbd8406
...
...
@@ -81,6 +81,21 @@ class ProfileMergeForm(forms.Form):
to_merge
=
forms
.
IntegerField
()
to_merge_into
=
forms
.
IntegerField
()
def
clean
(
self
):
"""
To merge Profiles, they must be distinct, and it must not be the
case that they both are associated to a Contributor instance
(which would mean two Contributor objects for the same person).
"""
data
=
super
().
clean
()
if
self
.
cleaned_data
[
'
to_merge
'
]
==
self
.
cleaned_data
[
'
to_merge_into
'
]:
self
.
add_error
(
None
,
'
A Profile cannot be merged into itself.
'
)
profile_to_merge
=
get_object_or_404
(
Profile
,
pk
=
self
.
cleaned_data
[
'
to_merge
'
])
profile_to_merge_into
=
get_object_or_404
(
Profile
,
pk
=
self
.
cleaned_data
[
'
to_merge_into
'
])
if
profile_to_merge
.
has_contributor
and
profile_to_merge_into
.
has_contributor
:
self
.
add_error
(
None
,
'
Each of these two Profiles has a Contributor. Cannot merge.
'
)
return
data
def
save
(
self
):
"""
Perform the actual merge: save all data from to-be-deleted profile
...
...
This diff is collapsed.
Click to expand it.
profiles/models.py
+
10
−
0
View file @
bdbd8406
...
...
@@ -10,6 +10,7 @@ from scipost.behaviors import orcid_validator
from
scipost.constants
import
(
TITLE_CHOICES
,
SCIPOST_DISCIPLINES
,
DISCIPLINE_PHYSICS
,
SCIPOST_SUBJECT_AREAS
)
from
scipost.fields
import
ChoiceArrayField
from
scipost.models
import
Contributor
from
comments.models
import
Comment
from
journals.models
import
Publication
,
PublicationAuthorsTable
...
...
@@ -73,6 +74,15 @@ class Profile(models.Model):
def
email
(
self
):
return
getattr
(
self
.
emails
.
filter
(
primary
=
True
).
first
(),
'
email
'
,
''
)
@property
def
has_contributor
(
self
):
has_contributor
=
False
try
:
has_contributor
=
(
self
.
contributor
is
not
None
)
except
Contributor
.
DoesNotExist
:
pass
return
has_contributor
def
get_absolute_url
(
self
):
return
reverse
(
'
profiles:profile_detail
'
,
kwargs
=
{
'
pk
'
:
self
.
id
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment