<commit_before># Copyright 2014 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Controllers for the profile page."""

__author__ = '<EMAIL> (<NAME>)'

from core.controllers import base
from core.domain import email_manager
from core.domain import user_services
import feconf
import utils


def require_user_id_else_redirect_to_homepage(handler):
    """Decorator that checks if a user_id is associated to the current
    session. If not, the user is redirected to the main page.

    Note that the user may not yet have registered.
    """
    def test_login(self, **kwargs):
        """Checks if the user for the current session is logged in.

        If not, redirects the user to the home page.
        """
        if not self.user_id:
            self.redirect('/')
            return
        return handler(self, **kwargs)

    return test_login


class ProfilePage(base.BaseHandler):
    """The world-viewable profile page."""

    PAGE_NAME_FOR_CSRF = 'profile'

    def get(self, username):
        """Handles GET requests for the publicly-viewable profile page."""
        if not username:
            raise self.PageNotFoundException

        user_settings = user_services.get_user_settings_from_username(username)

        if not user_settings:
            raise self.PageNotFoundException

        self.values.update({
            'nav_mode': feconf.NAV_MODE_PROFILE,
            'PROFILE_USERNAME': username,
        })
        self.render_template('profile/profile.html')


class ProfileHandler(base.BaseHandler):
    """Provides data for the profile page."""

    PAGE_NAME_FOR_CSRF = 'profile'

    def get(self, username):
        """Handles GET requests."""
        if not username:
            raise self.PageNotFoundException

        user_settings = user_services.get_user_settings_from_username(username)
        if not user_settings:
            raise self.PageNotFoundException

        user_contributions = user_services.get_user_contributions(
            user_settings.user_id)

        self.values.update({
            'user_bio': user_settings.user_bio,
            'first_contribution_msec': (
                user_settings.first_contribution_msec
                if user_settings.first_contribution_msec else None),
            'profile_picture_data_url': user_settings.profile_picture_data_url,
            'created_explorations_count': len(
                user_contributions.created_exploration_ids),
            'edited_explorations_count': len(
                user_contributions.edited_exploration_ids)
        })
        self.render_json(self.values)

<commit_msg>pulls appropriate viewable created and edited exploration summaries to front-end<commit_after># Copyright 2014 The Oppia Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Controllers for the profile page."""

__author__ = '<EMAIL> (<NAME>)'

from core.controllers import base
from core.domain import email_manager
from core.domain import exp_services
from core.domain import user_services
import feconf
import utils


def require_user_id_else_redirect_to_homepage(handler):
    """Decorator that checks if a user_id is associated to the current
    session. If not, the user is redirected to the main page.

    Note that the user may not yet have registered.
    """
    def test_login(self, **kwargs):
        """Checks if the user for the current session is logged in.

        If not, redirects the user to the home page.
        """
        if not self.user_id:
            self.redirect('/')
            return
        return handler(self, **kwargs)

    return test_login


class ProfilePage(base.BaseHandler):
    """The world-viewable profile page."""

    PAGE_NAME_FOR_CSRF = 'profile'

    def get(self, username):
        """Handles GET requests for the publicly-viewable profile page."""
        if not username:
            raise self.PageNotFoundException

        user_settings = user_services.get_user_settings_from_username(username)

        if not user_settings:
            raise self.PageNotFoundException

        self.values.update({
            'nav_mode': feconf.NAV_MODE_PROFILE,
            'PROFILE_USERNAME': username,
        })
        self.render_template('profile/profile.html')


class ProfileHandler(base.BaseHandler):
    """Provides data for the profile page."""

    PAGE_NAME_FOR_CSRF = 'profile'

    def get(self, username):
        """Handles GET requests."""
        if not username:
            raise self.PageNotFoundException

        user_settings = user_services.get_user_settings_from_username(username)
        if not user_settings:
            raise self.PageNotFoundException

        user_contributions = user_services.get_user_contributions(
            user_settings.user_id)

        created_exploration_summaries = (
            exp_services.get_displayable_exploration_summaries_matching_ids(
                user_contributions.created_exploration_ids))

        edited_exploration_summaries = (
            exp_services.get_displayable_exploration_summaries_matching_ids(
                user_contributions.edited_exploration_ids))

        self.values.update({
            'user_bio': user_settings.user_bio,
            'first_contribution_msec': (
                user_settings.first_contribution_msec
                if user_settings.first_contribution_msec else None),
            'profile_picture_data_url': user_settings.profile_picture_data_url,
            'created_explorations_count': len(
                user_contributions.created_exploration_ids),
            'edited_explorations_count': len(
                user_contributions.edited_exploration_ids),
            'created_exploration_summaries': created_exploration_summaries,
            'edited_exploration_summaries': edited_exploration_summaries
        })
        self.render_json(self.values)


{'fraction_non_alphanumeric': 0.07271147161066048, 'fraction_numerical': 0.002317497103128621, 'mean_word_length': 2.9322323462414577, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4863029', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1803, 'n_words': 547}