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
2137dde9
Commit
2137dde9
authored
7 years ago
by
Todd Dembrey
Browse files
Options
Downloads
Patches
Plain Diff
Provide a way to define fields on the model which are required
parent
031f4240
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
opentech/apply/funds/blocks.py
+38
-1
38 additions, 1 deletion
opentech/apply/funds/blocks.py
opentech/apply/stream_forms/blocks.py
+1
-1
1 addition, 1 deletion
opentech/apply/stream_forms/blocks.py
with
39 additions
and
2 deletions
opentech/apply/funds/blocks.py
+
38
−
1
View file @
2137dde9
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.text
import
mark_safe
from
opentech.apply.stream_forms.blocks
import
FormFieldsBlock
from
wagtail.wagtailcore.blocks
import
StaticBlock
from
opentech.apply.stream_forms.blocks
import
FormFieldsBlock
,
FormFieldBlock
from
opentech.apply.categories.blocks
import
CategoryQuestionBlock
from
opentech.apply.categories.blocks
import
CategoryQuestionBlock
class
CustomFormFieldsBlock
(
FormFieldsBlock
):
class
CustomFormFieldsBlock
(
FormFieldsBlock
):
category
=
CategoryQuestionBlock
(
group
=
_
(
'
Custom
'
))
category
=
CategoryQuestionBlock
(
group
=
_
(
'
Custom
'
))
def
__init__
(
self
,
*
args
,
**
kwargs
):
child_blocks
=
[(
block
.
name
,
block
(
group
=
_
(
'
Required
'
)))
for
block
in
MustIncludeFieldBlock
.
__subclasses__
()]
super
().
__init__
(
child_blocks
,
*
args
,
**
kwargs
)
class
MustIncludeStatic
(
StaticBlock
):
def
__init__
(
self
,
*
args
,
description
=
''
,
**
kwargs
):
self
.
description
=
description
super
().
__init__
(
*
args
,
**
kwargs
)
class
Meta
:
admin_text
=
'
Much be included in the form once.
'
def
render_form
(
self
,
*
args
,
**
kwargs
):
form
=
super
().
render_form
(
*
args
,
**
kwargs
)
form
=
'
<br>
'
.
join
([
self
.
description
,
form
])
return
mark_safe
(
form
)
class
MustIncludeFieldBlock
(
FormFieldBlock
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
info_name
=
f
'
{
self
.
name
}
_field
'
child_blocks
=
[(
info_name
,
MustIncludeStatic
(
description
=
self
.
description
))]
super
().
__init__
(
child_blocks
,
*
args
,
**
kwargs
)
class
TitleBlock
(
MustIncludeFieldBlock
):
name
=
'
title
'
description
=
'
The title of the project
'
class
ValueBlock
(
MustIncludeFieldBlock
):
name
=
'
value
'
description
=
'
The value of the project
'
This diff is collapsed.
Click to expand it.
opentech/apply/stream_forms/blocks.py
+
1
−
1
View file @
2137dde9
...
@@ -8,7 +8,7 @@ from django.utils.translation import ugettext_lazy as _
...
@@ -8,7 +8,7 @@ from django.utils.translation import ugettext_lazy as _
from
unidecode
import
unidecode
from
unidecode
import
unidecode
from
wagtail.wagtailcore.blocks
import
(
from
wagtail.wagtailcore.blocks
import
(
StructBlock
,
TextBlock
,
CharBlock
,
BooleanBlock
,
ListBlock
,
StreamBlock
,
StructBlock
,
TextBlock
,
CharBlock
,
BooleanBlock
,
ListBlock
,
StreamBlock
,
DateBlock
,
TimeBlock
,
DateTimeBlock
,
ChoiceBlock
,
RichTextBlock
,
DateBlock
,
TimeBlock
,
DateTimeBlock
,
ChoiceBlock
,
RichTextBlock
,
StaticBlock
)
)
...
...
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