Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LDV Specification
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
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
ASTRON SDC
LDV Specification
Commits
7e8ef465
Commit
7e8ef465
authored
1 year ago
by
Klaas Kliffen
Browse files
Options
Downloads
Patches
Plain Diff
Small formatting fixes.
parent
1e90d1ac
No related branches found
Branches containing commit
No related tags found
1 merge request
!104
Propagate extra fields form group into WorkSpecifications
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ldvspec/lofardata/views/group/template.py
+59
-58
59 additions, 58 deletions
ldvspec/lofardata/views/group/template.py
with
59 additions
and
58 deletions
ldvspec/lofardata/views/group/template.py
+
59
−
58
View file @
7e8ef465
from
django.contrib.auth.mixins
import
LoginRequiredMixin
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.views.generic
import
UpdateView
from
lofardata.forms
import
GroupForm
from
lofardata.models
import
ATDBProcessingSite
,
Group
,
WorkSpecification
from
lofardata.view_helpers
import
filters_preprocessor
from
lofardata.view_helpers.specification
import
(
create_work_specifications_for_group
,
propagate_group_properties_to_workspecification
,
split_obs_ids_string
,
)
from
rest_framework.reverse
import
reverse_lazy
class
GroupCreateUpdateView
(
LoginRequiredMixin
,
UpdateView
):
template_name
=
"
lofardata/group/create_update.html
"
model
=
Group
form_class
=
GroupForm
def
get_object
(
self
,
queryset
=
None
):
if
self
.
kwargs
.
__len__
()
==
0
or
self
.
kwargs
[
"
pk
"
]
is
None
:
group
=
Group
()
else
:
group
=
Group
.
objects
.
get
(
pk
=
self
.
kwargs
[
"
pk
"
])
return
group
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
().
get_context_data
(
**
kwargs
)
processing_sites
=
list
(
ATDBProcessingSite
.
objects
.
values
(
"
name
"
,
"
url
"
))
context
[
"
processing_sites
"
]
=
processing_sites
context
[
"
single_processing_site
"
]
=
processing_sites
[
0
][
'
name
'
]
if
len
(
processing_sites
)
==
1
else
None
try
:
group
=
Group
.
objects
.
get
(
pk
=
context
[
"
object
"
].
pk
)
except
ObjectDoesNotExist
:
group
=
None
# Excludes obs_id, since groups handle these differently
context
[
"
filters
"
]
=
filters_preprocessor
.
preprocess
(
group
,
exclude
=
[
"
obs_id
"
])
return
context
def
form_valid
(
self
,
form
):
is_new
=
not
form
.
instance
.
pk
group
=
form
.
save
()
if
is_new
:
obs_ids
=
split_obs_ids_string
(
form
.
data
.
get
(
"
obs_ids
"
))
batch_size
=
form
.
data
.
get
(
"
batch_size
"
)
create_work_specifications_for_group
(
group
,
self
.
request
.
user
,
obs_ids
,
batch_size
)
else
:
workspecifications_in_group
=
WorkSpecification
.
objects
.
filter
(
group
=
group
)
for
workspecification
in
workspecifications_in_group
:
propagate_group_properties_to_workspecification
(
group
,
workspecification
)
workspecification
.
save
()
return
super
().
form_valid
(
form
)
def
get_success_url
(
self
,
**
kwargs
):
return
reverse_lazy
(
"
index
"
)
from
django.contrib.auth.mixins
import
LoginRequiredMixin
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.views.generic
import
UpdateView
from
lofardata.forms
import
GroupForm
from
lofardata.models
import
ATDBProcessingSite
,
Group
,
WorkSpecification
from
lofardata.view_helpers
import
filters_preprocessor
from
lofardata.view_helpers.specification
import
(
create_work_specifications_for_group
,
propagate_group_properties_to_workspecification
,
split_obs_ids_string
,
)
from
rest_framework.reverse
import
reverse_lazy
class
GroupCreateUpdateView
(
LoginRequiredMixin
,
UpdateView
):
template_name
=
"
lofardata/group/create_update.html
"
model
=
Group
form_class
=
GroupForm
def
get_object
(
self
,
queryset
=
None
):
if
self
.
kwargs
.
__len__
()
==
0
or
self
.
kwargs
[
"
pk
"
]
is
None
:
group
=
Group
()
else
:
group
=
Group
.
objects
.
get
(
pk
=
self
.
kwargs
[
"
pk
"
])
return
group
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
().
get_context_data
(
**
kwargs
)
processing_sites
=
list
(
ATDBProcessingSite
.
objects
.
values
(
"
name
"
,
"
url
"
))
context
[
"
processing_sites
"
]
=
processing_sites
context
[
"
single_processing_site
"
]
=
processing_sites
[
0
][
'
name
'
]
if
len
(
processing_sites
)
==
1
else
None
try
:
group
=
Group
.
objects
.
get
(
pk
=
context
[
"
object
"
].
pk
)
except
ObjectDoesNotExist
:
group
=
None
# Excludes obs_id, since groups handle these differently
context
[
"
filters
"
]
=
filters_preprocessor
.
preprocess
(
group
,
exclude
=
[
"
obs_id
"
])
return
context
def
form_valid
(
self
,
form
):
is_new
=
not
form
.
instance
.
pk
group
=
form
.
save
()
if
is_new
:
obs_ids
=
split_obs_ids_string
(
form
.
data
.
get
(
"
obs_ids
"
))
batch_size
=
form
.
data
.
get
(
"
batch_size
"
)
create_work_specifications_for_group
(
group
,
self
.
request
.
user
,
obs_ids
,
batch_size
)
else
:
workspecifications_in_group
=
WorkSpecification
.
objects
.
filter
(
group
=
group
)
for
workspecification
in
workspecifications_in_group
:
propagate_group_properties_to_workspecification
(
group
,
workspecification
)
workspecification
.
save
()
return
super
().
form_valid
(
form
)
def
get_success_url
(
self
,
**
kwargs
):
return
reverse_lazy
(
"
index
"
)
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