Exemple #1
0
    def test_document_mimetypes_rendering(self):
        ARCHIVETYPES = [_e for _e, _t in DOCUMENT_TYPE_MAP.items() if _t == 'archive']
        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']
        self.assertIsNotNone(ARCHIVETYPES)
        self.assertIsNotNone(AUDIOTYPES)
        self.assertIsNotNone(IMGTYPES)
        self.assertIsNotNone(VIDEOTYPES)

        # Make sure we won't have template rendering issues
        self.assertTrue('dwg' in ARCHIVETYPES)
        self.assertTrue('dxf' in ARCHIVETYPES)
        self.assertTrue('tif' in ARCHIVETYPES)
        self.assertTrue('tiff' in ARCHIVETYPES)
        self.assertTrue('pbm' in ARCHIVETYPES)
Exemple #2
0
 def is_video(self):
     VIDEOTYPES = [
         _e for _e, _t in DOCUMENT_TYPE_MAP.items() if _t == 'video'
     ]
     return self.is_file and self.extension.lower() in VIDEOTYPES
Exemple #3
0
 def is_image(self):
     IMGTYPES = [
         _e for _e, _t in DOCUMENT_TYPE_MAP.items() if _t == 'image'
     ]
     return self.is_file and self.extension.lower() in IMGTYPES
Exemple #4
0
 def is_audio(self):
     AUDIOTYPES = [
         _e for _e, _t in DOCUMENT_TYPE_MAP.items() if _t == 'audio'
     ]
     return self.is_file and self.extension.lower() in AUDIOTYPES
Exemple #5
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 = get_perms(request.user,
                           document.get_self_resource()) + get_perms(
                               request.user, document)

    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.error("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)