Beispiel #1
0
def index(request):
    # logged in user
    c = create_context(request.user)
    c.ident = request.user
    add_auth_info_to_context(request, c)
    c.silos = list_silos()

    if settings.METADATA_EMBARGOED:
        # if not ident:
        #    abort(401, "Not Authorised")
        if request.user.is_authenticated():
            c.silos = authz(ident)
        else:
            return HttpResponseForbidden("Forbidden")

    c.silo_infos = {}
    for silo in c.silos:
        c.silo_infos[silo] = []
        state_info = granary.describe_silo(silo)
        if "title" in state_info and state_info["title"]:
            c.silo_infos[silo].append(state_info["title"])
        else:
            c.silo_infos[silo].append(silo)
        c.silo_infos[silo].append(get_datasets_count(silo))
        c.silo_infos[silo].append(getSiloModifiedDate(silo))

    return render_html_or_json(request, c, "list_of_silos.html", c.silos)
def index(request):
    # logged in user
    c = create_context(request.user)
    c.ident = request.user
    add_auth_info_to_context(request, c)
    c.silos = list_silos()

    if settings.METADATA_EMBARGOED:
        #if not ident:
        #    abort(401, "Not Authorised")
        if request.user.is_authenticated():
            c.silos = authz(ident)
        else:
            return HttpResponseForbidden("Forbidden")

    c.silo_infos = {}
    for silo in c.silos:
        c.silo_infos[silo] = []
        state_info = granary.describe_silo(silo)
        if 'title' in state_info and state_info['title']:
            c.silo_infos[silo].append(state_info['title'])
        else:
            c.silo_infos[silo].append(silo)
        c.silo_infos[silo].append(get_datasets_count(silo))
        c.silo_infos[silo].append(getSiloModifiedDate(silo))

    return render_html_or_json(request, c, 'list_of_silos.html', c.silos)
def api_view(request, api_name):
    # logged in user
    c = create_context(request.user)
    c.ident = request.user
    add_auth_info_to_context(request, c)
    if api_name not in ['silos', 'datasets', 'states', 'items']:
        # redirect(url(controller="api", action="apiview", api_name="silos"))
        return redirect("/api/silos")
    c.api_file = "%s_api.html"%api_name    
    return render_to_response('/api.html', {'c':c})
Beispiel #4
0
def api_view(request, api_name):
    # logged in user
    c = create_context(request.user)
    c.ident = request.user
    add_auth_info_to_context(request, c)
    if api_name not in ['silos', 'datasets', 'states', 'items']:
        # redirect(url(controller="api", action="apiview", api_name="silos"))
        return redirect("/api/silos")
    c.api_file = "%s_api.html" % api_name
    return render_to_response('/api.html', {'c': c})
def view(request, siloname):
    c = create_context(request.user, siloname)
    add_auth_info_to_context(request, c)
    if not granary.issilo(siloname):
        raise Http404

    ident = request.user
    c.ident = ident
    c.silo_name = siloname
    c.user_permissions = list_user_permissions(ident.username, siloname)
    c.editor = False
    if settings.METADATA_EMBARGOED:
        if request.user.is_authenticated():
            c.silos = authz(ident)
            if siloname in silos:
                c.editor = True
            else:
                return HttpResponseForbidden("Forbidden")
        else:
            return HttpResponseForbidden("Forbidden")
    else:
        c.silos = authz(ident)
        if siloname in c.silos:
            c.editor = True

    # FIXME: MAJOR issue - very specific 'if' here
    # TODO: Add a flag to the Silo model to mark whether a silo is
    # listable.
    if siloname in ['ww1archives', 'digitalbooks']:
        return HttpResponse(
            "The silo %s contains too many data packages to list" % siloname,
            mimetype="text/plain")

    rdfsilo = granary.get_rdf_silo(siloname)
    state_info = granary.describe_silo(siloname)
    if 'title' in state_info and state_info['title']:
        c.title = state_info['title']
    c.embargos = {}
    c.items = []
    for item in rdfsilo.list_items():
        c.embargos[item] = None
        try:
            c.embargos[item] = is_embargoed(rdfsilo, item)
        except:
            pass
        c.items.append(item)
        #c.embargos[item] = ()

    return render_html_or_json(request, c, 'siloview.html', c.embargos)
