Ejemplo n.º 1
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.fields['links'].choices = self.generate_link_choices()
     self.fields['links'].initial = self.generate_link_values(
         resources=get_related_resources(self.instance))
     for field in self.fields:
         help_text = self.fields[field].help_text
         self.fields[field].help_text = None
         if help_text != '':
             self.fields[field].widget.attrs.update({
                 'class': 'has-external-popover',
                 'data-content': help_text,
                 'placeholder': help_text,
                 'data-placement': 'right',
                 'data-container': 'body',
                 'data-html': 'true'
             })
Ejemplo n.º 2
0
def document_detail(request, docid):
    """
    The view that show details of each document
    """
    try:
        document = _resolve_document(request, docid, 'base.view_resourcebase',
                                     _PERMISSION_MSG_VIEW)
    except PermissionDenied:
        return HttpResponse(_("Not allowed"), status=403)
    except Exception:
        raise Http404(_("Not found"))
    if not document:
        raise Http404(_("Not found"))

    permission_manager = ManageResourceOwnerPermissions(document)
    permission_manager.set_owner_permissions_according_to_workflow()

    # Add metadata_author or poc if missing
    document.add_missing_metadata_author_or_poc()

    related = get_related_resources(document)

    # 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)

    # Call this first in order to be sure "perms_list" is correct
    permissions_json = _perms_info_json(document)

    perms_list = list(document.get_self_resource().get_user_perms(
        request.user).union(document.get_user_perms(request.user)))

    group = None
    if document.group:
        try:
            group = GroupProfile.objects.get(slug=document.group.name)
        except ObjectDoesNotExist:
            group = None

    access_token = None
    if request and request.user:
        access_token = get_or_create_token(request.user)
        if access_token and not access_token.is_expired():
            access_token = access_token.token
        else:
            access_token = None

    AUDIOTYPES = [_e for _e, _t in DOCUMENT_TYPE_MAP.items() if _t == 'audio']
    IMGTYPES = [_e for _e, _t in DOCUMENT_TYPE_MAP.items() if _t == 'image']
    VIDEOTYPES = [_e for _e, _t in DOCUMENT_TYPE_MAP.items() if _t == 'video']

    context_dict = {
        'access_token': access_token,
        'resource': document,
        'perms_list': perms_list,
        'permissions_json': permissions_json,
        'group': group,
        'metadata': metadata,
        'audiotypes': AUDIOTYPES,
        'imgtypes': IMGTYPES,
        'videotypes': VIDEOTYPES,
        'mimetypemap': DOCUMENT_MIMETYPE_MAP,
        'related': related
    }

    if settings.SOCIAL_ORIGINS:
        context_dict["social_links"] = build_social_links(request, document)

    if getattr(settings, 'EXIF_ENABLED', False):
        try:
            from geonode.documents.exif.utils import exif_extract_dict
            exif = exif_extract_dict(document)
            if exif:
                context_dict['exif_data'] = exif
        except Exception:
            logger.debug("Exif extraction failed.")

    if request.user.is_authenticated:
        if getattr(settings, 'FAVORITE_ENABLED', False):
            from geonode.favorite.utils import get_favorite_info
            context_dict["favorite_info"] = get_favorite_info(
                request.user, document)

    register_event(request, EventType.EVENT_VIEW, document)

    return render(request,
                  "documents/document_detail.html",
                  context=context_dict)