<commit_before>import httplib as http

from framework import request
from framework.exceptions import HTTPError
from framework.auth import get_current_user

from website.util import web_url_for
from website.project.decorators import (must_have_addon,
    must_have_permission, must_not_be_registration,
    must_be_valid_project
)

from ..api import Figshare
from ..utils import options_to_hgrid


###### AJAX Config
@must_be_valid_project
@must_have_addon('figshare', 'node')
def figshare_config_get(node_addon, **kwargs):
    """API that returns the serialized node settings."""
    user = get_current_user()
    return {
        'result': serialize_settings(node_addon, user),
    }, http.OK


@must_have_permission('write')
@must_not_be_registration
@must_have_addon('figshare', 'node')
def figshare_config_put(node_addon, auth, **kwargs):
    """View for changing a node's linked figshare folder."""
    selected = request.json.get('selected')    
    fields = {}
    for key in selected.keys():
        fields[key] = selected[key]
    node = node_addon.owner
    node_addon.update_fields(fields, node, auth)

    return {
        'result': {
            'linked': {
                'name': fields.get('title') or '',
                'id': fields.get('id') or None,
                'type': fields.get('type') or None
            },
            'urls': serialize_urls(node_addon)
        },
        'message': 'Successfully updated settings.',
    }, http.OK


@must_have_permission('write')
@must_have_addon('figshare', 'node')
def figshare_import_user_auth(auth, node_addon, **kwargs):
    """Import figshare credentials from the currently logged-in user to a node.
    """
    user = auth.user
    user_addon = user.get_addon('figshare')
    if user_addon is None or node_addon is None:
        raise HTTPError(http.BAD_REQUEST)
    node_addon.authorize(user_addon, save=True)
    return {
        'result': serialize_settings(node_addon, user),
        'message': 'Successfully imported access token from profile.',
    }, http.OK
<commit_msg>Fixes issue causes figshare settings not to display properly.<commit_after>import httplib as http

from framework import request
from framework.exceptions import HTTPError
from framework.auth import get_current_user

from website.util import web_url_for
from website.project.decorators import (must_have_addon,
    must_have_permission, must_not_be_registration,
    must_be_valid_project
)

from ..api import Figshare
from ..utils import options_to_hgrid


###### AJAX Config
@must_be_valid_project
@must_have_addon('figshare', 'node')
def figshare_config_get(node_addon, **kwargs):
    """API that returns the serialized node settings."""
    user = get_current_user()
    return {
        'result': serialize_settings(node_addon, user),
    }, http.OK


@must_have_permission('write')
@must_not_be_registration
@must_have_addon('figshare', 'node')
def figshare_config_put(node_addon, auth, **kwargs):
    """View for changing a node's linked figshare folder."""
    selected = request.json.get('selected')    
    fields = {}
    for key in selected.keys():
        fields[key] = selected[key]
    node = node_addon.owner
    node_addon.update_fields(fields, node, auth)

    return {
        'result': {
            'linked': {
                'title': fields.get('title') or '',
                'id': fields.get('id') or None,
                'type': fields.get('type') or None
            },
            'urls': serialize_urls(node_addon)
        },
        'message': 'Successfully updated settings.',
    }, http.OK


@must_have_permission('write')
@must_have_addon('figshare', 'node')
def figshare_import_user_auth(auth, node_addon, **kwargs):
    """Import figshare credentials from the currently logged-in user to a node.
    """
    user = auth.user
    user_addon = user.get_addon('figshare')
    if user_addon is None or node_addon is None:
        raise HTTPError(http.BAD_REQUEST)
    node_addon.authorize(user_addon, save=True)
    return {
        'result': serialize_settings(node_addon, user),
        'message': 'Successfully imported access token from profile.',
    }, http.OK

{'fraction_non_alphanumeric': 0.11250301132257287, 'fraction_numerical': 0.0, 'mean_word_length': 3.5032537960954446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3616805', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1266, 'n_words': 316}