upgrade_dealer_features_20180910.py 1.6 KB

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