Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ippidb-web
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
iPPIDB
ippidb-web
Commits
8cc2539d
Commit
8cc2539d
authored
7 years ago
by
Hervé MENAGER
Browse files
Options
Downloads
Patches
Plain Diff
modify PDB ID form to validate format and PDB entry existence
Former-commit-id: fb0ff3428b6b55c4e73c58b186cf72d48b83f4d4
parent
10c6f0d7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ippisite/ippidb/forms.py
+12
-1
12 additions, 1 deletion
ippisite/ippidb/forms.py
with
12 additions
and
1 deletion
ippisite/ippidb/forms.py
+
12
−
1
View file @
8cc2539d
from
django.forms
import
ModelForm
,
modelformset_factory
,
formset_factory
from
django
import
forms
from
django.db
import
models
from
django.core.exceptions
import
ValidationError
from
django.core.validators
import
RegexValidator
from
.models
import
Bibliography
,
Protein
,
ProteinDomainComplex
,
Ppi
,
PpiComplex
from
.ws
import
pdb_entry_exists
class
IdForm
(
ModelForm
):
class
Meta
:
...
...
@@ -23,8 +27,15 @@ class BibliographyForm(ModelForm):
'
journal_name
'
:
forms
.
TextInput
(
attrs
=
{
'
readonly
'
:
'
readonly
'
,
'
class
'
:
'
readonly
'
}),
}
def
validate_pdb_exists
(
value
):
if
not
(
pdb_entry_exists
(
value
)):
raise
ValidationError
(
'
PDB entry not found: %(value)s
'
,
params
=
{
'
value
'
:
value
},
code
=
'
invalid
'
)
class
PDBForm
(
forms
.
Form
):
pdb_id
=
forms
.
CharField
(
label
=
"
PDB ID
"
,
max_length
=
4
,
widget
=
forms
.
TextInput
(
attrs
=
{
'
placeholder
'
:
'
e.g 4HHB
'
}))
pdb_id
=
forms
.
CharField
(
label
=
"
PDB ID
"
,
max_length
=
4
,
widget
=
forms
.
TextInput
(
attrs
=
{
'
placeholder
'
:
'
e.g 4HHB
'
}),
required
=
True
,
validators
=
[
RegexValidator
(
'
^[0-9][a-zA-Z0-9]{3}$
'
,
message
=
'
PDB ID must be 1 numeric + 3 alphanumeric characters
'
),
validate_pdb_exists
])
PDBFormSet
=
formset_factory
(
PDBForm
)
formset
=
PDBFormSet
()
...
...
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