Exemple #1
0
    def get(self):

        logging.info("Warmup: loading homepage html")
        library.library_content_html()

        logging.info("Warmup: loading badges")
        util_badges.all_badges()
        util_badges.all_badges_dict()
Exemple #2
0
    def get(self):
        if App.is_dev_server:
            logging.info("Warmup: deleting caches")
            from google.appengine.ext import blobstore
            from google.appengine.ext import db
            for k in blobstore.BlobInfo.all():
                logging.info(" -- %s", k.key())
                k.delete()

        logging.info("Warmup: loading homepage html")
        library.library_content_html()

        logging.info("Warmup: loading badges")
        util_badges.all_badges()
        util_badges.all_badges_dict()
Exemple #3
0
def get_badge_activity_data(user_data, bucket_list, bucket_type, dt_start_utc, dt_end_utc, tz_offset):

    dict_bucket = get_empty_dict_bucket(bucket_list)
    user_badges = models_badges.UserBadge.get_for_user_data_between_dts(user_data, dt_start_utc, dt_end_utc).fetch(1000)
    badges_dict = util_badges.all_badges_dict()

    for user_badge in user_badges:
        key = get_bucket_value(user_badge.date, tz_offset, bucket_type)

        badge = badges_dict.get(user_badge.badge_name)
        if not badge:
            continue

        if not dict_bucket.has_key(key):
            continue

        if not dict_bucket[key]:
            dict_bucket[key] = {"points": 0, "badge_category": -1, "badge_url": "", "badge_descriptions": {}}

        dict_bucket[key]["points"] += user_badge.points_earned
        dict_bucket[key]["badge_descriptions"][badge.description] = True

        if badge.badge_category > dict_bucket[key]["badge_category"]:
            dict_bucket[key]["badge_url"] = badge.chart_icon_src()
            dict_bucket[key]["badge_category"] = badge.badge_category

    add_bucket_html_summary(dict_bucket, "badge_descriptions", 3)

    return dict_bucket
def get_badge_activity_data(user_data, bucket_list, bucket_type, dt_start_utc, dt_end_utc, tz_offset):

    dict_bucket = get_empty_dict_bucket(bucket_list)
    user_badges = models_badges.UserBadge.get_for_user_data_between_dts(user_data, dt_start_utc, dt_end_utc).fetch(1000)
    badges_dict = util_badges.all_badges_dict()

    for user_badge in user_badges:
        key = get_bucket_value(user_badge.date, tz_offset, bucket_type)

        badge = badges_dict.get(user_badge.badge_name)
        if not badge:
            continue

        if not dict_bucket.has_key(key):
            continue;

        if not dict_bucket[key]:
            dict_bucket[key] = {"points": 0, "badge_category": -1, "badge_url": "", "badge_descriptions": {}}

        dict_bucket[key]["points"] += user_badge.points_earned
        dict_bucket[key]["badge_descriptions"][badge.description] = True

        if badge.badge_category > dict_bucket[key]["badge_category"]:
            dict_bucket[key]["badge_url"] = badge.chart_icon_src()
            dict_bucket[key]["badge_category"] = badge.badge_category

    add_bucket_html_summary(dict_bucket, "badge_descriptions", 3)

    return dict_bucket
Exemple #5
0
def recent_badge_activity(user_badges):
    badges_dict = util_badges.all_badges_dict()
    list_badge_activity = []

    for user_badge in user_badges:
        badge = badges_dict.get(user_badge.badge_name)
        if badge:
            list_badge_activity.append(RecentBadgeActivity(user_badge, badge))

    return list_badge_activity
def recent_badge_activity(user_badges):
    badges_dict = util_badges.all_badges_dict()
    list_badge_activity = []

    for user_badge in user_badges:
        badge = badges_dict.get(user_badge.badge_name)
        if badge:
            list_badge_activity.append(RecentBadgeActivity(user_badge, badge))

    return list_badge_activity
