本文整理汇总了Python中geonode.layers.forms.LayerForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python LayerForm.is_valid方法的具体用法?Python LayerForm.is_valid怎么用?Python LayerForm.is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geonode.layers.forms.LayerForm
的用法示例。
在下文中一共展示了LayerForm.is_valid方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: layer_metadata
# 需要导入模块: from geonode.layers.forms import LayerForm [as 别名]
# 或者: from geonode.layers.forms.LayerForm import is_valid [as 别名]
def layer_metadata(request, layername, template='layers/layer_metadata.html'):
layer = _resolve_layer(
request,
layername,
'base.change_resourcebase_metadata',
_PERMISSION_MSG_METADATA)
layer_attribute_set = inlineformset_factory(
Layer,
Attribute,
extra=0,
form=LayerAttributeForm,
)
topic_category = layer.category
poc = layer.poc
metadata_author = layer.metadata_author
if request.method == "POST":
if layer.metadata_uploaded_preserve: # layer metadata cannot be edited
out = {
'success': False,
'errors': METADATA_UPLOADED_PRESERVE_ERROR
}
return HttpResponse(
json.dumps(out),
content_type='application/json',
status=400)
layer_form = LayerForm(request.POST, instance=layer, prefix="resource")
attribute_form = layer_attribute_set(
request.POST,
instance=layer,
prefix="layer_attribute_set",
queryset=Attribute.objects.order_by('display_order'))
category_form = CategoryForm(
request.POST,
prefix="category_choice_field",
initial=int(
request.POST["category_choice_field"]) if "category_choice_field" in request.POST else None)
else:
layer_form = LayerForm(instance=layer, prefix="resource")
attribute_form = layer_attribute_set(
instance=layer,
prefix="layer_attribute_set",
queryset=Attribute.objects.order_by('display_order'))
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
if request.method == "POST" and layer_form.is_valid(
) and attribute_form.is_valid() and category_form.is_valid():
new_poc = layer_form.cleaned_data['poc']
new_author = layer_form.cleaned_data['metadata_author']
new_keywords = layer_form.cleaned_data['keywords']
if new_poc is None:
if poc is None:
poc_form = ProfileForm(
request.POST,
prefix="poc",
instance=poc)
else:
poc_form = ProfileForm(request.POST, prefix="poc")
if poc_form.is_valid():
if len(poc_form.cleaned_data['profile']) == 0:
# FIXME use form.add_error in django > 1.7
errors = poc_form._errors.setdefault('profile', ErrorList())
errors.append(_('You must set a point of contact for this resource'))
poc = None
if poc_form.has_changed and poc_form.is_valid():
new_poc = poc_form.save()
if new_author is None:
if metadata_author is None:
author_form = ProfileForm(request.POST, prefix="author",
instance=metadata_author)
else:
author_form = ProfileForm(request.POST, prefix="author")
if author_form.is_valid():
if len(author_form.cleaned_data['profile']) == 0:
# FIXME use form.add_error in django > 1.7
errors = author_form._errors.setdefault('profile', ErrorList())
errors.append(_('You must set an author for this resource'))
metadata_author = None
if author_form.has_changed and author_form.is_valid():
new_author = author_form.save()
new_category = TopicCategory.objects.get(
id=category_form.cleaned_data['category_choice_field'])
for form in attribute_form.cleaned_data:
la = Attribute.objects.get(id=int(form['id'].id))
la.description = form["description"]
la.attribute_label = form["attribute_label"]
la.visible = form["visible"]
la.display_order = form["display_order"]
la.save()
if new_poc is not None and new_author is not None:
#.........这里部分代码省略.........
示例2: layer_metadata
# 需要导入模块: from geonode.layers.forms import LayerForm [as 别名]
# 或者: from geonode.layers.forms.LayerForm import is_valid [as 别名]
def layer_metadata(request, layername, template='layers/layer_metadata.html'):
layer = _resolve_layer(
request,
layername,
'base.change_resourcebase_metadata',
_PERMISSION_MSG_METADATA)
layer_attribute_set = inlineformset_factory(
Layer,
Attribute,
extra=0,
form=LayerAttributeForm,
)
topic_category = layer.category
poc = layer.poc
metadata_author = layer.metadata_author
if request.method == "POST":
layer_form = LayerForm(request.POST, instance=layer, prefix="resource")
attribute_form = layer_attribute_set(
request.POST,
instance=layer,
prefix="layer_attribute_set",
queryset=Attribute.objects.order_by('display_order'))
category_form = CategoryForm(
request.POST,
prefix="category_choice_field",
initial=int(
request.POST["category_choice_field"]) if "category_choice_field" in request.POST else None)
else:
layer_form = LayerForm(instance=layer, prefix="resource")
attribute_form = layer_attribute_set(
instance=layer,
prefix="layer_attribute_set",
queryset=Attribute.objects.order_by('display_order'))
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
if request.method == "POST" and layer_form.is_valid(
) and attribute_form.is_valid() and category_form.is_valid():
new_poc = layer_form.cleaned_data['poc']
new_author = layer_form.cleaned_data['metadata_author']
new_keywords = layer_form.cleaned_data['keywords']
if new_poc is None:
if poc is None:
poc_form = ProfileForm(
request.POST,
prefix="poc",
instance=poc)
else:
poc_form = ProfileForm(request.POST, prefix="poc")
if poc_form.has_changed and poc_form.is_valid():
new_poc = poc_form.save()
if new_author is None:
if metadata_author is None:
author_form = ProfileForm(request.POST, prefix="author",
instance=metadata_author)
else:
author_form = ProfileForm(request.POST, prefix="author")
if author_form.has_changed and author_form.is_valid():
new_author = author_form.save()
new_category = TopicCategory.objects.get(
id=category_form.cleaned_data['category_choice_field'])
for form in attribute_form.cleaned_data:
la = Attribute.objects.get(id=int(form['id'].id))
la.description = form["description"]
la.attribute_label = form["attribute_label"]
la.visible = form["visible"]
la.display_order = form["display_order"]
la.save()
if new_poc is not None and new_author is not None:
the_layer = layer_form.save()
the_layer.poc = new_poc
the_layer.metadata_author = new_author
the_layer.keywords.clear()
the_layer.keywords.add(*new_keywords)
the_layer.category = new_category
the_layer.save()
return HttpResponseRedirect(
reverse(
'layer_detail',
args=(
layer.service_typename,
)))
if poc is None:
poc_form = ProfileForm(instance=poc, prefix="poc")
else:
layer_form.fields['poc'].initial = poc.id
poc_form = ProfileForm(prefix="poc")
poc_form.hidden = True
if metadata_author is None:
author_form = ProfileForm(instance=metadata_author, prefix="author")
#.........这里部分代码省略.........
示例3: layer_metadata
# 需要导入模块: from geonode.layers.forms import LayerForm [as 别名]
# 或者: from geonode.layers.forms.LayerForm import is_valid [as 别名]
def layer_metadata(request, layername, template='layers/layer_metadata.html'):
layer = _resolve_layer(request, layername, 'layers.change_layer', _PERMISSION_MSG_METADATA)
layer_attribute_set = inlineformset_factory(Layer, Attribute, extra=0, form=LayerAttributeForm, )
poc = layer.poc
metadata_author = layer.metadata_author
ContactRole.objects.get(resource=layer, role=layer.poc_role)
ContactRole.objects.get(resource=layer, role=layer.metadata_author_role)
if request.method == "POST":
layer_form = LayerForm(request.POST, instance=layer, prefix="layer")
attribute_form = layer_attribute_set(request.POST, instance=layer, prefix="layer_attribute_set", queryset=Attribute.objects.order_by('display_order'))
else:
layer_form = LayerForm(instance=layer, prefix="layer")
attribute_form = layer_attribute_set(instance=layer, prefix="layer_attribute_set", queryset=Attribute.objects.order_by('display_order'))
if request.method == "POST" and layer_form.is_valid():
new_poc = layer_form.cleaned_data['poc']
new_author = layer_form.cleaned_data['metadata_author']
new_keywords = layer_form.cleaned_data['keywords']
if new_poc is None:
poc_form = ProfileForm(request.POST, prefix="poc")
if poc_form.has_changed and poc_form.is_valid():
new_poc = poc_form.save()
if new_author is None:
author_form = ProfileForm(request.POST, prefix="author")
if author_form.has_changed and author_form.is_valid():
new_author = author_form.save()
if attribute_form.is_valid():
for form in attribute_form.cleaned_data:
la = Attribute.objects.get(id=int(form['id'].id))
la.attribute_label = form["attribute_label"]
la.visible = form["visible"]
la.display_order = form["display_order"]
la.save()
if new_poc is not None and new_author is not None:
the_layer = layer_form.save()
the_layer.poc = new_poc
the_layer.metadata_author = new_author
the_layer.keywords.clear()
the_layer.keywords.add(*new_keywords)
return HttpResponseRedirect(reverse('layer_detail', args=(layer.typename,)))
if poc.user is None:
poc_form = ProfileForm(instance=poc, prefix="poc")
else:
layer_form.fields['poc'].initial = poc.id
poc_form = ProfileForm(prefix="poc")
poc_form.hidden=True
if metadata_author.user is None:
author_form = ProfileForm(instance=metadata_author, prefix="author")
else:
layer_form.fields['metadata_author'].initial = metadata_author.id
author_form = ProfileForm(prefix="author")
author_form.hidden=True
return render_to_response(template, RequestContext(request, {
"layer": layer,
"layer_form": layer_form,
"poc_form": poc_form,
"author_form": author_form,
"attribute_form": attribute_form,
}))
示例4: layer_metadata
# 需要导入模块: from geonode.layers.forms import LayerForm [as 别名]
# 或者: from geonode.layers.forms.LayerForm import is_valid [as 别名]
#.........这里部分代码省略.........
request_post = request.POST.copy() #^^
request_post['resource-date'] = icraf_dr_date_created #^^
request_post['resource-edition'] = icraf_dr_year.year_num #^^
layer_form = LayerForm(request_post, instance=layer, prefix="resource") #^^ replace request.POST
attribute_form = layer_attribute_set(
request.POST,
instance=layer,
prefix="layer_attribute_set",
queryset=Attribute.objects.order_by('display_order'))
category_form = CategoryForm(
request.POST,
prefix="category_choice_field",
initial=int(
request.POST["category_choice_field"]) if "category_choice_field" in request.POST else None)
else:
layer_form = LayerForm(instance=layer, prefix="resource")
attribute_form = layer_attribute_set(
instance=layer,
prefix="layer_attribute_set",
queryset=Attribute.objects.order_by('display_order'))
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
icraf_dr_categories = Category.objects.order_by('cat_num') #^^
icraf_dr_coverages = Coverage.objects.order_by('cov_num') #^^
icraf_dr_sources = Source.objects.order_by('src_num') #^^
icraf_dr_years = Year.objects.order_by('year_num') #^^
try: #^^
icraf_dr_main = Main.objects.get(layer=layer) #^^
except: #^^
icraf_dr_main = None #^^
if request.method == "POST" and layer_form.is_valid(
) and attribute_form.is_valid() and category_form.is_valid():
new_poc = layer_form.cleaned_data['poc']
new_author = layer_form.cleaned_data['metadata_author']
new_keywords = layer_form.cleaned_data['keywords']
if new_poc is None:
if poc is None:
poc_form = ProfileForm(
request.POST,
prefix="poc",
instance=poc)
else:
poc_form = ProfileForm(request.POST, prefix="poc")
if poc_form.is_valid():
if len(poc_form.cleaned_data['profile']) == 0:
# FIXME use form.add_error in django > 1.7
errors = poc_form._errors.setdefault('profile', ErrorList())
errors.append(_('You must set a point of contact for this resource'))
poc = None
if poc_form.has_changed and poc_form.is_valid():
new_poc = poc_form.save()
if new_author is None:
if metadata_author is None:
author_form = ProfileForm(request.POST, prefix="author",
instance=metadata_author)
else:
author_form = ProfileForm(request.POST, prefix="author")
if author_form.is_valid():
if len(author_form.cleaned_data['profile']) == 0:
# FIXME use form.add_error in django > 1.7
errors = author_form._errors.setdefault('profile', ErrorList())
示例5: layer_metadata
# 需要导入模块: from geonode.layers.forms import LayerForm [as 别名]
# 或者: from geonode.layers.forms.LayerForm import is_valid [as 别名]
def layer_metadata(request, layername, template='layers/layer_metadata.html'):
layer = _resolve_layer(
request,
layername,
'base.change_resourcebase_metadata',
_PERMISSION_MSG_METADATA)
layer_attribute_set = inlineformset_factory(
Layer,
Attribute,
extra=0,
form=LayerAttributeForm,
)
topic_category = layer.category
poc = layer.poc
metadata_author = layer.metadata_author
external_person = layer.external_person
if request.method == "POST":
layer_form = LayerForm(request.POST, instance=layer, prefix="resource")
lkd_project_form = LinkedProjectsForm(request.POST, instance=layer)
attribute_form = layer_attribute_set(
request.POST,
instance=layer,
prefix="layer_attribute_set",
queryset=Attribute.objects.order_by('display_order'))
category_form = CategoryForm(
request.POST,
prefix="category_choice_field",
initial=int(
request.POST["category_choice_field"]) if "category_choice_field" in request.POST else None)
else:
layer_form = LayerForm(instance=layer, prefix="resource")
lkd_project_form = LinkedProjectsForm(instance=layer)
attribute_form = layer_attribute_set(
instance=layer,
prefix="layer_attribute_set",
queryset=Attribute.objects.order_by('display_order'))
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
if request.method == "POST" and layer_form.is_valid(
) and attribute_form.is_valid() and category_form.is_valid() and lkd_project_form.is_valid():
new_poc = layer_form.cleaned_data['poc']
new_ep = layer_form.cleaned_data['external_person']
new_keywords = layer_form.cleaned_data['keywords']
if new_poc is None:
if poc is None:
poc_form = ExternalPersonForm(
request.POST,
prefix="poc",
instance=poc)
else:
poc_form = ExternalPersonForm(request.POST, prefix="poc")
if poc_form.has_changed and poc_form.is_valid():
new_poc = poc_form.save()
if new_ep is None:
if external_person is None:
ep_form = ExternalPersonForm(
request.POST,
prefix="external_person",
instance=external_person)
else:
ep_form = ExternalPersonForm(request.POST, prefix="external_person")
if ep_form.has_changed and ep_form.is_valid():
new_ep = ep_form.save()
# Permite clasificar las capas segun el tipo de fuente capturado
# esto ayuda la ejecuión del filtrado en la lista de capas.
st = layer_form.cleaned_data['source']
st_low = st.lower().replace(" ", "")
if st_low == '':
src_type = 'otro'
elif st_low == 'centrogeo':
src_type = 'centrogeo'
else:
src_type = 'externo'
new_category = TopicCategory.objects.get(
id=category_form.cleaned_data['category_choice_field'])
for form in attribute_form.cleaned_data:
la = Attribute.objects.get(id=int(form['id'].id))
la.description = form["description"]
la.attribute_type = form["attribute_type"]
la.visible = form["visible"]
la.display_order = form["display_order"]
la.save()
if new_poc is not None and new_ep is not None:
new_keywords = layer_form.cleaned_data['keywords']
layer.keywords.clear()
layer.keywords.add(*new_keywords)
the_layer = layer_form.save()
the_layer.poc = new_poc
the_layer.external_person = new_ep
lkd_project_form.save()
#.........这里部分代码省略.........
示例6: layer_metadata
# 需要导入模块: from geonode.layers.forms import LayerForm [as 别名]
# 或者: from geonode.layers.forms.LayerForm import is_valid [as 别名]
#.........这里部分代码省略.........
prefix="layer_attribute_set",
queryset=Attribute.objects.order_by('display_order'))
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
# Keywords from THESAURI management
layer_tkeywords = layer.tkeywords.all()
tkeywords_list = ''
lang = 'en' # TODO: use user's language
if layer_tkeywords and len(layer_tkeywords) > 0:
tkeywords_ids = layer_tkeywords.values_list('id', flat=True)
if hasattr(settings, 'THESAURI'):
for el in settings.THESAURI:
thesaurus_name = el['name']
try:
t = Thesaurus.objects.get(identifier=thesaurus_name)
for tk in t.thesaurus.filter(pk__in=tkeywords_ids):
tkl = tk.keyword.filter(lang=lang)
if len(tkl) > 0:
tkl_ids = ",".join(
map(str, tkl.values_list('id', flat=True)))
tkeywords_list += "," + \
tkl_ids if len(
tkeywords_list) > 0 else tkl_ids
except BaseException:
tb = traceback.format_exc()
logger.error(tb)
tkeywords_form = TKeywordForm(
prefix="tkeywords",
initial={'tkeywords': tkeywords_list})
if request.method == "POST" and layer_form.is_valid() and attribute_form.is_valid(
) and category_form.is_valid() and tkeywords_form.is_valid():
new_poc = layer_form.cleaned_data['poc']
new_author = layer_form.cleaned_data['metadata_author']
if new_poc is None:
if poc is None:
poc_form = ProfileForm(
request.POST,
prefix="poc",
instance=poc)
else:
poc_form = ProfileForm(request.POST, prefix="poc")
if poc_form.is_valid():
if len(poc_form.cleaned_data['profile']) == 0:
# FIXME use form.add_error in django > 1.7
errors = poc_form._errors.setdefault(
'profile', ErrorList())
errors.append(
_('You must set a point of contact for this resource'))
poc = None
if poc_form.has_changed and poc_form.is_valid():
new_poc = poc_form.save()
if new_author is None:
if metadata_author is None:
author_form = ProfileForm(request.POST, prefix="author",
instance=metadata_author)
else:
author_form = ProfileForm(request.POST, prefix="author")
if author_form.is_valid():
if len(author_form.cleaned_data['profile']) == 0:
# FIXME use form.add_error in django > 1.7