<commit_before># -*- coding: utf-8 -*-

import logging
import httplib as http
from dateutil.parser import parse as parse_date

from flask import request, redirect
from modularodm.exceptions import ValidationError

from framework.auth import get_user
from framework.auth.decorators import collect_auth, must_be_logged_in
from framework.exceptions import HTTPError
from framework.forms.utils import sanitize
from framework.auth import get_current_user
from framework.auth import utils as auth_utils

from website.models import ApiKey, User
from website.views import _render_nodes
from website import settings
from website.profile import utils as profile_utils
from website.util.sanitize import escape_html

logger = logging.getLogger(__name__)


def get_public_projects(uid=None, user=None):
    user = user or User.load(uid)
    return _render_nodes([
        node
        for node in user.node__contributed
        if node.category == 'project'
        and node.is_public
        and not node.is_registration
        and not node.is_deleted
    ])


def get_public_components(uid=None, user=None):
    user = user or User.load(uid)
    return _render_nodes([
        node
        for node in user.node__contributed
        if node.category != 'project'
        and node.is_public
        and not node.is_registration
        and not node.is_deleted
    ])


def date_or_none(date):
    try:
        return parse_date(date)
    except Exception as error:
        logger.exception(error)
        return None


def _profile_view(uid=None):

    user = get_current_user()
    profile = User.load(uid) if uid else user

    if not (uid or user):
        return redirect('/login/?next={0}'.format(request.path))

    if profile:
        profile_user_data = profile_utils.serialize_user(profile, full=True)
        # TODO: Fix circular import
        # from website.addons.badges.util import get_sorted_user_badges
        return {
            'profile': profile_user_data,
            # NOTE: While badges, are unused, 'assertions' and 'badges' can be
            # empty lists. When badges are enabled, use the utility functions
            # that are currently commented out
            'assertions': [],  # get_sorted_user_badges(profile),
            'badges': [],  # _get_user_created_badges(profile),
            'user': {<commit_msg>Use ADDONS_REQUESTED to check whether to compute profile badges<commit_after># -*- coding: utf-8 -*-

import logging
import httplib as http
from dateutil.parser import parse as parse_date

from flask import request, redirect
from modularodm.exceptions import ValidationError

from framework.auth.decorators import collect_auth, must_be_logged_in
from framework.exceptions import HTTPError
from framework.forms.utils import sanitize
from framework.auth import get_current_user
from framework.auth import utils as auth_utils

from website.models import ApiKey, User
from website.views import _render_nodes
from website import settings
from website.profile import utils as profile_utils
from website.util.sanitize import escape_html

logger = logging.getLogger(__name__)


def get_public_projects(uid=None, user=None):
    user = user or User.load(uid)
    return _render_nodes([
        node
        for node in user.node__contributed
        if node.category == 'project'
        and node.is_public
        and not node.is_registration
        and not node.is_deleted
    ])


def get_public_components(uid=None, user=None):
    user = user or User.load(uid)
    return _render_nodes([
        node
        for node in user.node__contributed
        if node.category != 'project'
        and node.is_public
        and not node.is_registration
        and not node.is_deleted
    ])


def date_or_none(date):
    try:
        return parse_date(date)
    except Exception as error:
        logger.exception(error)
        return None


def _profile_view(uid=None):
    # TODO: Fix circular import
    from website.addons.badges.util import get_sorted_user_badges

    user = get_current_user()
    profile = User.load(uid) if uid else user

    if not (uid or user):
        return redirect('/login/?next={0}'.format(request.path))

    if 'badges' in settings.ADDONS_REQUESTED:
        badge_assertions = get_sorted_user_badges(profile),
        badges = _get_user_created_badges(profile)
    else:
        # NOTE: While badges, are unused, 'assertions' and 'badges' can be
        # empty lists.
        badge_assertions = []
        badges = []

    if profile:
        profile_user_data = profile_utils.serialize_user(profile, full=True)
        return {
            'profile': profile_user_data,
            'assertions': badge_assertions,
            'badges': badges,
            'user': {
{'fraction_non_alphanumeric': 0.07318104906937395, 'fraction_numerical': 0.0008460236886632825, 'mean_word_length': 3.0488013698630136, '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': '5686267', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1339, 'n_words': 404}