def handle(self, *args, **options): for database_name in document_stores_to_process(args): manager = get_db_manager(database_name) print ("Database %s") % (database_name) print "Syncing....." initializer.run(manager) print "Done."
def migrate_01(managers, map_fun_project_docs, map_fun_raw_form_model_docs, map_fun_submission_docs): for manager in managers: initializer.run(manager) submissions = manager.database.query(map_fun_submission_docs) for submission in submissions: document = submission.key document['event_time'] = document['created'] if 'voided' in document: document.pop('voided') manager.database.save(document) raw_submissions = manager.database.query(map_fun_raw_submission_docs) for submission in raw_submissions: manager.database.delete(submission.key) projects = manager.database.query(map_fun_project_docs) for project in projects: document = project.key document['language'] = 'en' document['data_senders'] = [] document['reminder_and_deadline'] = { "frequency_enabled": "False", "reminders_enabled": "False" } manager.database.save(document) form_models = manager.database.query(map_fun_raw_form_model_docs) for form_model in form_models: document = form_model.key if document['form_code'] == 'reg': continue document['label']['en'] = document['label']['eng'] del document['label']['eng'] document['metadata']['activeLanguages'] = ["en"] for index, json_field in enumerate(document['json_fields']): json_field['label']['en'] = json_field['label']['eng'] del json_field['label']['eng'] json_field['required'] = False if json_field['type'] == 'integer': range = json_field['range'] del json_field['range'] json_field['constraints'] = [['range', range]] if json_field['type'] == 'text': length = json_field['length'] del json_field['length'] json_field['constraints'] = [['length', length]] json_field['required'] = json_field.get( 'entity_question_flag', False) if (json_field['type'] == 'select') | (json_field['type'] == 'select1'): for i, choice in enumerate(json_field['choices']): choice['text']['en'] = choice['text']['eng'] del choice['text']['eng'] choice['val'] = chr(i + 97) json_field['choices'][i] = choice document['json_fields'][index] = json_field manager.database.save(document)
def create_org_database(db_name): from datawinners.initializer import run from datawinners.main.database import get_db_manager manager = get_db_manager(db_name) assert manager, "Could not create database manager for %s " % (db_name,) create_search_index(db_name) run(manager) return manager
def handle(self, *args, **options): if "syncall" in args: managers = load_all_managers() else: managers = load_test_managers() for manager in managers: print("Database %s") % (manager.database_name, ) print "Syncing....." initializer.run(manager) print "Done."
def handle(self, *args, **options): managers = [] if "syncall" in args: managers = load_all_managers() else: manager = load_manager_for_default_test_account() managers.append(manager) for manager in managers: print("Database %s") % (manager.database_name, ) print "Syncing....." initializer.run(manager) print "Done."
def handle(self, *args, **options): managers = [] if "syncall" in args: managers = load_all_managers() else: manager = load_manager_for_default_test_account() managers.append(manager) for manager in managers: print ("Database %s") % (manager.database_name,) print "Syncing....." initializer.run(manager) print "Done."
def create_org_database(sender, user, request, **kwargs): from datawinners.initializer import run profile = user.get_profile() org = Organization.objects.get(org_id=profile.org_id) if org is None: return None org_settings = OrganizationSetting.objects.get(organization=org) db_name = org_settings.document_store # Explicitly create the new database. Should fail it db already exists. server = couchdb.client.Server(datawinners.settings.COUCH_DB_SERVER) server.create(db_name) manager = get_db_manager(server=datawinners.settings.COUCH_DB_SERVER, database=db_name) assert manager, "Could not create database manager for %s " % (db_name,) run(manager)
def create_org_database(sender, user, request, **kwargs): from datawinners.initializer import run profile = user.get_profile() org = Organization.objects.get(org_id=profile.org_id) if org is None: return None org_settings = OrganizationSetting.objects.get(organization=org) db_name = org_settings.document_store # Explicitly create the new database. Should fail it db already exists. server = couchdb.client.Server(datawinners.settings.COUCH_DB_SERVER) server.create(db_name) manager = get_db_manager(server=datawinners.settings.COUCH_DB_SERVER, database=db_name) assert manager, "Could not create database manager for %s " % (db_name, ) run(manager)
def create_org_database(sender, user, request, **kwargs): from datawinners.initializer import run profile = user.get_profile() org = Organization.objects.get(org_id=profile.org_id) active_organization(org) org_settings = OrganizationSetting.objects.get(organization=org) db_name = org_settings.document_store # Explicitly create the new database. Should fail it db already exists. manager = get_db_manager(server=settings.COUCH_DB_SERVER, database=db_name) assert manager, "Could not create database manager for %s " % (db_name, ) run(manager) profile.reporter_id = make_user_as_a_datasender(manager, org, user.get_full_name(), profile.mobile_phone) profile.save()
def migrate_01(managers, map_fun_raw_form_model_docs): failed_managers = [] for manager in managers: try: print manager.database print manager print 'running initializer' initializer.run(manager) print 'syncing form models' form_models = manager.database.query(map_fun_raw_form_model_docs) for form_model in form_models: document = form_model.key language = document['metadata']['activeLanguages'][0] if document['form_code'] == 'reg': document['metadata']['activeLanguages'] = ["en"] document['is_registration_model'] = True document["validators"] = [ {"cls": "mandatory"}, {"cls": "mobile_number_mandatory_for_reporter"}, {"cls": "at_least_one_location_field_must_be_answered_validator"} ] else: document['is_registration_model'] = False for index, json_field in enumerate(document['json_fields']): json_field['label'] = json_field['name'] document['json_fields'][index] = json_field document["validators"] = [{"cls": "mandatory"}] manager.database.save(document) print 'syncing entity reg forms' entity_types = get_all_entity_types(manager) # django.core.management.base forces the locale to en-us. translation.activate('en') for entity_type in entity_types: if entity_type != ['reporter']: create_registration_form(manager, entity_type) print "done for %s"%(manager,) except Exception as e: failed_managers.append((manager,e.message)) print 'failed managers if any' for manager,exception_mesage in failed_managers: print " %s failed. the reason : %s" %(manager,exception_mesage)
def load_data(): manager = load_manager_for_default_test_account() initializer.run(manager) CLINIC_ENTITY_TYPE = [u"clinic"] WATER_POINT_ENTITY_TYPE = [u"waterpoint"] create_entity_types(manager, [CLINIC_ENTITY_TYPE, WATER_POINT_ENTITY_TYPE]) load_datadict_types(manager) load_clinic_entities(CLINIC_ENTITY_TYPE, manager) load_waterpoint_entities(WATER_POINT_ENTITY_TYPE, manager) create_clinic_projects(CLINIC_ENTITY_TYPE, manager) #Register Reporter phone_number_type = create_data_dict(manager, name='Telephone Number', slug='telephone_number', primitive_type='string') first_name_type = create_data_dict(manager, name='First Name', slug='first_name', primitive_type='string') register(manager, entity_type=REPORTER_ENTITY_TYPE, data=[(MOBILE_NUMBER_FIELD, "1234567890", phone_number_type), (NAME_FIELD, "Shweta", first_name_type)], location=[u'Madagascar', u'Toliary', u'Menabe', u'Mahabo', u'Beronono'], short_code="rep1") register(manager, entity_type=REPORTER_ENTITY_TYPE, data=[(MOBILE_NUMBER_FIELD, "261332592634", phone_number_type), (NAME_FIELD, "David", first_name_type)], location=[u'Madagascar', u'Fianarantsoa', u'Haute matsiatra', u'Ambohimahasoa', u'Camp Robin'], short_code="rep2") load_sms_data_for_cli001(manager)
def load_data(): manager = load_manager_for_default_test_account() initializer.run(manager) CLINIC_ENTITY_TYPE = [u"clinic"] WATER_POINT_ENTITY_TYPE = [u"waterpoint"] create_entity_types(manager, [CLINIC_ENTITY_TYPE, WATER_POINT_ENTITY_TYPE]) load_datadict_types(manager) load_clinic_entities(CLINIC_ENTITY_TYPE, manager) load_waterpoint_entities(WATER_POINT_ENTITY_TYPE, manager) create_clinic_projects(CLINIC_ENTITY_TYPE, manager) #Register Reporter phone_number_type = create_data_dict(manager, name='Telephone Number', slug='telephone_number', primitive_type='string') first_name_type = create_data_dict(manager, name='First Name', slug='first_name', primitive_type='string') register(manager, entity_type=REPORTER_ENTITY_TYPE, data=[(MOBILE_NUMBER_FIELD, "1234567890", phone_number_type), (NAME_FIELD, "Shweta", first_name_type)], location=[ u'Madagascar', u'Toliary', u'Menabe', u'Mahabo', u'Beronono' ], short_code="rep1") register(manager, entity_type=REPORTER_ENTITY_TYPE, data=[(MOBILE_NUMBER_FIELD, "261332592634", phone_number_type), (NAME_FIELD, "David", first_name_type)], location=[ u'Madagascar', u'Fianarantsoa', u'Haute matsiatra', u'Ambohimahasoa', u'Camp Robin' ], short_code="rep2") load_sms_data_for_cli001(manager)