Beispiel #1
0
def detect():
    if request.method == "GET":
        return render_template("detect.html")
    if request.method == "POST":
        url = request.values.get("url")
        if url is None:
            return render_template("detect.html")
        register = autodiscovery.discover(url)
        if util.request_wants_json():
            resp = make_response( json.dumps(register) )
            resp.mimetype = "application/json"
            return resp        
        else:
            return render_template("repository.html", repo=register, searchurl=searchurl)
Beispiel #2
0
def contribute():

    detectdone = False
    dup = False

    if request.method == 'GET':
    
        # check to see if this is an update
        if 'updaterequest' in request.values:
            # get record from OARR
            try:
                base = app.config.get("OARR_API_BASE_URL")
                if base is None: abort(500)
                client = OARRClient(base)
                record = client.get_record(request.values["updaterequest"]).raw
                if "opendoar" not in record["admin"]: record["admin"]["opendoar"] = {}
                record["admin"]["opendoar"]["updaterequest"] = request.values["updaterequest"]
                detectdone = True
            except:
                abort(404)
        
        # check for a url request param
        elif 'url' in request.values:
            # if there is one, then try to set the initial object
            if len(request.values['url']) != 0:
                try:
                    register = autodiscovery.discover(request.values['url'])
                    record = register.raw
                    for k, v in util.defaultrecord['register']['metadata'][0]['record'].iteritems():
                        if k not in record.get('register',{}).get('metadata',[{"record":{}}])[0]['record']:
                            record['register']['metadata'][0]['record'][k] = v
                except:
                    record = util.defaultrecord

                # check if there is already a record with this url
                dup = rawduplicate(request.values['url'],raw=True)
                
            else:
                record = util.defaultrecord
            detectdone = True
        else:
            # otherwise set a default initial object
            record = util.defaultrecord
            
        if util.request_wants_json():
            resp = make_response( json.dumps({"record":record}) )
            resp.mimetype = "application/json"
            return resp
        else:
            return render_template("contribute.html", record=record, detectdone=detectdone, duplicate=dup)

    elif request.method == 'POST':
        base = app.config.get("OARR_API_BASE_URL")
        apikey = app.config.get("OARR_API_KEY")
        if base is None or apikey is None: abort(500)
        client = OARRClient(base, apikey)
        record = client.prep_record(util.defaultrecord,request)
        if 'updaterequest' not in record['admin']['opendoar']: record['admin']['opendoar']['newcontribution'] = True
        saved = client.save_record(record)
        if saved:
            flash('Thank you very much for your submission. Your request will be processed as soon as possible, and usually within three working days.', 'success')
            return redirect('/')
        else:
            flash('Sorry, there was a problem saving your submission. Please try again.', 'error')
            return redirect('/contribute')
Beispiel #3
0
from portality.autodiscovery import autodiscovery
import json

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser()

    parser.add_argument("-u", "--url", help="url to autodetect from")

    args = parser.parse_args()

    if not args.url:
        print "Please specify a url with the -u option"
        exit()

    register = autodiscovery.discover(args.url)
    print json.dumps(register.raw)