本文整理汇总了Python中geonode.base.forms.CategoryForm类的典型用法代码示例。如果您正苦于以下问题:Python CategoryForm类的具体用法?Python CategoryForm怎么用?Python CategoryForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CategoryForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: document_metadata
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
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
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
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: map_metadata
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
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
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
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
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
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
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
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
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
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
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)
#.........这里部分代码省略.........