本文整理汇总了Python中geonode.maps.forms.MapForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python MapForm.is_valid方法的具体用法?Python MapForm.is_valid怎么用?Python MapForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geonode.maps.forms.MapForm
的用法示例。
在下文中一共展示了MapForm.is_valid方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: map_metadata
# 需要导入模块: from geonode.maps.forms import MapForm [as 别名]
# 或者: from geonode.maps.forms.MapForm import is_valid [as 别名]
def map_metadata(request, mapid, template='maps/map_metadata.html'):
'''
The view that displays a form for
editing map metadata
'''
map_obj = _resolve_map(request, mapid, msg=_PERMISSION_MSG_METADATA)
if request.method == "POST":
# Change metadata, return to map info page
map_form = MapForm(request.POST, instance=map_obj, prefix="map")
if map_form.is_valid():
map_obj = map_form.save(commit=False)
if map_form.cleaned_data["keywords"]:
map_obj.keywords.add(*map_form.cleaned_data["keywords"])
else:
map_obj.keywords.clear()
map_obj.save()
return HttpResponseRedirect(reverse('map_detail', args=(map_obj.id,)))
else:
# Show form
map_form = MapForm(instance=map_obj, prefix="map")
return render_to_response(template, RequestContext(request, {
"map": map_obj,
"map_form": map_form
}))
示例2: map_metadata
# 需要导入模块: from geonode.maps.forms import MapForm [as 别名]
# 或者: from geonode.maps.forms.MapForm import is_valid [as 别名]
def map_metadata(request, mapid, template='maps/map_metadata.html'):
map_obj = _resolve_map(request, mapid, 'base.view_resourcebase', _PERMISSION_MSG_VIEW)
poc = map_obj.poc
metadata_author = map_obj.metadata_author
topic_category = map_obj.category
if request.method == "POST":
map_form = MapForm(request.POST, instance=map_obj, prefix="resource")
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:
map_form = MapForm(instance=map_obj, prefix="resource")
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
if request.method == "POST" and map_form.is_valid(
) and category_form.is_valid():
new_poc = map_form.cleaned_data['poc']
new_author = map_form.cleaned_data['metadata_author']
new_keywords = map_form.cleaned_data['keywords']
new_title = strip_tags(map_form.cleaned_data['title'])
new_abstract = strip_tags(map_form.cleaned_data['abstract'])
new_category = TopicCategory.objects.get(
id=category_form.cleaned_data['category_choice_field'])
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()
if new_poc is not None and new_author is not None:
the_map = map_form.save()
the_map.poc = new_poc
the_map.metadata_author = new_author
the_map.title = new_title
the_map.abstract = new_abstract
the_map.save()
the_map.keywords.clear()
the_map.keywords.add(*new_keywords)
the_map.category = new_category
the_map.save()
return HttpResponseRedirect(
reverse(
'map_detail',
args=(
map_obj.id,
)))
if poc is None:
poc_form = ProfileForm(request.POST, prefix="poc")
else:
if poc is None:
poc_form = ProfileForm(instance=poc, prefix="poc")
else:
map_form.fields['poc'].initial = poc.id
poc_form = ProfileForm(prefix="poc")
poc_form.hidden = True
if metadata_author is None:
author_form = ProfileForm(request.POST, prefix="author")
else:
if metadata_author is None:
author_form = ProfileForm(
instance=metadata_author,
prefix="author")
else:
map_form.fields['metadata_author'].initial = metadata_author.id
author_form = ProfileForm(prefix="author")
author_form.hidden = True
return render_to_response(template, RequestContext(request, {
"map": map_obj,
"map_form": map_form,
"poc_form": poc_form,
"author_form": author_form,
"category_form": category_form,
}))
示例3: map_metadata
# 需要导入模块: from geonode.maps.forms import MapForm [as 别名]
# 或者: from geonode.maps.forms.MapForm import is_valid [as 别名]
def map_metadata(
request,
mapid,
template='maps/map_metadata.html',
ajax=True):
map_obj = _resolve_map(
request,
mapid,
'base.change_resourcebase_metadata',
_PERMISSION_MSG_VIEW)
poc = map_obj.poc
metadata_author = map_obj.metadata_author
topic_category = map_obj.category
if request.method == "POST":
map_form = MapForm(request.POST, instance=map_obj, prefix="resource")
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:
map_form = MapForm(instance=map_obj, prefix="resource")
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
if request.method == "POST" and map_form.is_valid(
) and category_form.is_valid():
new_poc = map_form.cleaned_data['poc']
new_author = map_form.cleaned_data['metadata_author']
new_keywords = map_form.cleaned_data['keywords']
new_regions = map_form.cleaned_data['regions']
new_title = strip_tags(map_form.cleaned_data['title'])
new_abstract = strip_tags(map_form.cleaned_data['abstract'])
new_category = TopicCategory.objects.get(
id=category_form.cleaned_data['category_choice_field'])
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()
the_map = map_form.instance
if new_poc is not None and new_author is not None:
the_map.poc = new_poc
the_map.metadata_author = new_author
the_map.title = new_title
the_map.abstract = new_abstract
if new_keywords:
the_map.keywords.clear()
the_map.keywords.add(*new_keywords)
if new_regions:
the_map.regions.clear()
the_map.regions.add(*new_regions)
the_map.category = new_category
the_map.save()
if getattr(settings, 'SLACK_ENABLED', False):
try:
from geonode.contrib.slack.utils import build_slack_message_map, send_slack_messages
send_slack_messages(
build_slack_message_map(
"map_edit", the_map))
except BaseException:
logger.error("Could not send slack message for modified map.")
if not ajax:
return HttpResponseRedirect(
reverse(
'map_detail',
args=(
map_obj.id,
)))
message = map_obj.id
return HttpResponse(json.dumps({'message': message}))
# - POST Request Ends here -
# Request.GET
if poc is None:
poc_form = ProfileForm(request.POST, prefix="poc")
else:
#.........这里部分代码省略.........
示例4: map_metadata
# 需要导入模块: from geonode.maps.forms import MapForm [as 别名]
# 或者: from geonode.maps.forms.MapForm import is_valid [as 别名]
def map_metadata(request, mapid, template="maps/map_metadata.html"):
map_obj = _resolve_map(request, mapid, msg=_PERMISSION_MSG_METADATA)
poc = map_obj.poc
metadata_author = map_obj.metadata_author
if request.method == "POST":
map_form = MapForm(request.POST, instance=map_obj, prefix="resource")
else:
map_form = MapForm(instance=map_obj, prefix="resource")
if request.method == "POST" and map_form.is_valid():
new_poc = map_form.cleaned_data["poc"]
new_author = map_form.cleaned_data["metadata_author"]
new_keywords = map_form.cleaned_data["keywords"]
new_title = strip_tags(map_form.cleaned_data["title"])
new_abstract = strip_tags(map_form.cleaned_data["abstract"])
if new_poc is None:
if poc.user 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.user 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()
if new_poc is not None and new_author is not None:
the_map = map_form.save()
the_map.poc = new_poc
the_map.metadata_author = new_author
the_map.title = new_title
the_map.abstract = new_abstract
the_map.save()
the_map.keywords.clear()
the_map.keywords.add(*new_keywords)
return HttpResponseRedirect(reverse("map_detail", args=(map_obj.id,)))
if poc.user is None:
poc_form = ProfileForm(instance=poc, prefix="poc")
else:
map_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:
map_form.fields["metadata_author"].initial = metadata_author.id
author_form = ProfileForm(prefix="author")
author_form.hidden = True
return render_to_response(
template,
RequestContext(
request, {"map": map_obj, "map_form": map_form, "poc_form": poc_form, "author_form": author_form}
),
)
示例5: map_metadata
# 需要导入模块: from geonode.maps.forms import MapForm [as 别名]
# 或者: from geonode.maps.forms.MapForm import is_valid [as 别名]
def map_metadata(request, mapid, template='maps/map_metadata.html'):
map_obj = _resolve_map(request, mapid, 'base.change_resourcebase_metadata', _PERMISSION_MSG_VIEW)
poc = map_obj.poc
metadata_author = map_obj.metadata_author
topic_category = map_obj.category
if request.method == "POST":
map_form = MapForm(request.POST, instance=map_obj, prefix="resource")
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:
map_form = MapForm(instance=map_obj, prefix="resource")
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
if request.method == "POST" and map_form.is_valid(
) and category_form.is_valid():
new_poc = map_form.cleaned_data['poc']
new_author = map_form.cleaned_data['metadata_author']
new_keywords = map_form.cleaned_data['keywords']
new_title = strip_tags(map_form.cleaned_data['title'])
new_abstract = strip_tags(map_form.cleaned_data['abstract'])
new_category = TopicCategory.objects.get(
id=category_form.cleaned_data['category_choice_field'])
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()
if new_poc is not None and new_author is not None:
the_map = map_form.save()
the_map.poc = new_poc
the_map.metadata_author = new_author
the_map.title = new_title
the_map.abstract = new_abstract
the_map.save()
the_map.keywords.clear()
the_map.keywords.add(*new_keywords)
the_map.category = new_category
the_map.save()
if getattr(settings, 'SLACK_ENABLED', False):
try:
from geonode.contrib.slack.utils import build_slack_message_map, send_slack_messages
send_slack_messages(build_slack_message_map("map_edit", the_map))
except:
print "Could not send slack message for modified map."
return HttpResponseRedirect(
reverse(
'map_detail',
args=(
map_obj.id,
)))
if poc is None:
poc_form = ProfileForm(request.POST, prefix="poc")
else:
if poc is None:
poc_form = ProfileForm(instance=poc, prefix="poc")
else:
map_form.fields['poc'].initial = poc.id
poc_form = ProfileForm(prefix="poc")
poc_form.hidden = True
if metadata_author is None:
author_form = ProfileForm(request.POST, prefix="author")
else:
if metadata_author is None:
author_form = ProfileForm(
instance=metadata_author,
prefix="author")
else:
map_form.fields['metadata_author'].initial = metadata_author.id
author_form = ProfileForm(prefix="author")
author_form.hidden = True
#.........这里部分代码省略.........