def run(self): frameworks = request_with_auth(get_source_url('entry-templates', 'v1')) if not frameworks: print('Couldn\'t find AF data at') with reversion.create_revision(): for framework in frameworks: self.import_framework(framework)
def run(self): projects = request_with_auth(get_source_url('events2', 'v1')) if not projects: print('Couldn\'t find projects data') with reversion.create_revision(): for project in projects: self.import_project(project)
def run(self): data = request_with_auth(get_source_url('leads')) if not data or not data.get('data'): print('Couldn\'t find leads data') leads = data['data'] with reversion.create_revision(): for lead in leads: self.import_lead(lead)
def run(self): entries = request_with_auth( get_source_url('entries', query='template=1', version='v1')) if not entries: print('Couldn\'t find entries data') with reversion.create_revision(): for entry in entries: self.import_entry(entry)
def run(self): data = requests.get(get_source_url('countries')).json() if not data or not data.get('data'): print('Couldn\'t find countries data') return countries = data['data'] for country in countries: self.import_country(country)
def run(self): if self.kwargs.get('data_file'): with open(self.kwargs['data_file']) as f: data = json.load(f) else: data = requests.get(get_source_url('users2', 'v1')).json() if not data: print('Couldn\'t find users data') return for user in data: self.import_user(user)
def run(self): if self.kwargs.get('data_file'): with open(self.kwargs['data_file']) as f: projects = json.load(f) else: projects = request_with_auth(get_source_url('events2', 'v1')) if not projects: print('Couldn\'t find projects data') with reversion.create_revision(): for project in projects: self.import_project(project)
def run(self): if self.kwargs.get('data_file'): with open(self.kwargs['data_file']) as f: user_groups = json.load(f) else: user_groups = request_with_auth(get_source_url( 'user-groups', 'v1')) if not user_groups: print('Couldn\'t find user groups data') with reversion.create_revision(): for user_group in user_groups: self.import_user_group(user_group)
def run(self): if self.kwargs.get('data_file'): with open(self.kwargs['data_file']) as f: entries = json.load(f) else: entries = request_with_auth( get_source_url('entries', query='template=1', version='v1')) if not entries: print('Couldn\'t find entries data') with reversion.create_revision(): for entry in entries: self.import_entry(entry)
def run(self): if self.kwargs.get('data_file'): with open(self.kwargs['data_file']) as f: frameworks = json.load(f) else: query = self.kwargs.get('query_str', '') frameworks = request_with_auth( get_source_url('entry-templates', 'v1', query)) if not frameworks: print('Couldn\'t find AF data at') with reversion.create_revision(): new_frameworks_file = open('new_afs.txt', 'a') for framework in frameworks: self.import_framework(framework, new_frameworks_file) new_frameworks_file.close()
AnalysisFrameworkMigration, ProjectMigration, UserMigration, ) from analysis_framework.models import ( AnalysisFramework, Widget, Exportable, Filter, ) import reversion import re ENTRY_TEMPLATES_URL = get_source_url('entry-templates', 'v1') def get_user(old_user_id): migration = UserMigration.objects.filter(old_id=old_user_id).first() return migration and migration.user def get_project(project_id): migration = ProjectMigration.objects.filter(old_id=project_id).first() return migration and migration.project def snap(x, default=16): if isinstance(x, str): x = int(re.sub(r'[^\d-]+', '', x))
from django.contrib.auth.models import User from django.core.management.base import BaseCommand import requests from deep_migration.utils import ( get_source_url, get_migrated_gallery_file, ) from deep_migration.models import UserMigration USERS_URL = get_source_url('users2', 'v1') class Command(BaseCommand): def handle(self, *args, **kwargs): data = requests.get(USERS_URL).json() if not data: print('Couldn\'t find users data at {}'.format(USERS_URL)) return for user in data: self.import_user(user) def import_user(self, data): print('------------') print('Migrating user') old_id = data['id'] username = data['username']
get_migrated_gallery_file, ) from geo.models import ( Region, AdminLevel, ) from deep_migration.models import ( CountryMigration, AdminLevelMigration, ) from geo.tasks import load_geo_areas COUNTRIES_URL = get_source_url('countries') class Command(BaseCommand): def handle(self, *args, **kwargs): data = requests.get(COUNTRIES_URL).json() if not data or not data.get('data'): print('Couldn\'t find countries data at {}'.format(COUNTRIES_URL)) return countries = data['data'] for country in countries: self.import_country(country) def import_country(self, country):
from django.core.management.base import BaseCommand from deep_migration.utils import ( get_source_url, request_with_auth, ) from deep_migration.models import ( CountryMigration, ProjectMigration, UserMigration, ) from project.models import Project, ProjectMembership import reversion EVENTS_URL = get_source_url('events2', 'v1') def get_user(old_user_id): migration = UserMigration.objects.filter(old_id=old_user_id).first() return migration and migration.user def get_region(reference_code): migration = CountryMigration.objects.filter(code=reference_code).first() return migration and migration.region class Command(BaseCommand): def handle(self, *args, **kwargs): projects = request_with_auth(EVENTS_URL)
from deep_migration.utils import ( get_source_url, request_with_auth, get_migrated_gallery_file, ) from deep_migration.models import ( LeadMigration, ProjectMigration, UserMigration, ) from lead.models import Lead import reversion LEADS_URL = get_source_url('leads') def get_user(old_user_id): migration = UserMigration.objects.filter(old_id=old_user_id).first() return migration and migration.user def get_project(project_id): migration = ProjectMigration.objects.filter(old_id=project_id).first() return migration and migration.project CONFIDENTIALITY_MAP = { 'UNP': Lead.UNPROTECTED, 'PRO': Lead.PROTECTED,