コード例 #1
0
    def update(cls, args):
        """ Update banner
        """
        banner = banner_client.get(args['id'])
        banner_dict = ttype2dict(banner)
        banner_dict.update(args)

        #is_valid is int,but update is ok

        if banner_dict.get('cities') \
                or banner_dict.get('region_groups'):
                # or banner_dict.get('regions'): TODO name conflict with keeper
            regions = cls._region_list2map(banner_dict.pop('cities'),
                                            banner_dict.pop('region_groups'),
                                            banner_dict.pop('regions'))
            banner_dict['regions'] = regions

        b_type = banner.type
        if b_type == banner_client.banner_type.NON_INTERACTIVE:
            banner_client.update_non_interactive_banner(banner_dict)
        if b_type == banner_client.banner_type.LINK:
            banner_client.update_link_banner(banner_dict)
        if b_type == banner_client.banner_type.ACTIVITY:
            banner_client.update_activity_banner(banner_dict)

        return ''
コード例 #2
0
    def get(cls, id):
        banner = banner_client.get(id)

        # assemble file url
        obj_hash2url(banner, 'image_hash', set_null=False)
        obj_hash2url(banner, 'activity_image_hash', set_null=False)

        cities, region_groups, regions = cls._region_map2list(banner.regions)
        setattr(banner, 'cities', cities)
        setattr(banner, 'region_groups', region_groups)
        setattr(banner, 'regions', regions)
        setattr(banner, 'modify_enabled', cls._get_modify_permission(id))

        return banner
コード例 #3
0
    def _get_modify_permission(cls, banner_id):
        banner = banner_client.get(banner_id)
        if not banner:
            raise_user_exc(BANNER_NOT_EXISTS_ERR, banner_id=banner_id)

        banner_regions = banner.regions
        if not banner_regions or not banner_regions.keys():
            return True

        banner_city_ids = banner_regions.keys()

        if current_user.has_groups(['activity_manager', 'marketing_manager']):
            return True
        elif current_user.has_groups(['city_director']):
            user_city_ids = city_base.get_city_ids_by_user()
            return all([banner_city_id in user_city_ids
                        for banner_city_id in banner_city_ids])

        return False