# -*- coding: utf-8 -*- # !/usr/bin/env python """ """ import os import sys #: current_dir - 2 PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..') sys.path.insert(0, PROJECT_ROOT) from script.base import init_env, get_logger logger = get_logger(__name__) init_env(interactive=True) from apps.web.dealer.models import Dealer from apps.web.agent.models import Agent from apps.web.common.models import Feature from apps.web.superadmin.models import SuperManager rsd_manager_id = '5abc5f5c4864d0265c654cb0' def add_limitAdLocationFeature(): limitAdLocationFeature = Feature.objects(name='limitAdLocation',role='dealer').first() if not limitAdLocationFeature: limitAdLocationFeature = Feature(name='limitAdLocation', role='dealer', managerId=rsd_manager_id, by=str(SuperManager.objects().first().id), description=u'部分经销商需要限制广告地理信息,此举动会一定程度导致粉丝量下降').save() agent_ids = ( str(_.id) for _ in Agent.objects(managerId=rsd_manager_id).only('id')) for dealer in Dealer.objects(agentId__in=agent_ids): d = dealer # type: Dealer updated = d.update(push__features=limitAdLocationFeature.name) if not updated: logger.error('update didn\'t succeed, {0}'.format(d)) logger.info('add_limitAdLocationFeature finished!') if __name__ == '__main__': add_limitAdLocationFeature()