Beispiel #1
0
def get_ols_url():
    req = data_utils.get_current_request()
    protocol = req.META['wsgi.url_scheme']
    r = req.build_absolute_uri()
    ols_url = protocol + '://' + data_utils.get_current_request().META['HTTP_HOST'] + reverse(
        'copo:ajax_search_ontology')

    return ols_url
Beispiel #2
0
 def __init__(self, sub_id):
     self.BASE_URL = FIGSHARE_API_URLS['base_url']
     request = data_utils.get_current_request()
     self.TOKEN = Figshare().get_token_for_user(request.user.id)['token']
     self.HEADERS = {'Authorization': 'token ' + self.TOKEN}
     self.MEDIA_ROOT = settings.MEDIA_ROOT
     self.transfer_token = RemoteDataFile().create_transfer(sub_id)['_id']
Beispiel #3
0
    def do_user_has_email(self):
        req = data_utils.get_current_request()
        user = User.objects.get(pk=int(req.user.id))

        self.context['user_has_email'] = bool(user.email.strip())

        return self.context
Beispiel #4
0
def submit_to_figshare(article_id):
    try:
        token_object = retrieve_token()
        collection = FigshareCollection().get_collection_head_from_article(
            article_id)
        article = FigshareCollection().get_article(article_id)
        request = data_utils.get_current_request()
        # get file path
        p = path.join(article['path'], article['hashed_name'])
        new_name = path.join(settings['MEDIA_ROOT'], article['original_name'])
        shutil.copyfile(p, new_name)
        # make article on figshare
        figshare_article = make_article(name=collection['name'],
                                        description=article['description'],
                                        type=article['article_type'],
                                        oauth=token_object)
        figshare_article_id = figshare_article['article_id']
        FigshareCollection().add_figshare_accession_to_article(
            figshare_id=figshare_article_id, article_id=article_id)
        FigshareCollection().add_figshare_url_to_article(
            figshare_id=figshare_article_id, article_id=article_id)
        add_file_to_article(oauth=token_object,
                            article_id=figshare_article_id,
                            filename=new_name)
        for tag in article['tags']:
            add_tags_to_article(oauth=token_object,
                                article_id=figshare_article_id,
                                tag=tag)
    except RuntimeError as e:
        print(e)
        return None
    return figshare_article_id
Beispiel #5
0
    def submit(self, sub_id, dataFile_ids):
        profile_id = data_utils.get_current_request().session.get('profile_id')
        s = Submission().get_record(ObjectId(sub_id))

        # get url for dataverse
        self.host = Submission().get_dataverse_details(sub_id)
        self.headers = {'X-Dataverse-key': self.host['apikey']}

        # if dataset id in submission meta, we are adding to existing dataset, otherwise
        #  we are creating a new dataset
        new_or_existing = s['meta']['new_or_existing']
        return self._add_to_dspace(s, new_or_existing)
Beispiel #6
0
    def do_update_quick_tour_flag(self):
        req = data_utils.get_current_request()
        quick_tour_flag = self.param_dict.get("quick_tour_flag", "false")

        if quick_tour_flag == "false":
            quick_tour_flag = False
        else:
            quick_tour_flag = True

        req.session["quick_tour_flag"] = quick_tour_flag
        self.context["quick_tour_flag"] = req.session["quick_tour_flag"]

        return self.context
Beispiel #7
0
def get_authorize_url():

    request_token_url = 'http://api.figshare.com/v1/pbl/oauth/request_token'
    authorization_url = 'http://api.figshare.com/v1/pbl/oauth/authorize'

    #Obtain request token
    request = data_utils.get_current_request()
    domain = request.META['HTTP_HOST']
    callback_uri = 'http://' + domain + reverse(
        'rest:set_figshare_credentials')
    oauth = OAuth1Session(client_key,
                          client_secret=client_secret,
                          callback_uri=callback_uri)
    fetch_response = oauth.fetch_request_token(request_token_url)
    request.session['resource_owner_key'] = fetch_response.get('oauth_token')
    request.session['resource_owner_secret'] = fetch_response.get(
        'oauth_token_secret')

    #Obtain Authorize Token
    authorize_url = authorization_url + '?oauth_token='
    authorize_url = authorize_url + request.session['resource_owner_key']

    #redirect user to auth page
    return authorize_url
Beispiel #8
0
def get_source_count(self):
    profile_id = data_utils.get_current_request().session['profile_id']
    num_sources = ProfileInfo(profile_id).source_count()
    return HttpResponse(encode({'num_sources': num_sources}))