def shop_all_items(request):
    ret = {
        'shop_brushes':
        Brush.for_shop(viewer=request.user, request=request),
        'shop_colors':
        Color.for_shop(viewer=request.user),
        'color_packs':
        ColorPack.for_shop(viewer=request.user),
        'coin_products':
        COIN_PRODUCTS,
        'brush_products':
        brush_products(request=request),
        'balance':
        economy.balance(request.user),
        'color_packs_header':
        redis.get('color_packs_header'),
        'colors_header':
        redis.get('colors_header'),
        'tabs': [
            {
                'name': 'colors',
                'default': True
            },
            {
                'name': 'coins'
            },
            {
                'name': 'brushes'
            },
        ],
    }

    return ret
def shop_all_items(request):
    ret = {
        'shop_brushes': Brush.for_shop(viewer=request.user, request=request),
        'shop_colors': Color.for_shop(viewer=request.user),
        'color_packs': ColorPack.for_shop(viewer=request.user),
        'coin_products': COIN_PRODUCTS,
        'brush_products': brush_products(request=request),
        'balance': economy.balance(request.user),
        'color_packs_header': redis.get('color_packs_header'),
        'colors_header': redis.get('colors_header'),
        'tabs': [
            {'name': 'colors', 'default': True},
            {'name': 'coins'},
            {'name': 'brushes'},
        ],
    }

    return ret
def heavy_state_sync(user, app_version=None, app_version_tuple=None, tab_last_seen_timestamps={}):
    from drawquest.apps.brushes.models import Brush
    from drawquest.apps.palettes.models import user_palettes, Color

    twitter_keys = '{}@{}'.format(settings.TWITTER_APP_KEY , settings.TWITTER_APP_SECRET)
    twitter_keys = twitter_keys[-6:] + twitter_keys[:-6]
    twitter_keys = swapcase(twitter_keys)

    ret = {
        'realtime_sync': realtime_sync(user),
        'user_palettes': user_palettes(user),
        'current_quest': current_quest_details(),
        'onboarding_quest_id': knobs.ONBOARDING_QUEST_ID,
        'sync': twitter_keys,
        'tumblr_success_regex': '''<div style="margin-bottom:10px; font-size:40px; color:#777;">Done!</div>''',
        'rewards': {
            'amounts': knobs.REWARDS,
            'copy': {
                'quest_of_the_day': _("You drew the Quest of the Day"),
                'archived_quest':   _("You drew a Quest"),
                'first_quest':      _("Woo! Your first Quest ever!"),
                'streak_3':         _("Quest Streak: 3"),
                'streak_10':        _("Quest Streak: 10"),
                'streak_100':       _("Epic! 100 straight Quests"),
            },
            'iphone_copy': {
                'archived_quest': _("You drew a Quest"),
                'first_quest': _("Your first Quest!"),
                'quest_of_the_day': _("Quest of the Day!"),
                'streak_10': _("Bonus Streak"),
                'streak_100': _("Bonus Streak"),
                'streak_3': _("Bonus Streak"),
                'personal_share': _("Shared with Facebook"),
                'personal_twitter_share': _("Shared with Twitter"),
            },
        },
        'features': {
            'invite_from_facebook': True,
            'invite_from_twitter': True,
            'user_search': True,
            'urban_airship_registration_before_auth': True,
            'urban_airship_registration': True,
        },
        'logging': {
            'on': True,
            'authentication-controller': {
                'request-for-me': False,
            },
            'facebook-controller': {
                'open-active-session-with-read-permissions': False,
                'request-new-publish-permissions': False,
                'request-new-publish-permissions-cancelled': False,
                'request-new-read-permissions': False,
                'request-new-read-permissions-cancelled': False,
            },
            'facebook-friends-coordinator': {
                'present-requests-dialog': False,
                'request-my-friends': False,
            },
            'http-request': {
                'error-auth/login_with_facebook': {
                    'mute-error-codes': {
                        '403': True,
                    }
                },
                'error-auth/login_with_twitter': {
                    'mute-error-codes': {
                        '403': True,
                    }
                },
                'error-quests/gallery_for_comment': {
                    'mute-error-codes': {
                        '404': True,
                    }
                }
            },
            'private-api': {
                'failed-activity/iphone_activities': {
                    'mute-error-codes': {
                        '1005': True,
                    }
                }
            },
            'sharing-controller': {
                'present-feed-dialog': False,
                'present-share-dialog-with-link': False,
            },
            'shop-controller': {
                'add-payment': False,
                'brush-products-request': False,
                'coin-products-request': False,
            },
            'twitter-api-manager': {
                'step-1': False,
                'step-2': False,
            },
            'twitter-controller': {
                'request-data-cursored-user-ids': False,
                'request-data-send-dm': False,
                'request-data-unknown': False,
                'request-data-users-for-ids': False,
            },
        },
        #TODO use settings.LOCALES once that's ready
        'supported_languages': ['de', 'en', 'es', 'fr', 'ja', 'ko', 'nl', 'pt', 'ru', 'th', 'zh-Hant', 'zh-Hans'],
        'l10n_files_url': None,
        'user_colors': list(Color.for_user(user)),
        'user_brushes': list(Brush.for_user(user)),
        'global_brushes': list(Brush.for_global()),
        'comment_view_logging_interval': 10,
        'papertrail': {
            'host': 'logs.papertrailapp.com',
            'port': 27889,
            'disabled_logging_points': [],
        },
        'modals': {},
    }

    if app_version_tuple and app_version_tuple >= (3,):
        ret['appirater_url'] = 'itms-apps://itunes.apple.com/app/idAPP_ID'
    else:
        ret['appirater_url'] = 'itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APP_ID'

    try:
        ret['color_alert_version'] = int(redis.get('color_alert_version'))
    except TypeError:
        ret['color_alert_version'] = 0

    if user.is_authenticated():
        user_kv_items = user.kv.hgetall()
        user_kv_items = dict((key, val) for key, val in user_kv_items.items()
                             if key in [
                                 'saw_update_modal_for_version',
                                 'saw_share_web_profile_modal',
                                 'publish_to_facebook',
                                 'publish_to_twitter',
                             ])

        ret.update({
            'user_email': user.email,
            'user_profile': user_profile(user.username),
            'balance': economy.balance(user),
            'completed_quest_ids': completed_quest_ids(user),
            'web_profile_privacy': user.kv.web_profile_privacy.get(),
            'twitter_privacy': user.kv.twitter_privacy.get(),
            'facebook_privacy': user.kv.facebook_privacy.get(),
            'user_kv': user_kv_items,
            'reminders': {
                'invite': 1,
            },
        })

        if (app_version and parse_version(knobs.CURRENT_APP_VERSION) > parse_version(app_version)):
            saw_version = user_kv_items.get('saw_update_modal_for_version')
            if (saw_version is None
                    or parse_version(saw_version) < parse_version(knobs.CURRENT_APP_VERSION)):
                ret['modals']['show_update_modal_for_version'] = knobs.CURRENT_APP_VERSION
                ret['modals']['update_modal_type'] = 'alert'

        if not user_kv_items.get('saw_share_web_profile_modal'):
            ret['modals']['show_share_web_profile_modal'] = (user.date_joined <= (datetime.now() - td(days=2))
                                                             or user.comments.count() >= 3)

    ret['tab_badge_type'] = 'flag'
    if tab_last_seen_timestamps:
        ret['tab_badges'] = tab_badges(user, last_seen_timestamps=tab_last_seen_timestamps)

    return ret
    def __init__(self, *args, **kwargs):
        super(ColorPackForm, self).__init__(*args, **kwargs)

        self.fields["colors"].label_from_instance = label_from_color_instance
        self.fields["colors"].queryset = Color.includable_in_color_pack()
