def site_document_detail(request, docid): # BETTER WAY INSTEAD OF DO TWO _RESOLVE_DOCUMENT PER CALL? document = _resolve_document(request, docid, 'base.view_resourcebase', _PERMISSION_MSG_VIEW) site = get_current_site(request) if not SiteResources.objects.get(site=site).resources.filter( pk=document.pk).exists(): raise Http404 else: return document_detail(request, docid)
def document_metadata_detail(request, docid, template='documents/site_metadata_detail.html'): document = _resolve_document(request, docid, 'view_resourcebase', _PERMISSION_MSG_METADATA) return render_to_response( template, RequestContext(request, { "resource": document, 'SITEURL': settings.SITEURL[:-1] }))
def site_document_detail(request, docid): # BETTER WAY INSTEAD OF DO TWO _RESOLVE_DOCUMENT PER CALL? document = _resolve_document( request, docid, 'base.view_resourcebase', _PERMISSION_MSG_VIEW) site = get_current_site(request) if not SiteResources.objects.get(site=site).resources.filter(pk=document.pk).exists(): raise Http404 else: return document_detail(request, docid)
def document_metadata(request, docid, template='documents/site_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.', content_type="text/plain", status=401) else: poc = document.poc metadata_author = document.metadata_author topic_category = document.category internationalize_fields() change_abstract(document) 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 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_document = document_form.save() the_document.poc = new_poc the_document.metadata_author = new_author the_document.keywords.add(*new_keywords) Document.objects.filter(id=the_document.id).update( category=new_category) if getattr(settings, 'SLACK_ENABLED', False): try: from geonode.contrib.slack.utils import build_slack_message_document, send_slack_messages send_slack_messages( build_slack_message_document( "document_edit", the_document)) except: print "Could not send slack message for modified document." return HttpResponseRedirect( reverse('document_detail', args=(document.id, ))) if poc is not None: document_form.fields['poc'].initial = poc.id poc_form = ProfileForm(prefix="poc") poc_form.hidden = True if metadata_author is not None: 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, }))
def document_detail(request, docid): """ The view that show details of each document """ document = None try: document = _resolve_document(request, docid, 'base.view_resourcebase', _PERMISSION_MSG_VIEW) 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 view this document.") })), status=403) if document is None: return HttpResponse('An unknown error has occured.', content_type="text/plain", status=401) else: try: related = document.content_type.get_object_for_this_type( id=document.object_id) except: related = '' # Update count for popularity ranking, # but do not includes admins or resource owners if request.user != document.owner and not request.user.is_superuser: Document.objects.filter(id=document.id).update( popular_count=F('popular_count') + 1) metadata = document.link_set.metadata().filter( name__in=settings.DOWNLOAD_FORMATS_METADATA) context_dict = { 'perms_list': get_perms(request.user, document.get_self_resource()), 'permissions_json': _perms_info_json(document), 'resource': document, 'metadata': metadata, 'imgtypes': IMGTYPES, 'related': related } if settings.SOCIAL_ORIGINS: context_dict["social_links"] = build_social_links( request, document) if getattr(settings, 'EXIF_ENABLED', False): try: from geonode.contrib.exif.utils import exif_extract_dict exif = exif_extract_dict(document) if exif: context_dict['exif_data'] = exif except: print "Exif extraction failed." return render_to_response("documents/site_document_detail.html", RequestContext(request, context_dict))