Beispiel #6
0
def view(request, siloname):
    c = create_context(request.user, siloname)
    add_auth_info_to_context(request, c)
    if not granary.issilo(siloname):
        raise Http404

    ident = request.user
    c.ident = ident
    c.silo_name = siloname
    c.user_permissions = list_user_permissions(ident.username, siloname)
    c.editor = False
    if settings.METADATA_EMBARGOED:
        if request.user.is_authenticated():
            c.silos = authz(ident)
            if siloname in silos:
                c.editor = True
            else:
                return HttpResponseForbidden("Forbidden")
        else:
            return HttpResponseForbidden("Forbidden")
    else:
        c.silos = authz(ident)
        if siloname in c.silos:
            c.editor = True

    # FIXME: MAJOR issue - very specific 'if' here
    # TODO: Add a flag to the Silo model to mark whether a silo is
    # listable.
    if siloname in ["ww1archives", "digitalbooks"]:
        return HttpResponse("The silo %s contains too many data packages to list" % siloname, mimetype="text/plain")

    rdfsilo = granary.get_rdf_silo(siloname)
    state_info = granary.describe_silo(siloname)
    if "title" in state_info and state_info["title"]:
        c.title = state_info["title"]
    c.embargos = {}
    c.items = []
    for item in rdfsilo.list_items():
        c.embargos[item] = None
        try:
            c.embargos[item] = is_embargoed(rdfsilo, item)
        except:
            pass
        c.items.append(item)
        # c.embargos[item] = ()

    return render_html_or_json(request, c, "siloview.html", c.embargos)
def silo_view(request, siloname):
    """
GET: Obtain a list of datasets in a silo

Returns
401 if not a valid user
403 if not authorized
Accept:text/html
Returns the ids of each dataset in the silo, along with a form for changing the embargo information and deleting the dataset. A form for dataset creation is also available.
Accept: text/plain, application/json
200 OK
Returns a JSON-encoded list of dataset ids in that silo along with the embargo information for each dataset
The file datasetsInSiloInformation.txt contains an example of the data returned (data_returned)
Accept:*/*, default
Returns text/HTML listing the ids of each dataset, along with a form for changing the embargo information and deleting the dataset. A form for dataset creation is also available.
    """
    if not granary.issilo(siloname):
        # No silo here
        response = HttpResponse()
        response.status_code = 404
        return response
        
    # Deal with request methods - GET then POST
    if request.method == "GET":
        c = create_context(request.user)
        
        c.silo_name = siloname

        # FIXME: Make these unhardcoded
        if siloname in ['ww1archives', 'digitalbooks']:
            abort(501, "The silo %s contains too many data packages to list"%siloname)
        c.editor = False
        
        c.read_state = can_read(request.user, siloname)
        
        if state == MDONLY:
            if settings.METADATA_EMBARGOED:
                # Forbidden
                response = HttpResponse()
                response.status_code = 403
                return response

        if can_write(request.user, siloname):
            c.editor = True

        options = request.REQUEST
        c.start = 0
        if 'start' in options and options['start']:
            try:
                c.start = int(options['start'])
            except ValueError:
                c.start = 0
        c.rows = 100
        if 'rows' in options and options['rows']:
            try:
                c.rows = int(options['rows'])
            except ValueError:
                c.rows = 100
                
                     
        c_silo = granary.get_rdf_silo(siloname)
        # Get title of silo
        state_info = granary.describe_silo(siloname)
        if 'title' in state_info and state_info['title']:
            c.title = state_info['title']
        # Get number of data packages in silo
        numFound = get_datasets_count(siloname)
        try:
            c.numFound = int(numFound)
        except ValueError:
            c.numFound = 0

        c.embargos = {}
        # FIXME: A crushingly slow way to check?
        for item in get_datasets(siloname, start=c.start, rows=c.rows):
            try:
                c.embargos[item] = is_embargoed(c_silo, item)
            except:
                c.embargos[item] = None
        c.items = c.embargos.keys()
        
        # pagination
        c.permissible_offsets = []
        c.pages_to_show = 5
        try:
            remainder = c.numFound % c.rows
            if remainder > 0:
                c.lastPage = c.numFound - remainder
            else:
                c.lastPage = c.numFound - c.rows

            if c.numFound > c.rows:
                offset_start = c.start - ( (c.pages_to_show/2) * c.rows )
                if offset_start < 0:
                    offset_start = 0
   
                offset_end = offset_start + (c.pages_to_show * c.rows)
                if offset_end > c.numFound:
                    offset_end = c.numFound
                    if remainder > 0:
                        offset_start = c.lastPage - (c.pages_to_show * c.rows)
                    else:
                        offset_start = c.lastPage - ((c.pages_to_show-1) * c.rows)

                    if offset_start < 0:
                        offset_start = 0
                              
                c.permissible_offsets = list( xrange( offset_start, offset_end, c.rows) )
        except ValueError:
            # FIXME: Not a good solution, escaping here
            pass
            
        return render_html_or_json(request, c, '/siloview.html', c.embargos)
    elif request.method == "POST":
        """
POST: Create new dataset

Parameters
id	 {id to create}
embargoed	 {true|false} (optional).
If the parameter is not supplied, a default value of true will be used.
embargoed_until	 {ISO8601 date} (optional).
If embargoed = true and no date has been supplied, a default time delta of 70 years will be used
title	{(Optional)}
Returns
409 if dataset already exists 
401 If not a valid user 
403 if not authorized 
403 if the name of the dataset does not confirm to the naming rule (name can contain only the followin characters 0-9a-zA-Z-_:
Accept: text/html
302 to splash page for newly created dataset
Accept: text/plain, application/json
201 created
Accept: */*, default
Returns text/plain, 201 created
PUT, DELETE: NOOP
        """
                
        if not can_write(request.user, siloname):
            # Forbidden
            response = HttpResponse()
            response.status_code = 403
            return response
        else:
            params = request.POST.dict()

            if not params.has_key("id"):
                response = HttpResponse()
                response.status_code = 400
                response.content = "400 Bad Request: Parameter 'id' is not available"
                return response
                
            c_silo = granary.get_rdf_silo(siloname)        
            if c_silo.exists(params['id']):
                response = HttpResponse()
                response.status_code = 409
                response.content = "409 Conflict: Data package already exists"
                return response

            # Supported params:
            # id, title, embargoed, embargoed_until, embargo_days_from_now
            id = params['id']
            if not allowable_id2(id):
                response = HttpResponse()
                response.status_code = 400
                response.content = "400 Bad request. Data package name not valid"
                return response

            del params['id']
            item = create_new(c_silo, id, request.user.username, **params)
            add_dataset(siloname, id)
            # Broadcast change as message
            try:
                b.creation(siloname, id, ident=request.user.username)
            except:
                pass
                 
            # conneg return
            
            if "HTTP_ACCEPT" in request.META.keys():
                if str(request.META['HTTP_ACCEPT']).lower() in ["text/html", "text/xhtml"]:
                    redirect('datasets_main_view', siloname=siloname, id=id)
            
            response = HttpResponse()
            response.status_code = 201
            response.content = "201 Created"
            response['Content-Location'] = reverse('datasets_main_view', siloname=siloname, id=id)
            return response
