本文整理汇总了Python中geonode.layers.forms.LayerForm类的典型用法代码示例。如果您正苦于以下问题:Python LayerForm类的具体用法?Python LayerForm怎么用?Python LayerForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LayerForm类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: layer_metadata
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
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
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
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":
icraf_dr_category =Category.objects.get(pk=request.POST['icraf_dr_category']) #^^
icraf_dr_coverage =Coverage.objects.get(pk=request.POST['icraf_dr_coverage']) #^^
icraf_dr_source =Source.objects.get(pk=request.POST['icraf_dr_source']) #^^
icraf_dr_year =Year.objects.get(pk=request.POST['icraf_dr_year']) #^^
icraf_dr_date_created = request.POST['icraf_dr_date_created'] #^^
icraf_dr_date_published = request.POST['icraf_dr_date_published'] #^^
icraf_dr_date_revised = request.POST['icraf_dr_date_revised'] #^^
#^^ validate date format
if (len(icraf_dr_date_created)): #^^
try: #^^
parse(icraf_dr_date_created) #^^
except ValueError: #^^
icraf_dr_date_created = None #^^
else: #^^
icraf_dr_date_created = None #^^
if (len(icraf_dr_date_published)): #^^
try: #^^
parse(icraf_dr_date_published) #^^
except ValueError: #^^
icraf_dr_date_published = None #^^
else: #^^
icraf_dr_date_published = None #^^
if (len(icraf_dr_date_revised)): #^^
try: #^^
parse(icraf_dr_date_revised) #^^
except ValueError: #^^
icraf_dr_date_revised = None #^^
else: #^^
icraf_dr_date_revised = None #^^
try: #^^
main_topic_category = TopicCategory(id=request.POST['category_choice_field']) #^^
except: #^^
main_topic_category = None #^^
main_regions = ','.join(request.POST.getlist('resource-regions')) #^^ save as comma separated ids
main_defaults = { #^^
'category': icraf_dr_category, #^^
'coverage': icraf_dr_coverage, #^^
'source': icraf_dr_source, #^^
'year': icraf_dr_year, #^^
'topic_category': main_topic_category, #^^
'regions': main_regions, #^^
'date_created': icraf_dr_date_created, #^^
'date_published': icraf_dr_date_published, #^^
'date_revised': icraf_dr_date_revised #^^
} #^^
main, main_created = Main.objects.get_or_create(layer=layer, defaults=main_defaults) #^^
if not main_created: #^^
main.category = icraf_dr_category #^^
main.coverage = icraf_dr_coverage #^^
main.source = icraf_dr_source #^^
main.year = icraf_dr_year #^^
main.topic_category = main_topic_category #^^
main.regions = main_regions #^^
main.date_created = icraf_dr_date_created #^^
main.date_published = icraf_dr_date_published #^^
main.date_revised = icraf_dr_date_revised #^^
main.save() #^^
#^^ override resource-date with icraf_dr_date_created
#^^ override resource-edition with icraf_dr_year
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(
#.........这里部分代码省略.........
示例5: layer_metadata
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
def layer_metadata(
request,
layername,
template='layers/layer_metadata.html',
ajax=True):
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
# assert False, str(layer_bbox)
config = layer.attribute_config()
# Add required parameters for GXP lazy-loading
layer_bbox = layer.bbox
bbox = [float(coord) for coord in list(layer_bbox[0:4])]
config["srs"] = getattr(settings, 'DEFAULT_MAP_CRS', 'EPSG:900913')
config["bbox"] = bbox if config["srs"] != 'EPSG:900913' \
else llbbox_to_mercator([float(coord) for coord in bbox])
config["title"] = layer.title
config["queryable"] = True
if layer.storeType == "remoteStore":
service = layer.service
source_params = {
"ptype": service.ptype,
"remote": True,
"url": service.base_url,
"name": service.name}
maplayer = GXPLayer(
name=layer.alternate,
ows_url=layer.ows_url,
layer_params=json.dumps(config),
source_params=json.dumps(source_params))
else:
maplayer = GXPLayer(
name=layer.alternate,
ows_url=layer.ows_url,
layer_params=json.dumps(config))
# Update count for popularity ranking,
# but do not includes admins or resource owners
if request.user != layer.owner and not request.user.is_superuser:
Layer.objects.filter(
id=layer.id).update(popular_count=F('popular_count') + 1)
# center/zoom don't matter; the viewer will center on the layer bounds
map_obj = GXPMap(
projection=getattr(
settings,
'DEFAULT_MAP_CRS',
'EPSG:900913'))
NON_WMS_BASE_LAYERS = [
la for la in default_map_config(request)[1] if la.ows_url is None]
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)
tkeywords_form = TKeywordForm(
request.POST,
prefix="tkeywords")
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)
#.........这里部分代码省略.........