def heavy_state_sync(user,
                     app_version=None,
                     app_version_tuple=None,
                     tab_last_seen_timestamps={}):
    from drawquest.apps.brushes.models import Brush
    from drawquest.apps.palettes.models import user_palettes, Color

    twitter_keys = '{}@{}'.format(settings.TWITTER_APP_KEY,
                                  settings.TWITTER_APP_SECRET)
    twitter_keys = twitter_keys[-6:] + twitter_keys[:-6]
    twitter_keys = swapcase(twitter_keys)

    ret = {
        'realtime_sync':
        realtime_sync(user),
        'user_palettes':
        user_palettes(user),
        'current_quest':
        current_quest_details(),
        'onboarding_quest_id':
        knobs.ONBOARDING_QUEST_ID,
        'sync':
        twitter_keys,
        'tumblr_success_regex':
        '''<div style="margin-bottom:10px; font-size:40px; color:#777;">Done!</div>''',
        'rewards': {
            'amounts': knobs.REWARDS,
            'copy': {
                'quest_of_the_day': _("You drew the Quest of the Day"),
                'archived_quest': _("You drew a Quest"),
                'first_quest': _("Woo! Your first Quest ever!"),
                'streak_3': _("Quest Streak: 3"),
                'streak_10': _("Quest Streak: 10"),
                'streak_100': _("Epic! 100 straight Quests"),
            },
            'iphone_copy': {
                'archived_quest': _("You drew a Quest"),
                'first_quest': _("Your first Quest!"),
                'quest_of_the_day': _("Quest of the Day!"),
                'streak_10': _("Bonus Streak"),
                'streak_100': _("Bonus Streak"),
                'streak_3': _("Bonus Streak"),
                'personal_share': _("Shared with Facebook"),
                'personal_twitter_share': _("Shared with Twitter"),
            },
        },
        'features': {
            'invite_from_facebook': True,
            'invite_from_twitter': True,
            'user_search': True,
            'urban_airship_registration_before_auth': True,
            'urban_airship_registration': True,
        },
        'logging': {
            'on': True,
            'authentication-controller': {
                'request-for-me': False,
            },
            'facebook-controller': {
                'open-active-session-with-read-permissions': False,
                'request-new-publish-permissions': False,
                'request-new-publish-permissions-cancelled': False,
                'request-new-read-permissions': False,
                'request-new-read-permissions-cancelled': False,
            },
            'facebook-friends-coordinator': {
                'present-requests-dialog': False,
                'request-my-friends': False,
            },
            'http-request': {
                'error-auth/login_with_facebook': {
                    'mute-error-codes': {
                        '403': True,
                    }
                },
                'error-auth/login_with_twitter': {
                    'mute-error-codes': {
                        '403': True,
                    }
                },
                'error-quests/gallery_for_comment': {
                    'mute-error-codes': {
                        '404': True,
                    }
                }
            },
            'private-api': {
                'failed-activity/iphone_activities': {
                    'mute-error-codes': {
                        '1005': True,
                    }
                }
            },
            'sharing-controller': {
                'present-feed-dialog': False,
                'present-share-dialog-with-link': False,
            },
            'shop-controller': {
                'add-payment': False,
                'brush-products-request': False,
                'coin-products-request': False,
            },
            'twitter-api-manager': {
                'step-1': False,
                'step-2': False,
            },
            'twitter-controller': {
                'request-data-cursored-user-ids': False,
                'request-data-send-dm': False,
                'request-data-unknown': False,
                'request-data-users-for-ids': False,
            },
        },
        #TODO use settings.LOCALES once that's ready
        'supported_languages': [
            'de', 'en', 'es', 'fr', 'ja', 'ko', 'nl', 'pt', 'ru', 'th',
            'zh-Hant', 'zh-Hans'
        ],
        'l10n_files_url':
        None,
        'user_colors':
        list(Color.for_user(user)),
        'user_brushes':
        list(Brush.for_user(user)),
        'global_brushes':
        list(Brush.for_global()),
        'comment_view_logging_interval':
        10,
        'papertrail': {
            'host': 'logs.papertrailapp.com',
            'port': 27889,
            'disabled_logging_points': [],
        },
        'modals': {},
    }

    if app_version_tuple and app_version_tuple >= (3, ):
        ret['appirater_url'] = 'itms-apps://itunes.apple.com/app/idAPP_ID'
    else:
        ret['appirater_url'] = 'itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APP_ID'

    try:
        ret['color_alert_version'] = int(redis.get('color_alert_version'))
    except TypeError:
        ret['color_alert_version'] = 0

    if user.is_authenticated():
        user_kv_items = user.kv.hgetall()
        user_kv_items = dict((key, val) for key, val in user_kv_items.items()
                             if key in [
                                 'saw_update_modal_for_version',
                                 'saw_share_web_profile_modal',
                                 'publish_to_facebook',
                                 'publish_to_twitter',
                             ])

        ret.update({
            'user_email': user.email,
            'user_profile': user_profile(user.username),
            'balance': economy.balance(user),
            'completed_quest_ids': completed_quest_ids(user),
            'web_profile_privacy': user.kv.web_profile_privacy.get(),
            'twitter_privacy': user.kv.twitter_privacy.get(),
            'facebook_privacy': user.kv.facebook_privacy.get(),
            'user_kv': user_kv_items,
            'reminders': {
                'invite': 1,
            },
        })

        if (app_version and parse_version(knobs.CURRENT_APP_VERSION) >
                parse_version(app_version)):
            saw_version = user_kv_items.get('saw_update_modal_for_version')
            if (saw_version is None or parse_version(saw_version) <
                    parse_version(knobs.CURRENT_APP_VERSION)):
                ret['modals'][
                    'show_update_modal_for_version'] = knobs.CURRENT_APP_VERSION
                ret['modals']['update_modal_type'] = 'alert'

        if not user_kv_items.get('saw_share_web_profile_modal'):
            ret['modals']['show_share_web_profile_modal'] = (
                user.date_joined <= (datetime.now() - td(days=2))
                or user.comments.count() >= 3)

    ret['tab_badge_type'] = 'flag'
    if tab_last_seen_timestamps:
        ret['tab_badges'] = tab_badges(
            user, last_seen_timestamps=tab_last_seen_timestamps)

    return ret
    def __init__(self, *args, **kwargs):
        super(ColorPackForm, self).__init__(*args, **kwargs)

        self.fields['colors'].label_from_instance = label_from_color_instance
        self.fields['colors'].queryset = Color.includable_in_color_pack()