def home(request):
    # logged in user
    c = create_context(request.user)
    c.ident = request.user
    add_auth_info_to_context(request, c)
    return render_to_response("home.html", {'c':c})
def api_index(request):
    # logged in user
    c = create_context(request.user)
    c.ident = request.user
    return redirect("/api/silos")
Beispiel #10
0
def home(request):
    # logged in user
    c = create_context(request.user)
    c.ident = request.user
    add_auth_info_to_context(request, c)
    return render_to_response("home.html", {'c': c})
Beispiel #11
0
def api_index(request):
    # logged in user
    c = create_context(request.user)
    c.ident = request.user
    return redirect("/api/silos")
Beispiel #12
0
def silo_view(request, siloname):
    """
GET: Obtain a list of datasets in a silo

Returns
401 if not a valid user
403 if not authorized
Accept:text/html
Returns the ids of each dataset in the silo, along with a form for changing the embargo information and deleting the dataset. A form for dataset creation is also available.
Accept: text/plain, application/json
200 OK
Returns a JSON-encoded list of dataset ids in that silo along with the embargo information for each dataset
The file datasetsInSiloInformation.txt contains an example of the data returned (data_returned)
Accept:*/*, default
Returns text/HTML listing the ids of each dataset, along with a form for changing the embargo information and deleting the dataset. A form for dataset creation is also available.
    """
    if not granary.issilo(siloname):
        # No silo here
        response = HttpResponse()
        response.status_code = 404
        return response

    # Deal with request methods - GET then POST
    if request.method == "GET":
        c = create_context(request.user)

        c.silo_name = siloname

        # FIXME: Make these unhardcoded
        if siloname in ['ww1archives', 'digitalbooks']:
            abort(
                501, "The silo %s contains too many data packages to list" %
                siloname)
        c.editor = False

        c.read_state = can_read(request.user, siloname)

        if state == MDONLY:
            if settings.METADATA_EMBARGOED:
                # Forbidden
                response = HttpResponse()
                response.status_code = 403
                return response

        if can_write(request.user, siloname):
            c.editor = True

        options = request.REQUEST
        c.start = 0
        if 'start' in options and options['start']:
            try:
                c.start = int(options['start'])
            except ValueError:
                c.start = 0
        c.rows = 100
        if 'rows' in options and options['rows']:
            try:
                c.rows = int(options['rows'])
            except ValueError:
                c.rows = 100

        c_silo = granary.get_rdf_silo(siloname)
        # Get title of silo
        state_info = granary.describe_silo(siloname)
        if 'title' in state_info and state_info['title']:
            c.title = state_info['title']
        # Get number of data packages in silo
        numFound = get_datasets_count(siloname)
        try:
            c.numFound = int(numFound)
        except ValueError:
            c.numFound = 0

        c.embargos = {}
        # FIXME: A crushingly slow way to check?
        for item in get_datasets(siloname, start=c.start, rows=c.rows):
            try:
                c.embargos[item] = is_embargoed(c_silo, item)
            except:
                c.embargos[item] = None
        c.items = c.embargos.keys()

        # pagination
        c.permissible_offsets = []
        c.pages_to_show = 5
        try:
            remainder = c.numFound % c.rows
            if remainder > 0:
                c.lastPage = c.numFound - remainder
            else:
                c.lastPage = c.numFound - c.rows

            if c.numFound > c.rows:
                offset_start = c.start - ((c.pages_to_show / 2) * c.rows)
                if offset_start < 0:
                    offset_start = 0

                offset_end = offset_start + (c.pages_to_show * c.rows)
                if offset_end > c.numFound:
                    offset_end = c.numFound
                    if remainder > 0:
                        offset_start = c.lastPage - (c.pages_to_show * c.rows)
                    else:
                        offset_start = c.lastPage - (
                            (c.pages_to_show - 1) * c.rows)

                    if offset_start < 0:
                        offset_start = 0

                c.permissible_offsets = list(
                    xrange(offset_start, offset_end, c.rows))
        except ValueError:
            # FIXME: Not a good solution, escaping here
            pass

        return render_html_or_json(request, c, '/siloview.html', c.embargos)
    elif request.method == "POST":
        """
POST: Create new dataset

Parameters
id	 {id to create}
embargoed	 {true|false} (optional).
If the parameter is not supplied, a default value of true will be used.
embargoed_until	 {ISO8601 date} (optional).
If embargoed = true and no date has been supplied, a default time delta of 70 years will be used
title	{(Optional)}
Returns
409 if dataset already exists 
401 If not a valid user 
403 if not authorized 
403 if the name of the dataset does not confirm to the naming rule (name can contain only the followin characters 0-9a-zA-Z-_:
Accept: text/html
302 to splash page for newly created dataset
Accept: text/plain, application/json
201 created
Accept: */*, default
Returns text/plain, 201 created
PUT, DELETE: NOOP
        """

        if not can_write(request.user, siloname):
            # Forbidden
            response = HttpResponse()
            response.status_code = 403
            return response
        else:
            params = request.POST.dict()

            if not params.has_key("id"):
                response = HttpResponse()
                response.status_code = 400
                response.content = "400 Bad Request: Parameter 'id' is not available"
                return response

            c_silo = granary.get_rdf_silo(siloname)
            if c_silo.exists(params['id']):
                response = HttpResponse()
                response.status_code = 409
                response.content = "409 Conflict: Data package already exists"
                return response

            # Supported params:
            # id, title, embargoed, embargoed_until, embargo_days_from_now
            id = params['id']
            if not allowable_id2(id):
                response = HttpResponse()
                response.status_code = 400
                response.content = "400 Bad request. Data package name not valid"
                return response

            del params['id']
            item = create_new(c_silo, id, request.user.username, **params)
            add_dataset(siloname, id)
            # Broadcast change as message
            try:
                b.creation(siloname, id, ident=request.user.username)
            except:
                pass

            # conneg return

            if "HTTP_ACCEPT" in request.META.keys():
                if str(request.META['HTTP_ACCEPT']).lower() in [
                        "text/html", "text/xhtml"
                ]:
                    redirect('datasets_main_view', siloname=siloname, id=id)

            response = HttpResponse()
            response.status_code = 201
            response.content = "201 Created"
            response['Content-Location'] = reverse('datasets_main_view',
                                                   siloname=siloname,
                                                   id=id)
            return response