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
adb087d5
Commit
adb087d5
authored
2 years ago
by
sandeepsajan0
Browse files
Options
Downloads
Patches
Plain Diff
Limit single file field block for PAF
parent
6c2a3834
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
hypha/apply/projects/admin.py
+3
-0
3 additions, 0 deletions
hypha/apply/projects/admin.py
hypha/apply/projects/admin_views.py
+37
-0
37 additions, 0 deletions
hypha/apply/projects/admin_views.py
with
40 additions
and
0 deletions
hypha/apply/projects/admin.py
+
3
−
0
View file @
adb087d5
from
wagtail.contrib.modeladmin.options
import
ModelAdmin
,
ModelAdminGroup
from
.admin_views
import
CreateProjectApprovalFormView
,
EditProjectApprovalFormView
from
.models
import
DocumentCategory
,
ProjectApprovalForm
...
...
@@ -13,6 +14,8 @@ class ProjectApprovalFormAdmin(ModelAdmin):
model
=
ProjectApprovalForm
menu_icon
=
'
form
'
list_display
=
(
'
name
'
,
'
used_by
'
,)
create_view_class
=
CreateProjectApprovalFormView
edit_view_class
=
EditProjectApprovalFormView
def
used_by
(
self
,
obj
):
rows
=
list
()
...
...
This diff is collapsed.
Click to expand it.
hypha/apply/projects/admin_views.py
0 → 100644
+
37
−
0
View file @
adb087d5
from
wagtail.contrib.modeladmin.views
import
CreateView
,
EditView
from
hypha.apply.utils.blocks
import
show_admin_form_error_messages
class
CreateProjectApprovalFormView
(
CreateView
):
def
get_form
(
self
):
"""
Overriding this method to disable the single file block option from Project Approval Form.
Set 0 as max_number of single file can be added to make single file block option unavailable or disable.
"""
form
=
super
(
CreateProjectApprovalFormView
,
self
).
get_form
()
form
.
fields
[
'
form_fields
'
].
block
.
meta
.
block_counts
=
{
'
file
'
:
{
'
min_num
'
:
0
,
'
max_num
'
:
0
}}
return
form
def
form_invalid
(
self
,
form
):
show_admin_form_error_messages
(
self
.
request
,
form
)
return
self
.
render_to_response
(
self
.
get_context_data
(
form
=
form
))
class
EditProjectApprovalFormView
(
EditView
):
def
get_form
(
self
):
"""
Overriding this method to disable the single file block option from Project Approval Form.
Calculating the number of Single file blocks that exist in the instance already.
And set that count as max_number of single file block can be added to make single file option disable.
"""
form
=
super
(
EditProjectApprovalFormView
,
self
).
get_form
()
single_file_count
=
sum
(
1
for
block
in
self
.
get_instance
().
form_fields
.
raw_data
if
block
[
'
type
'
]
==
'
file
'
)
form
.
fields
[
'
form_fields
'
].
block
.
meta
.
block_counts
=
{
'
file
'
:
{
'
min_num
'
:
0
,
'
max_num
'
:
single_file_count
}}
return
form
def
form_invalid
(
self
,
form
):
show_admin_form_error_messages
(
self
.
request
,
form
)
return
self
.
render_to_response
(
self
.
get_context_data
(
form
=
form
))
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