本文整理汇总了Python中geonode.base.forms.CategoryForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python CategoryForm.is_valid方法的具体用法?Python CategoryForm.is_valid怎么用?Python CategoryForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geonode.base.forms.CategoryForm
的用法示例。
在下文中一共展示了CategoryForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: document_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm import is_valid [as 别名]
def document_metadata(
request,
docid,
template='v2/document_metadata.html'):
document = None
try:
document = _resolve_document(
request,
docid,
'base.change_resourcebase_metadata',
_PERMISSION_MSG_METADATA)
except Http404:
return HttpResponse(
loader.render_to_string(
'404.html', RequestContext(
request, {
})), status=404)
except PermissionDenied:
return HttpResponse(
loader.render_to_string(
'401.html', RequestContext(
request, {
'error_message': _("You are not allowed to edit this document.")})), status=403)
if document is None:
return HttpResponse(
'An unknown error has occured.',
mimetype="text/plain",
status=401
)
else:
poc = document.poc
metadata_author = document.metadata_author
topic_category = document.category
if request.method == "POST":
document_form = DocumentForm(
request.POST,
instance=document,
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:
document_form = DocumentForm(instance=document, prefix="resource")
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
if request.method == "POST" and document_form.is_valid(
) and category_form.is_valid():
new_poc = document_form.cleaned_data['poc']
new_author = document_form.cleaned_data['metadata_author']
new_keywords = document_form.cleaned_data['keywords']
new_category = TopicCategory.objects.get(
id=category_form.cleaned_data['category_choice_field'])
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 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:
# rename document file if any title fields changed
title_fields = ['category', 'regions', 'datasource', 'title', 'subtitle', 'papersize', 'date', 'edition']
title_fields_changed = [i for e in title_fields for i in document_form.changed_data if e == i]
if title_fields_changed:
doc_file_path = os.path.dirname(document.doc_file.name)
new_filename = '%s.%s' % (
get_valid_filename('_'.join([
'afg',
new_category.identifier,
'-'.join([r.code for r in document_form.cleaned_data['regions']]),
document_form.cleaned_data['datasource'],
slugify(document_form.cleaned_data['title']),
slugify(document_form.cleaned_data['subtitle']),
document_form.cleaned_data['papersize'],
document_form.cleaned_data['date'].strftime('%Y-%m-%d'),
#.........这里部分代码省略.........
示例2: map_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm 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:
#.........这里部分代码省略.........
示例3: project_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm import is_valid [as 别名]
def project_metadata(
request,
docid,
template='documents/project_metadata.html'):
document = None
try:
document = _resolve_document_geo(
request,
docid,
'base.change_resourcebase',
_PERMISSION_MSG_METADATA)
except Http404:
return HttpResponse(
loader.render_to_string(
'404.html', RequestContext(
request, {
})), status=404)
except PermissionDenied:
return HttpResponse(
loader.render_to_string(
'401.html', RequestContext(
request, {
'error_message': _("You are not allowed to edit this document.")})), status=403)
if document is None:
return HttpResponse(
'An unknown error has occured.',
mimetype="text/plain",
status=401
)
else:
poc = document.poc
print poc
metadata_author = document.metadata_author
topic_category = document.category
if request.method == "POST":
print "Entre a if"
document_form = ProjectForm(
request.POST,
instance=document,
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:
print "Entre a else"
document_form = ProjectForm(instance=document, prefix="resource")
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
if request.method == "POST" and document_form.is_valid(
) and category_form.is_valid():
new_poc = document_form.cleaned_data['poc']
new_author = document_form.cleaned_data['metadata_author']
new_keywords = document_form.cleaned_data['keywords']
new_category = TopicCategory.objects.get(
id=category_form.cleaned_data['category_choice_field'])
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 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_document = document_form.save()
the_document.poc = new_poc
the_document.metadata_author = new_author
the_document.keywords.add(*new_keywords)
the_document.category = new_category
the_document.save()
return HttpResponseRedirect(
reverse(
'project_detail',
args=(
document.id,
)))
#.........这里部分代码省略.........
示例4: layer_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm 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: map_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm 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,
}))
示例6: map_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm import is_valid [as 别名]
def map_metadata(request, mapid, template="maps/cread_map_metadata.html"):
map_obj = _resolve_map(request, mapid, "base.change_resourcebase_metadata", _PERMISSION_MSG_VIEW)
cmapqs = CReadResource.objects.filter(resource=map_obj)
if len(cmapqs) == 0:
logger.info("cread_resource does not exist for map %r", map_obj)
cread_resource = None
else:
logger.debug("cread_resource found for map %r (%d)", map_obj, len(cmapqs))
cread_resource = cmapqs[0]
poc = map_obj.poc
metadata_author = map_obj.metadata_author
topic_category = map_obj.category
cread_subcategory = cread_resource.subcategory if cread_resource else None
if request.method == "POST":
baseinfo_form = CReadBaseInfoForm(request.POST, prefix="baseinfo")
map_form = CReadMapForm(
# 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,
)
cread_subcategory_form = CReadSubCategoryForm(
request.POST,
prefix="cread_subcategory_choice_field",
initial=int(request.POST["cread_subcategory_choice_field"])
if "cread_subcategory_choice_field" in request.POST
else None,
)
else:
baseinfo_form = CReadBaseInfoForm(
prefix="baseinfo", initial={"title": map_obj.title, "abstract": map_obj.abstract}
)
map_form = CReadMapForm(instance=map_obj, prefix="resource")
category_form = CategoryForm(
prefix="category_choice_field", initial=topic_category.id if topic_category else None
)
cread_subcategory_form = CReadSubCategoryForm(
prefix="cread_subcategory_choice_field", initial=cread_subcategory.id if cread_subcategory else None
)
if (
request.method == "POST"
and baseinfo_form.is_valid()
and map_form.is_valid()
and cread_subcategory_form.is_valid()
):
new_title = strip_tags(baseinfo_form.cleaned_data["title"])
new_abstract = strip_tags(baseinfo_form.cleaned_data["abstract"])
new_poc = map_form.cleaned_data["poc"]
new_author = map_form.cleaned_data["metadata_author"]
new_keywords = map_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()
# CRead category
# note: call to is_valid is needed to compute the cleaned data
if cread_subcategory_form.is_valid():
logger.info("Checking CReadLayer record %r ", cread_subcategory_form.is_valid())
cread_subcat_id = cread_subcategory_form.cleaned_data["cread_subcategory_choice_field"]
new_creadsubcategory = CReadSubCategory.objects.get(id=cread_subcat_id)
new_creadcategory = new_creadsubcategory.category
logger.debug(
"Selected cread cat/subcat: %s : %s / %s",
new_creadcategory.identifier,
new_creadcategory.name,
new_creadsubcategory.identifier,
)
if cread_resource:
logger.info("Update CReadResource record")
else:
logger.info("Create new CReadResource record")
cread_resource = CReadResource()
cread_resource.resource = map_obj
#.........这里部分代码省略.........
示例7: layer_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm import is_valid [as 别名]
def layer_metadata(request, layername, template='upload/layer_upload_metadata.html'):
layer = _resolve_layer(
request,
layername,
'base.change_resourcebase_metadata',
_PERMISSION_MSG_METADATA)
topic_category = layer.category
poc = layer.poc or layer.owner
metadata_author = layer.metadata_author
if request.method == "POST":
layer_form = UploadLayerForm(request.POST, instance=layer, 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:
layer_form = UploadLayerForm(instance=layer, prefix="resource")
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 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()
else:
if not isinstance(new_poc, Profile):
new_poc = Profile.objects.get(id=new_poc)
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()
else:
if not isinstance(new_author, Profile):
new_author = Profile.objects.get(id=new_author)
new_category = TopicCategory.objects.get(
id=category_form.cleaned_data['category_choice_field'])
if new_poc is not None and new_author 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.metadata_author = new_author
Layer.objects.filter(id=the_layer.id).update(
category=new_category
)
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")
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,
"category_form": category_form,
}))
示例8: layer_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm 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:
#.........这里部分代码省略.........
示例9: document_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm import is_valid [as 别名]
def document_metadata(
request,
docid,
template='documents/document_metadata.html'):
document = None
try:
document = _resolve_document(
request,
docid,
'base.change_resourcebase_metadata',
_PERMISSION_MSG_METADATA)
except Http404:
return HttpResponse(
loader.render_to_string(
'404.html', RequestContext(
request, {
})), status=404)
except PermissionDenied:
return HttpResponse(
loader.render_to_string(
'401.html', RequestContext(
request, {
'error_message': _("You are not allowed to edit this document.")})), status=403)
if document is None:
return HttpResponse(
'An unknown error has occured.',
mimetype="text/plain",
status=401
)
else:
poc = document.poc
metadata_author = document.metadata_author
topic_category = document.category
external_person = document.external_person
if request.method == "POST":
document_form = DocumentForm(
request.POST,
instance=document,
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:
document_form = DocumentForm(instance=document, prefix="resource")
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
if request.method == "POST" and document_form.is_valid(
) and category_form.is_valid():
new_poc = document_form.cleaned_data['poc']
#new_author = document_form.cleaned_data['metadata_author']
new_keywords = document_form.cleaned_data['keywords']
new_ep = document_form.cleaned_data['external_person']
new_category = TopicCategory.objects.get(
id=category_form.cleaned_data['category_choice_field'])
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_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()
"""
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_ep is not None:
the_document = document_form.save()
the_document.poc = new_poc
#.........这里部分代码省略.........
示例10: document_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm import is_valid [as 别名]
def document_metadata(
request,
docid,
template='documents/document_metadata.html',
ajax=True):
document = None
try:
document = _resolve_document(
request,
docid,
'base.change_resourcebase_metadata',
_PERMISSION_MSG_METADATA)
except Http404:
return HttpResponse(
loader.render_to_string(
'404.html', context={
}, request=request), status=404)
except PermissionDenied:
return HttpResponse(
loader.render_to_string(
'401.html', context={
'error_message': _("You are not allowed to edit this document.")}, request=request), status=403)
if document is None:
return HttpResponse(
'An unknown error has occured.',
content_type="text/plain",
status=401
)
else:
poc = document.poc
metadata_author = document.metadata_author
topic_category = document.category
if request.method == "POST":
document_form = DocumentForm(
request.POST,
instance=document,
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:
document_form = DocumentForm(instance=document, prefix="resource")
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
if request.method == "POST" and document_form.is_valid(
) and category_form.is_valid():
new_poc = document_form.cleaned_data['poc']
new_author = document_form.cleaned_data['metadata_author']
new_keywords = document_form.cleaned_data['keywords']
new_regions = document_form.cleaned_data['regions']
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.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()
the_document = document_form.instance
if new_poc is not None and new_author is not None:
the_document.poc = new_poc
the_document.metadata_author = new_author
#.........这里部分代码省略.........
示例11: appinstance_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm import is_valid [as 别名]
def appinstance_metadata(
request,
appinstanceid,
template='app_manager/appinstance_metadata.html'):
appinstance = None
try:
appinstance = _resolve_appinstance(
request,
appinstanceid,
'base.change_resourcebase_metadata',
_PERMISSION_MSG_METADATA)
except Http404:
return HttpResponse(
loader.render_to_string(
'404.html', RequestContext(
request, {
})), status=404)
except PermissionDenied:
return HttpResponse(
loader.render_to_string(
'401.html', RequestContext(
request, {
'error_message': _("You are not allowed to edit this instance.")})), status=403)
if appinstance is None:
return HttpResponse(
'An unknown error has occured.',
mimetype="text/plain",
status=401
)
else:
poc = appinstance.poc
metadata_author = appinstance.metadata_author
topic_category = appinstance.category
if request.method == "POST":
appinstance_form = AppInstanceEditForm(
request.POST,
instance=appinstance,
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:
appinstance_form = AppInstanceEditForm(instance=appinstance, prefix="resource")
category_form = CategoryForm(
prefix="category_choice_field",
initial=topic_category.id if topic_category else None)
if request.method == "POST" and appinstance_form.is_valid(
) and category_form.is_valid():
new_poc = appinstance_form.cleaned_data['poc']
new_author = appinstance_form.cleaned_data['metadata_author']
new_keywords = appinstance_form.cleaned_data['keywords']
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.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()
if new_poc is not None and new_author is not None:
the_appinstance = appinstance_form.save()
the_appinstance.poc = new_poc
the_appinstance.metadata_author = new_author
the_appinstance.keywords.add(*new_keywords)
AppInstance.objects.filter(id=the_appinstance.id).update(category=new_category)
#.........这里部分代码省略.........
示例12: map_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm 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
#.........这里部分代码省略.........
示例13: layer_metadata_create
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm import is_valid [as 别名]
def layer_metadata_create(request, layername, template='layers/cread_layer_metadata.html', publish=False):
logger.debug("*** ENTER CREAD:layer_metadata_create (pub=%s)", publish)
layer = _resolve_layer(
request,
layername,
'base.change_resourcebase_metadata',
_PERMISSION_MSG_METADATA)
clayerqs = CReadResource.objects.filter(resource=layer)
if len(clayerqs) == 0:
logger.info('cread_resource does not exist for layer %r', layer)
cread_resource = None
else:
logger.debug('cread_resource found for layer %r (%d)', layer, len(clayerqs))
cread_resource = clayerqs[0]
layer_attribute_set = inlineformset_factory(
Layer,
Attribute,
extra=0,
form=LayerAttributeForm,
)
topic_category = layer.category
cread_subcategory = cread_resource.subcategory if cread_resource else None
poc = layer.poc
metadata_author = layer.metadata_author
if request.method == "POST":
baseinfo_form = CReadBaseInfoForm(request.POST, prefix="baseinfo")
layer_form = CReadLayerForm(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)
#cread_category_form = CReadCategoryForm(
#request.POST,
#prefix="cread_category_choice_field",
#initial=int(
#request.POST["cread_category_choice_field"]) if "cread_category_choice_field" in request.POST else None)
cread_subcategory_form = CReadSubCategoryForm(
request.POST,
prefix="cread_subcategory_choice_field",
initial=int(
request.POST["cread_subcategory_choice_field"]) if "cread_subcategory_choice_field" in request.POST else None)
else:
baseinfo_form = CReadBaseInfoForm(
prefix="baseinfo",
initial={'title': layer.title,
'abstract': layer.abstract})
layer_form = CReadLayerForm(instance=layer, prefix="resource")
#_preprocess_fields(layer_form)
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)
#cread_category_form = CReadCategoryForm(
#prefix="cread_category_choice_field",
#initial=cread_category.id if cread_category else None)
cread_subcategory_form = CReadSubCategoryForm(
prefix="cread_subcategory_choice_field",
initial=cread_subcategory.id if cread_subcategory else None)
if request.method == "POST" \
and baseinfo_form.is_valid() \
and layer_form.is_valid() \
and attribute_form.is_valid() \
and cread_subcategory_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",
#.........这里部分代码省略.........
示例14: document_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm import is_valid [as 别名]
def document_metadata(request, docid, template='documents/document_metadata.html'):
document = Document.objects.get(id=docid)
poc = document.poc
metadata_author = document.metadata_author
topic_category = document.category
if request.method == "POST":
document_form = DocumentForm(request.POST, instance=document, 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:
document_form = DocumentForm(instance=document, prefix="resource")
category_form = CategoryForm(prefix="category_choice_field", initial=topic_category.id if topic_category else None)
if request.method == "POST" and document_form.is_valid() and category_form.is_valid():
new_poc = document_form.cleaned_data['poc']
new_author = document_form.cleaned_data['metadata_author']
new_keywords = document_form.cleaned_data['keywords']
new_category = TopicCategory.objects.get(id=category_form.cleaned_data['category_choice_field'])
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 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_document = document_form.save()
the_document.poc = new_poc
the_document.metadata_author = new_author
the_document.keywords.add(*new_keywords)
the_document.category = new_category
the_document.save()
return HttpResponseRedirect(reverse('document_detail', args=(document.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:
document_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:
document_form.fields['metadata_author'].initial = metadata_author.id
author_form = ProfileForm(prefix="author")
author_form.hidden = True
return render_to_response(template, RequestContext(request, {
"document": document,
"document_form": document_form,
"poc_form": poc_form,
"author_form": author_form,
"category_form": category_form,
}))
示例15: layer_metadata
# 需要导入模块: from geonode.base.forms import CategoryForm [as 别名]
# 或者: from geonode.base.forms.CategoryForm 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