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
b11078e1
Commit
b11078e1
authored
7 years ago
by
Jorran de Wit
Browse files
Options
Downloads
Patches
Plain Diff
First working version of upgrade prospect
parent
ff846a4d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
partners/forms.py
+42
-4
42 additions, 4 deletions
partners/forms.py
partners/templates/partners/promote_prospartner.html
+0
-8
0 additions, 8 deletions
partners/templates/partners/promote_prospartner.html
partners/views.py
+9
-3
9 additions, 3 deletions
partners/views.py
with
51 additions
and
15 deletions
partners/forms.py
+
42
−
4
View file @
b11078e1
from
django
import
forms
from
django.contrib.auth.models
import
User
from
django.db.models
import
Q
from
captcha.fields
import
ReCaptchaField
from
django_countries
import
countries
...
...
@@ -62,11 +64,41 @@ class PromoteToContactForm(forms.ModelForm):
'
email
'
,
)
def
promote_contacts
(
self
,
partner
):
def
clean_email
(
self
):
"""
Check if email address is already used.
"""
email
=
self
.
cleaned_data
[
'
email
'
]
if
User
.
objects
.
filter
(
Q
(
email
=
email
)
|
Q
(
username
=
email
)).
exists
():
self
.
add_error
(
'
email
'
,
'
This emailadres has already been used.
'
)
return
email
def
promote_contact
(
self
,
partner
):
"""
Promote ProspectiveContact
'
s to Contact
'
s related to a certain Partner.
The status update after promotion is handled outside this method, in the Partner model.
"""
raise
NotImplemented
# How to handle empty instances?
if
self
.
errors
:
return
forms
.
ValidationError
# Is this a valid exception?
# Create a new User and Contact linked to the partner given
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
'
]
)
user
.
save
()
contact
=
Contact
(
user
=
user
,
title
=
self
.
cleaned_data
[
'
title
'
],
kind
=
self
.
cleaned_data
[
'
contact_types
'
]
)
contact
.
save
()
contact
.
partners
.
add
(
partner
)
return
contact
class
PromoteToContactFormset
(
forms
.
BaseModelFormSet
):
...
...
@@ -97,7 +129,8 @@ class PromoteToContactFormset(forms.BaseModelFormSet):
if
contact_type_keys
:
# Add error to all forms if not all CONTACT_TYPES are assigned
for
form
in
self
.
forms
:
form
.
add_error
(
'
contact_types
'
,
"
Not all contact types have been selected yet.
"
)
form
.
add_error
(
'
contact_types
'
,
(
"
Not all contact types have been
"
"
divided over the contacts yet.
"
))
def
save
(
self
,
*
args
,
**
kwargs
):
raise
DeprecationWarning
((
"
This formset is not meant to used with the default
"
...
...
@@ -107,7 +140,12 @@ class PromoteToContactFormset(forms.BaseModelFormSet):
"""
Promote ProspectiveContact
'
s to Contact
'
s related to a certain Partner.
"""
raise
NotImplemented
contacts
=
[]
for
form
in
self
.
forms
:
contacts
.
append
(
form
.
promote_contact
(
partner
))
partner
.
main_contact
=
contacts
[
0
]
partner
.
save
()
return
contacts
class
ProspectivePartnerForm
(
forms
.
ModelForm
):
...
...
This diff is collapsed.
Click to expand it.
partners/templates/partners/promote_prospartner.html
+
0
−
8
View file @
b11078e1
...
...
@@ -29,14 +29,6 @@
{{ form|bootstrap }}
{% endfor %}
{% for error in contact_formset.non_form_errors %}
<div
class=
"form-group row"
>
<div
class=
"alert alert-danger show"
>
<strong>
Form error
</strong>
·
{{error}}
</div>
</div>
{% endfor %}
<input
class=
"btn btn-primary"
type=
"submit"
value=
"Submit"
/>
</form>
</div>
...
...
This diff is collapsed.
Click to expand it.
partners/views.py
+
9
−
3
View file @
b11078e1
...
...
@@ -93,13 +93,19 @@ def promote_prospartner(request, prospartner_id):
pk
=
prospartner_id
)
form
=
PromoteToPartnerForm
(
request
.
POST
or
None
,
instance
=
prospartner
)
ContactModelFormset
=
modelformset_factory
(
ProspectiveContact
,
PromoteToContactForm
,
formset
=
PromoteToContactFormset
)
formset
=
PromoteToContactFormset
,
extra
=
0
)
contact_formset
=
ContactModelFormset
(
request
.
POST
or
None
,
queryset
=
prospartner
.
prospective_contacts
.
all
())
if
form
.
is_valid
()
and
contact_formset
.
is_valid
():
partner
,
institution
=
form
.
promote_to_partner
()
contact_formset
.
promote_contacts
(
partner
)
raise
NotImplemented
contacts
=
contact_formset
.
promote_contacts
(
partner
)
# partner.send_mail()
# contacts.send_mail()
messages
.
success
(
request
,
(
'
<h3>Upgraded Partner %s</h3>
'
'
%i contacts have received a validation mail.
'
)
%
(
str
(
partner
),
len
(
contacts
)))
return
redirect
(
reverse
(
'
partners:dashboard
'
))
context
=
{
'
form
'
:
form
,
'
contact_formset
'
:
contact_formset
}
return
render
(
request
,
'
partners/promote_prospartner.html
'
,
context
)
...
...
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