12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- # -*- coding: utf-8 -*-
- #!/usr/bin/env python
- """
- 更改agentIncomeReport 字段名,为了与其他model统一使用query 对象
- """
- import os
- import sys
- from bson.objectid import ObjectId
- #: 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.agent.models import AgentIncomeReport
- agentIncomeReportCollection = AgentIncomeReport.get_collection()
- reports = agentIncomeReportCollection.find({'createdTime': {'$ne': ''}})
- if not reports: print 'no reports to operate on'
- for report in reports:
- print 'updating report=%s' % (str(report['_id']),)
- updated0 = agentIncomeReportCollection.update({'_id': ObjectId(report['_id'])},
- {'$set': {'dateTimeAdded': report['createdTime']}})
- assert updated0, 'updated0 failed, report=%s' % (str(report['_id']),)
- updated1 = agentIncomeReportCollection.update({'_id': ObjectId(report['_id'])},
- {'$unset': {'createdTime': ''}})
- assert updated1, 'updated1 failed, report=%s' % (str(report['_id']),)
- print 'finished!'
|