本文整理汇总了Python中geonode.people.forms.ProfileForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python ProfileForm.save方法的具体用法?Python ProfileForm.save怎么用?Python ProfileForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geonode.people.forms.ProfileForm
的用法示例。
在下文中一共展示了ProfileForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profile_edit
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [as 别名]
def profile_edit(request, username=None):
if username is None:
try:
profile = request.user.profile
except Profile.DoesNotExist:
return redirect("profile_browse")
else:
profile = get_object_or_404(Profile, username=username)
if request.method == "POST":
form = ProfileForm(request.POST, request.FILES, instance=profile)
if form.is_valid():
form.save()
messages.success(request, "Profile profile updated.")
return redirect(
reverse(
'profile_detail',
args=[
request.user.username]))
else:
form = ProfileForm(instance=profile)
return render(request, "people/profile_edit.html", {
"form": form,
})
示例2: profile_edit
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [as 别名]
def profile_edit(request, username=None):
if username is None:
try:
profile = request.user
username = profile.username
except Profile.DoesNotExist:
return redirect("profile_browse")
else:
profile = get_object_or_404(Profile, username=username)
if username == request.user.username or request.user.is_superuser:
if request.method == "POST":
form = ProfileForm(request.POST, request.FILES, instance=profile)
if form.is_valid():
form.save()
messages.success(request, "Profile profile updated.")
return redirect(
reverse(
'profile_detail',
args=[
username]))
else:
form = ProfileForm(instance=profile)
return render(request, "people/profile_edit.html", {
"profile": profile,
"form": form,
})
else:
return HttpResponseForbidden(
'You are not allowed to edit other users profile')
示例3: document_metadata
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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
if request.method == "POST":
document_form = DocumentForm(request.POST, instance=document, prefix="document")
else:
document_form = DocumentForm(instance=document, prefix="document")
if request.method == "POST" and document_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"]
if new_poc is None:
poc_form = ProfileForm(request.POST, prefix="poc")
if poc_form.has_changed and poc_form.is_valid():
new_poc = poc_form.save()
if new_author is None:
author_form = ProfileForm(request.POST, prefix="author")
if author_form.has_changed and author_form.is_valid():
new_author = author_form.save()
if new_poc is not None and new_author is not None:
the_document = document_form.save(commit=False)
the_document.poc = new_poc
the_document.metadata_author = new_author
the_document.keywords.add(*new_keywords)
the_document.save()
return HttpResponseRedirect(reverse("document_detail", args=(document.id,)))
if poc.user 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.user 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},
),
)
示例4: project_metadata
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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,
)))
#.........这里部分代码省略.........
示例5: map_metadata
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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
#.........这里部分代码省略.........
示例6: map_metadata
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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,
}))
示例7: layer_metadata
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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:
#.........这里部分代码省略.........
示例8: document_metadata
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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,
}))
示例9: map_metadata
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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:
#.........这里部分代码省略.........
示例10: document_metadata
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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
#.........这里部分代码省略.........
示例11: appinstance_metadata
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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: layer_metadata
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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":
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(
#.........这里部分代码省略.........
示例15: document_metadata
# 需要导入模块: from geonode.people.forms import ProfileForm [as 别名]
# 或者: from geonode.people.forms.ProfileForm import save [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
#.........这里部分代码省略.........