def save(self): c_name = self.c_name key = self.username if dataset.key_exists(c_name, key): err = dataset.update(c_name, key, self) if err != '': return False else: err = dataset.create(c_name, key, self) if err != '': return False return True
def people_new(): if current_user.is_authenticated == False: flash(f'Must be logged in to curate people') return redirect(url_for('index')) form = PeopleForm() if form.validate_on_submit(): people = People() people.cl_people_id = form.cl_people_id.data people.family_name = form.family_name.data people.given_name = form.given_name.data people.thesis_id = form.thesis_id.data people.authors_id = form.authors_id.data people.archivesspace_id = form.archivesspace_id.data people.directory_id = form.directory_id.data people.viaf = form.viaf.data people.lcnaf = form.lcnaf.data people.isni = form.isni.data people.wikidata = form.wikidata.data people.snac = form.snac.data people.orcid = form.orcid.data people.image = form.image.data people.educated_at = form.educated_at.data people.caltech = form.caltech.data people.jpl = form.jpl.data people.faculty = form.faculty.data people.alumn = form.alumn.data people.notes = form.notes.data c_name = cfg.OBJECTS key = people.cl_people_id now = datetime.now() if dataset.key_exists(c_name, key): err = dataset.update(c_name, key, people.to_dict()) if err != '': flash(f'WARNING: failed to update {key} in {c_name}, {err}') else: flash(f'{people.cl_people_id} updated {now}') else: err = dataset.create(c_name, key, people.to_dict()) if err != '': flash(f'WARNING: failed to create {key} in {c_name}, {err}') else: flash(f'{people.cl_people_id} created {now}') return redirect( url_for('people_edit', cl_people_id=people.cl_people_id)) return render_template('people_edit.html', title="New People", user=current_user, form=form)
def create_role(argv): c_name = cfg.ROLES if len(argv) != 1: usage_create_role() return False role_name = argv[0] if dataset.key_exists(c_name, role_name): print(f'{role_name} already exists in {c_name}') return False role = { f'{cfg.USERS}': { 'create': False, 'read': False, 'update': False, 'delete': False }, f'{cfg.ROLES}': { 'create': False, 'read': False, 'update': False, 'delete': False }, f'{cfg.OBJECTS}': { 'create': False, 'read': False, 'update': False, 'delete': False }, } for c_name in [cfg.USERS, cfg.ROLES, cfg.OBJECTS]: print(f'Collection {c_name}') perms = role[c_name] for perm in ['create', 'read', 'update', 'delete']: y_or_n = input(f'allow {perm}? [Y/n] ').lower() if y_or_n in ['y', 'yes']: role[c_name][perm] = True else: role[c_name][perm] = False c_name = cfg.ROLES err = dataset.create(c_name, role_name, role) if err != '': print(f'ERROR: {err}') return False return True
def NewUser(username, email, display_name): '''NewUser create a new user in cfg.USERS, then returns a new User().''' c_name = cfg.USERS user = { 'c_name': c_name, 'id': username, 'username': username, 'display_name': display_name, 'email': email, 'role': '', 'password': '' } if dataset.key_exists(c_name, username): return None err = dataset.create(c_name, username, user) if err != '': return None u = User(username) return u
def add_user(argv): c_name = cfg.USERS if len(argv) != 3: usage_add_user() return False username, email, display_name = argv[0], argv[1], argv[2] if dataset.key_exists(c_name, username) == True: print(f'{username} already exists in {c_name}') return False user = { 'id': username, 'username': username, 'email': email, 'display_name': display_name, } err = dataset.create(c_name, username, user) if err != '': return False print(f'NOTE: {username} will need to have a role and password set.') return True
err = dataset.init(c_name) if err != "": print(f"expected '', got '{err}' for dataset.init({c_name})") sys.exit(1) src = ''' [ {"_Key": "k1", "title": "One thing", "name": "Fred"}, {"_Key": "k2", "title": "Two things", "name": "Frieda"}, {"_Key": "k3", "title": "Three things", "name": "Fiona"} ] ''' for obj in json.loads(src): key = obj['_Key'] err = dataset.create(c_name, key, obj) if err != '': print( f"expected '', got '{err}' for dataset.create({c_name}, {_key}, {obj})" ) sys.exit(1) expected_keys = ["k1", "k2", "k3"] keys = dataset.keys(c_name) i = 0 for key in keys: if not key in expected_keys: print(f"expected {key} in {expected_keys} for {c_name}") sys.exit(1) obj, err = dataset.read(c_name, key) if err != '':
"cl_people_id", "family_name", "given_name", "thesis_id", "authors_id", "archivesspace_id", "directory_id", "viaf", "lcnaf", "isni", "wikidata", "snac", "orcid", "image", "educated_at", "caltech", "jpl", "faculty", "alumn", "notes" ]: obj2[attr2] = '' for attr1 in obj1: attr2 = attr1.lower().replace(' ', '_').replace('(', '').replace( ')', '') if attr2 in [ "cl_people_id", "family_name", "given_name", "thesis_id", "authors_id", "archivesspace_id", "directory_id", "viaf", "lcnaf", "isni", "wikidata", "snac", "orcid", "image", "educated_at", "caltech", "jpl", "faculty", "alumn", "notes" ]: if attr2 in ['caltech', 'alumn', 'jpl', 'faculty']: obj2[attr2] = True if obj1[attr1] == '': obj2[attr2] = False elif obj1[attr1]: obj2[attr2] = obj1[attr1] if dataset.key_exists(c_name2, key): err = dataset.update(c_name2, key, obj2) else: err = dataset.create(c_name2, key, obj2) if err != '': print(f'WARNING: write failed, {key} in {c_name2}, {err}')