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
729355df
Commit
729355df
authored
6 years ago
by
Jean-Sébastien Caux
Browse files
Options
Downloads
Patches
Plain Diff
Partial work on organizations.Contact create facilities
parent
c24029ca
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
organizations/forms.py
+90
-0
90 additions, 0 deletions
organizations/forms.py
organizations/views.py
+15
-0
15 additions, 0 deletions
organizations/views.py
with
105 additions
and
0 deletions
organizations/forms.py
+
90
−
0
View file @
729355df
...
@@ -12,6 +12,96 @@ from django.db import transaction
...
@@ -12,6 +12,96 @@ from django.db import transaction
from
.constants
import
ROLE_KINDS
from
.constants
import
ROLE_KINDS
from
.models
import
Contact
from
.models
import
Contact
from
scipost.constants
import
TITLE_CHOICES
class
ContactForm
(
forms
.
ModelForm
):
"""
This Contact form is mainly used for editing Contact instances.
"""
class
Meta
:
model
=
Contact
class
NewContactForm
(
ContactForm
):
"""
This Contact form is used to create new Contact instances, as it will also handle
possible sending and activation of User instances coming with the new Contact.
"""
title
=
forms
.
ChoiceField
(
choices
=
TITLE_CHOICES
,
label
=
'
Title
'
)
first_name
=
forms
.
CharField
()
last_name
=
forms
.
CharField
()
email
=
forms
.
CharField
()
existing_user
=
None
def
__init__
(
self
,
*
args
,
**
kwargs
):
"""
Organization is a required argument to tell the formset which Organization
the Contact is being edited for in the current form.
"""
self
.
organization
=
kwargs
.
pop
(
'
organization
'
)
super
().
__init__
(
*
args
,
**
kwargs
)
def
clean_email
(
self
):
"""
Check if User already is known in the system.
"""
email
=
self
.
cleaned_data
[
'
email
'
]
try
:
self
.
existing_user
=
User
.
objects
.
get
(
email
=
email
)
if
not
self
.
data
.
get
(
'
confirm_use_existing
'
,
''
)
==
'
on
'
:
# Do not give error if user wants to use existing User
self
.
add_error
(
'
email
'
,
'
This User is already registered.
'
)
self
.
fields
[
'
confirm_use_existing
'
]
=
forms
.
BooleanField
(
required
=
False
,
initial
=
False
,
label
=
'
Use the existing user instead: %s %s
'
%
(
self
.
existing_user
.
first_name
,
self
.
existing_user
.
last_name
))
except
User
.
DoesNotExist
:
pass
return
email
@transaction.atomic
def
save
(
self
,
current_user
,
commit
=
True
):
"""
If existing user is found, link it to the Organization.
"""
if
self
.
existing_user
and
self
.
data
.
get
(
'
confirm_use_existing
'
,
''
)
==
'
on
'
:
# Do not create new Contact
try
:
# Link Contact to new Organization
contact
=
self
.
existing_user
.
org_contact
contact
.
organizations
.
add
(
self
.
organization
)
except
Contact
.
DoesNotExist
:
# Not yet a 'Contact-User'
contact
=
super
().
save
(
commit
=
False
)
contact
.
title
=
self
.
existing_user
.
org_contact
.
title
contact
.
user
=
self
.
existing_user
contact
.
save
()
contact
.
organizations
.
add
(
self
.
organization
)
return
contact
# Create complete new Account (User + Contact)
user
=
User
(
first_name
=
self
.
cleaned_data
[
'
first_name
'
],
last_name
=
self
.
cleaned_data
[
'
last_name
'
],
email
=
self
.
cleaned_data
[
'
email
'
],
username
=
self
.
cleaned_data
[
'
email
'
],
is_active
=
False
,
)
user
.
save
()
contact
=
Contact
(
user
=
user
,
title
=
self
.
cleaned_data
[
'
title
'
]
)
contact
.
generate_key
()
contact
.
save
()
contact
.
organizations
.
add
(
self
.
organization
)
# TODOdeprecPartners Send email for activation
# PartnerUtils.load({'contact': contact})
# PartnerUtils.email_contact_new_for_activation(current_user=current_user)
return
contact
class
ContactActivationForm
(
forms
.
ModelForm
):
class
ContactActivationForm
(
forms
.
ModelForm
):
class
Meta
:
class
Meta
:
...
...
This diff is collapsed.
Click to expand it.
organizations/views.py
+
15
−
0
View file @
729355df
...
@@ -102,6 +102,21 @@ class OrganizationDetailView(DetailView):
...
@@ -102,6 +102,21 @@ class OrganizationDetailView(DetailView):
return
queryset
return
queryset
@permission_required
(
'
scipost.can_manage_SPB
'
,
return_403
=
True
)
def
organization_add_contact
(
request
,
organization_id
):
organization
=
get_object_or_404
(
Organization
,
id
=
organization_id
)
form
=
NewContactForm
(
request
.
POST
or
None
,
organization
=
organization
)
if
form
.
is_valid
():
contact
=
form
.
save
(
current_user
=
request
.
user
)
messages
.
success
(
request
,
'
<h3>Created contact: %s</h3>Email has been sent.
'
%
str
(
contact
))
return
redirect
(
reverse
(
'
organizations:dashboard
'
))
context
=
{
'
organization
'
:
organization
,
'
form
'
:
form
}
return
render
(
request
,
'
organizations/organization_add_contact.html
'
,
context
)
def
activate_account
(
request
,
activation_key
):
def
activate_account
(
request
,
activation_key
):
contact
=
get_object_or_404
(
Contact
,
user__is_active
=
False
,
contact
=
get_object_or_404
(
Contact
,
user__is_active
=
False
,
...
...
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