def update_label(self, label, post_data): """ Updates an item's label. Generally straightforward except for subjects """ ok = True old_label = self.manifest.label self.manifest.label = label self.manifest.save() self.manifest.revised_save() note = '' if self.manifest.item_type == 'projects': try: cobj = Project.objects.get(uuid=self.manifest.uuid) cobj.label = label cobj.save() ok = True except Project.DoesNotExist: self.errors['uuid'] = self.manifest.uuid + ' not in projects' ok = False elif self.manifest.item_type == 'subjects': # we need to adjust context paths for this subject + its children subj_gen = SubjectGeneration() subj_gen.generate_save_context_path_from_uuid(self.manifest.uuid) note = str(subj_gen.changes) + ' items affected' elif self.manifest.item_type == 'persons': # we need to adjust person's combined name try: cobj = Person.objects.get(uuid=self.manifest.uuid) cobj.combined_name = label if 'given_name' in post_data: cobj.given_name = post_data['given_name'] if 'surname' in post_data: cobj.surname = post_data['surname'] if 'initials' in post_data: cobj.initials = post_data['initials'] cobj.save() ok = True except Person.DoesNotExist: self.errors['uuid'] = self.manifest.uuid + ' not in projects' ok = False # now reindex for solr, including child items impacted by the changes sri = SolrReIndex() sri.reindex_related(self.manifest.uuid) self.response = {'action': 'update-label', 'ok': ok, 'change': {'prop': 'label', 'new': label, 'old': old_label, 'note': note}} return self.response
def update_label(self, label, post_data): """ Updates an item's label. Generally straightforward except for subjects """ ok = True note = '' old_label = self.manifest.label if 'language' in post_data: language = post_data['language'] else: language = Languages.DEFAULT_LANGUAGE if 'script' in post_data: script = post_data['script'] else: script = None if language != Languages.DEFAULT_LANGUAGE: # editing another language, not the default lan_obj = Languages() key = lan_obj.get_language_script_key(language, script) self.manifest.localized_json = lan_obj.modify_localization_json(self.manifest.localized_json, key, label) self.manifest.save() self.manifest.revised_save() else: # editing the default language self.manifest.label = label self.manifest.save() self.manifest.revised_save() # only do additional label changes in default language if self.manifest.item_type == 'projects': try: cobj = Project.objects.get(uuid=self.manifest.uuid) cobj.label = label cobj.save() ok = True except Project.DoesNotExist: self.errors['uuid'] = self.manifest.uuid + ' not in projects' ok = False elif self.manifest.item_type == 'subjects': # we need to adjust context paths for this subject + its children subj_gen = SubjectGeneration() subj_gen.generate_save_context_path_from_uuid(self.manifest.uuid) note = str(subj_gen.changes) + ' items affected' elif self.manifest.item_type == 'tables': ex_id = ExpTableIdentifiers() ex_id.make_all_identifiers(self.manifest.uuid) try: cobj = ExpTable.objects.get(table_id=ex_id.table_id) cobj.label = label cobj.save() ok = True except ExpTable.DoesNotExist: self.errors['uuid'] = ex_id.table_id + ' not in tables' ok = False elif self.manifest.item_type == 'persons': # we need to adjust person's combined name try: cobj = Person.objects.get(uuid=self.manifest.uuid) cobj.combined_name = label if 'given_name' in post_data: cobj.given_name = post_data['given_name'] if 'surname' in post_data: cobj.surname = post_data['surname'] if 'initials' in post_data: cobj.initials = post_data['initials'] if 'mid_init' in post_data: cobj.mid_init = post_data['mid_init'] cobj.save() ok = True except Person.DoesNotExist: self.errors['uuid'] = self.manifest.uuid + ' not in persons' ok = False # now reindex for solr, including child items impacted by the changes if self.manifest.item_type != 'tables' and self.edit_status > 0: if 'reindex' in post_data: sri = SolrReIndex() sri.reindex_related(self.manifest.uuid) if ok: # now clear the cache a change was made self.clear_caches() self.response = {'action': 'update-label', 'ok': ok, 'change': {'prop': 'label', 'new': label, 'old': old_label, 'note': note}} return self.response