-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
forms.py
109 lines (95 loc) · 4.46 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# coding=utf-8
""""
Eleprofile module forms.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the Mozilla Public License 2.0.
"""
__author__ = '[email protected]'
__date__ = '2020-07-13'
__copyright__ = 'Copyright 2015 - 2020, Gis3w'
from django.forms.models import ModelForm
from django.utils.translation import ugettext_lazy as _
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, HTML, Row, Field, Hidden
# from usersmanage.forms import G3WACLForm
from usersmanage.utils import crispyBoxACL, userHasGroups
from usersmanage.configs import G3W_EDITOR1
from core.mixins.forms import G3WRequestFormMixin, G3WFormMixin
from qdjango.models import Layer
from .models import EleProProject, EleProDTM
class ProjectForm(G3WFormMixin, G3WRequestFormMixin, ModelForm):
"""
Form for EleProProject model.
"""
class Meta:
model = EleProProject
fields = '__all__'
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_tag = False
self.helper.layout = Layout(
Div(
Div(
Div(
Div(
HTML("<h3 class='box-title'><i class='fa fa-file'></i> {}</h3>".format(
_('Project'))),
css_class='box-header with-border'
),
Div(
'project',
Field('note', css_class='wys5'),
css_class='box-body',
),
css_class='box box-success'
),
css_class='col-md-12'
),
css_class='row'
),
)
class DTMForm(G3WFormMixin, G3WRequestFormMixin, ModelForm):
"""
Form for EleProProject model.
"""
class Meta:
model = EleProDTM
fields = '__all__'
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# build queryset for DTM layer and path layers
self.fields['dtm_layer'].queryset = Layer.objects.filter(
project_id=EleProProject.objects.get(pk=kwargs['initial']['elepro_project']).project_id,
layer_type__in=('raster', 'gdal')
)
self.fields['layers'].queryset = Layer.objects.filter(
project_id=EleProProject.objects.get(pk=kwargs['initial']['elepro_project']).project_id,
geometrytype__in=('LineString', 'MultiLineString')
)
self.helper = FormHelper(self)
self.helper.form_tag = False
self.helper.layout = Layout(
Div(
Div(
Div(
Div(
HTML("<h3 class='box-title'><i class='fa fa-file'></i> {}</h3>".format(
_('DTM Layer and pth layers'))),
css_class='box-header with-border'
),
Div(
Field('elepro_project', type='hidden'),
'dtm_layer',
'dtm_delta',
'layers',
Field('note', css_class='wys5'),
css_class='box-body',
),
css_class='box box-success'
),
css_class='col-md-12'
),
css_class='row'
),
)