Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
ots
hypha
Commits
9af71a98
Commit
9af71a98
authored
7 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
Allow applicants to post comments
parent
d5739703
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
opentech/apply/activity/views.py
+2
-21
2 additions, 21 deletions
opentech/apply/activity/views.py
opentech/apply/funds/views.py
+7
-21
7 additions, 21 deletions
opentech/apply/funds/views.py
opentech/apply/utils/views.py
+42
-1
42 additions, 1 deletion
opentech/apply/utils/views.py
with
51 additions
and
43 deletions
opentech/apply/activity/views.py
+
2
−
21
View file @
9af71a98
from
django.utils.decorators
import
method_decorator
from
django.views.generic
import
CreateView
,
View
from
django.views.generic
import
CreateView
from
opentech.apply.u
sers.decorators
import
staff_required
from
opentech.apply.u
tils.views
import
DelegatedViewMixin
from
.forms
import
CommentForm
from
.models
import
Activity
,
COMMENT
...
...
@@ -30,24 +29,6 @@ class ActivityContextMixin:
return
super
().
get_context_data
(
**
extra
,
**
kwargs
)
@method_decorator
(
staff_required
,
name
=
'
dispatch
'
)
class
DelegatedViewMixin
(
View
):
"""
For use on create views accepting forms from another view
"""
def
get_template_names
(
self
):
return
self
.
kwargs
[
'
template_names
'
]
def
get_context_data
(
self
,
**
kwargs
):
# Use the previous context but override the validated form
form
=
kwargs
.
pop
(
'
form
'
)
kwargs
.
update
(
self
.
kwargs
[
'
context
'
])
kwargs
.
update
(
**
{
self
.
context_name
:
form
})
return
super
().
get_context_data
(
**
kwargs
)
@classmethod
def
contribute_form
(
cls
,
submission
):
return
cls
.
context_name
,
cls
.
form_class
(
instance
=
submission
)
class
CommentFormView
(
DelegatedViewMixin
,
CreateView
):
form_class
=
CommentForm
context_name
=
'
comment_form
'
...
...
This diff is collapsed.
Click to expand it.
opentech/apply/funds/views.py
+
7
−
21
View file @
9af71a98
...
...
@@ -2,7 +2,7 @@ from django import forms
from
django.core.exceptions
import
PermissionDenied
from
django.template.response
import
TemplateResponse
from
django.utils.decorators
import
method_decorator
from
django.views.generic
import
DetailView
,
UpdateView
from
django.views.generic
import
UpdateView
from
django_filters.views
import
FilterView
from
django_tables2.views
import
SingleTableMixin
...
...
@@ -15,7 +15,7 @@ from opentech.apply.activity.views import (
)
from
opentech.apply.activity.models
import
Activity
from
opentech.apply.users.decorators
import
staff_required
from
opentech.apply.utils.views
import
ViewDispatcher
from
opentech.apply.utils.views
import
DelegateableView
,
ViewDispatcher
from
.forms
import
ProgressSubmissionForm
,
UpdateSubmissionLeadForm
from
.models
import
ApplicationSubmission
...
...
@@ -92,8 +92,7 @@ class UpdateLeadView(DelegatedViewMixin, UpdateView):
return
response
@method_decorator
(
staff_required
,
name
=
'
dispatch
'
)
class
AdminSubmissionDetailView
(
ActivityContextMixin
,
DetailView
):
class
AdminSubmissionDetailView
(
ActivityContextMixin
,
DelegateableView
):
model
=
ApplicationSubmission
form_views
=
{
'
progress
'
:
ProgressSubmissionView
,
...
...
@@ -102,30 +101,17 @@ class AdminSubmissionDetailView(ActivityContextMixin, DetailView):
}
def
get_context_data
(
self
,
**
kwargs
):
forms
=
dict
(
form_view
.
contribute_form
(
self
.
object
)
for
form_view
in
self
.
form_views
.
values
())
return
super
().
get_context_data
(
other_submissions
=
self
.
model
.
objects
.
filter
(
user
=
self
.
object
.
user
).
exclude
(
id
=
self
.
object
.
id
),
**
forms
,
**
kwargs
,
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
kwargs
[
'
submission
'
]
=
self
.
object
# Information to pretend we originate from this view
kwargs
[
'
template_names
'
]
=
self
.
get_template_names
()
kwargs
[
'
context
'
]
=
self
.
get_context_data
()
form_submitted
=
request
.
POST
[
'
form-submitted
'
].
lower
()
view
=
self
.
form_views
[
form_submitted
].
as_view
()
return
view
(
request
,
*
args
,
**
kwargs
)
class
ApplicantSubmissionDetailView
(
DetailView
):
class
ApplicantSubmissionDetailView
(
ActivityContextMixin
,
DelegateableView
):
model
=
ApplicationSubmission
form_views
=
{
'
comment
'
:
CommentFormView
,
}
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
if
self
.
get_object
().
user
!=
request
.
user
:
...
...
This diff is collapsed.
Click to expand it.
opentech/apply/utils/views.py
+
42
−
1
View file @
9af71a98
from
django.contrib.auth.decorators
import
login_required
from
django.utils.decorators
import
method_decorator
from
django.views.generic
import
View
from
django.views.generic
import
DetailView
,
View
from
opentech.apply.users.groups
import
STAFF_GROUP_NAME
...
...
@@ -17,3 +17,44 @@ class ViewDispatcher(View):
view
=
self
.
applicant_view
return
view
.
as_view
()(
request
,
*
args
,
**
kwargs
)
class
DelegateableView
(
DetailView
):
"""
A view which passes its context to child form views to allow them to post to the same URL
"""
def
get_context_data
(
self
,
**
kwargs
):
forms
=
dict
(
form_view
.
contribute_form
(
self
.
object
)
for
form_view
in
self
.
form_views
.
values
())
return
super
().
get_context_data
(
**
forms
,
**
kwargs
,
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
kwargs
[
'
submission
'
]
=
self
.
object
# Information to pretend we originate from this view
kwargs
[
'
template_names
'
]
=
self
.
get_template_names
()
kwargs
[
'
context
'
]
=
self
.
get_context_data
()
form_submitted
=
request
.
POST
[
'
form-submitted
'
].
lower
()
view
=
self
.
form_views
[
form_submitted
].
as_view
()
return
view
(
request
,
*
args
,
**
kwargs
)
class
DelegatedViewMixin
(
View
):
"""
For use on create views accepting forms from another view
"""
def
get_template_names
(
self
):
return
self
.
kwargs
[
'
template_names
'
]
def
get_context_data
(
self
,
**
kwargs
):
# Use the previous context but override the validated form
form
=
kwargs
.
pop
(
'
form
'
)
kwargs
.
update
(
self
.
kwargs
[
'
context
'
])
kwargs
.
update
(
**
{
self
.
context_name
:
form
})
return
super
().
get_context_data
(
**
kwargs
)
@classmethod
def
contribute_form
(
cls
,
submission
):
return
cls
.
context_name
,
cls
.
form_class
(
instance
=
submission
)
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