-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.py
executable file
·64 lines (50 loc) · 2.44 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
# -*- coding: utf-8 -*-
#########################################################################
#
# Copyright (C) 2012 OpenPlans
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
import os
import tempfile
import taggit
from django import forms
from django.utils import simplejson as json
from django.utils.translation import ugettext_lazy as _
from geonode.datamanager.models import DataConnection
from geonode.people.models import Profile
from geonode.datamanager.enumerations import DATAUPDATE_FREQ
from geonode.datamanager.utils import getFormhubColumns
class DataConnectionCreateForm(forms.ModelForm):
formhub_password = forms.CharField(widget=forms.PasswordInput(), required=True)
class Meta:
model = DataConnection
exclude = ('owner', 'creation_date', 'lastedit_date', 'update_freq', 'lat_column','lon_column','layer_name','geocode_column', 'geocode_country')
class DataConnectionEditForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
dataconnection = kwargs.pop('dataconnection')
super(DataConnectionEditForm, self).__init__(*args, **kwargs)
#get the dataconnection
CHOICES = getFormhubColumns(dataconnection)
self.fields['lat_column'].choices = CHOICES
self.fields['lon_column'].choices = CHOICES
self.fields['geocode_column'].choices = CHOICES
lat_column = forms.ChoiceField(choices=[])
lon_column = forms.ChoiceField(choices=[])
geocode_column = forms.ChoiceField(choices=[], required=False)
update_freq = forms.ChoiceField(choices=DATAUPDATE_FREQ)
class Meta:
model = DataConnection
exclude = ('owner', 'creation_date', 'lastedit_date','layer_name', 'formhub_url', 'formhub_username', 'formhub_password',)