Exemple #7
0
def recent_badge_activity(user, dt_start, dt_end):

    badges_dict = util_badges.all_badges_dict()

    list_badge_activity = []
    user_badges = models_badges.UserBadge.get_for_user_between_dts(user, dt_start, dt_end)

    for user_badge in user_badges:
        badge = badges_dict.get(user_badge.badge_name)
        if badge:
            list_badge_activity.append(RecentBadgeActivity(user_badge, badge))

    return list_badge_activity
Exemple #8
0
def add_action_results(obj, dict_results):

    badges_earned = []
    user_data = models.UserData.current()

    if user_data:
        dict_results["user_data"] = user_data

        dict_results["user_info_html"] = templatetags.user_info(
            user_data.nickname, user_data)

        user_notifications_dict = notifications.UserNotifier.pop_for_user_data(
            user_data)

        # Add any new badge notifications
        user_badges = user_notifications_dict["badges"]
        if len(user_badges) > 0:
            badges_dict = util_badges.all_badges_dict()

            for user_badge in user_badges:
                badge = badges_dict.get(user_badge.badge_name)

                if badge:

                    if not hasattr(badge, "user_badges"):
                        badge.user_badges = []

                    badge.user_badges.append(user_badge)
                    badge.is_owned = True
                    badges_earned.append(badge)

        if len(badges_earned) > 0:
            dict_results["badges_earned"] = badges_earned
            dict_results["badges_earned_html"] = badge_notifications_html(
                user_badges)

        # Add any new login notifications for phantom users
        login_notifications = user_notifications_dict["login"]
        if len(login_notifications) > 0:
            dict_results[
                "login_notifications_html"] = login_notifications_html(
                    login_notifications, user_data)

    obj.action_results = dict_results
Exemple #9
0
def badges_list():
    badges_dict = util_badges.all_badges_dict()

    user_data = models.UserData.current()
    if user_data:

        user_data_student = get_visible_user_data_from_request()
        if user_data_student:

            user_badges = models_badges.UserBadge.get_for(user_data_student)

            for user_badge in user_badges:

                badge = badges_dict.get(user_badge.badge_name)

                if badge:
                    if not hasattr(badge, "user_badges"):
                        badge.user_badges = []
                    badge.user_badges.append(user_badge)
                    badge.is_owned = True

    return sorted(filter(lambda badge: not badge.is_hidden(), badges_dict.values()), key=lambda badge: badge.name)
Exemple #10
0
def add_action_results(obj, dict_results):

    badges_earned = []
    user_data = models.UserData.current()

    if user_data:
        dict_results["user_data"] = user_data

        dict_results["user_info_html"] = templatetags.user_info(user_data.nickname, user_data)

        user_notifications_dict = notifications.UserNotifier.pop_for_user_data(user_data)

        # Add any new badge notifications
        user_badges = user_notifications_dict["badges"]
        if len(user_badges) > 0:
            badges_dict = util_badges.all_badges_dict()

            for user_badge in user_badges:
                badge = badges_dict.get(user_badge.badge_name)

                if badge:

                    if not hasattr(badge, "user_badges"):
                        badge.user_badges = []

                    badge.user_badges.append(user_badge)
                    badge.is_owned = True
                    badges_earned.append(badge)

        if len(badges_earned) > 0:
            dict_results["badges_earned"] = badges_earned
            dict_results["badges_earned_html"] = badge_notifications_html(user_badges)

        # Add any new login notifications for phantom users
        login_notifications = user_notifications_dict["login"]
        if len(login_notifications) > 0:
            dict_results["login_notifications_html"] = login_notifications_html(login_notifications, user_data)

    obj.action_results = dict_results
Exemple #11
0
def badges_list():
    badges_dict = util_badges.all_badges_dict()

    user_data = models.UserData.current()
    if user_data:

        user_data_student = get_visible_user_data_from_request()
        if user_data_student:

            user_badges = models_badges.UserBadge.get_for(user_data_student)

            for user_badge in user_badges:

                badge = badges_dict.get(user_badge.badge_name)

                if badge:
                    if not hasattr(badge, "user_badges"):
                        badge.user_badges = []
                    badge.user_badges.append(user_badge)
                    badge.is_owned = True

    return sorted(filter(lambda badge: not badge.is_hidden(),
                         badges_dict.values()),
                  key=lambda badge: badge.name)