def entity_change (request, topic_map, entity_id): entity = get_topic_or_404(Entity, entity_id) editor = request.user.eats_user context_data = {'entity': entity} authority = editor.get_current_authority() editable_authorities = editor.editable_authorities.all() authority_data = {'current_authority': authority.get_id()} entity_data = None if request.method == 'POST': if '_change_authority' in request.POST: authority_data = request.POST else: entity_data = request.POST current_authority_form = CurrentAuthorityForm( topic_map, editable_authorities, authority_data) existences = ExistencePropertyAssertions(topic_map, entity, authority, entity_data) entity_types = EntityTypePropertyAssertions(topic_map, entity, authority, entity_data) names = NamePropertyAssertions(topic_map, entity, authority, entity_data) notes = NotePropertyAssertions(topic_map, entity, authority, entity_data) entity_relationships = EntityRelationshipPropertyAssertions( topic_map, entity, authority, entity_data) subject_identifiers = SubjectIdentifierPropertyAssertions( topic_map, entity, authority, entity_data) existences_formset = existences.formset entity_types_formset = entity_types.formset names_formset = names.formset notes_formset = notes.formset entity_relationships_formset = entity_relationships.formset subject_identifiers_formset = subject_identifiers.formset if request.method == 'POST': redirect_url = reverse('entity-change', kwargs={'entity_id': entity_id}) if '_change_authority' in request.POST: if current_authority_form.is_valid(): authority_id = current_authority_form.cleaned_data[ 'current_authority'] authority = Authority.objects.get_by_identifier(authority_id) editor.set_current_authority(authority) return HttpResponseRedirect(redirect_url) else: formsets = (existences_formset, entity_types_formset, names_formset, notes_formset, entity_relationships_formset, subject_identifiers_formset) is_valid = False for formset in formsets: is_valid = formset.is_valid() if not is_valid: break if is_valid: for formset in formsets: formset.save() return HttpResponseRedirect(redirect_url) context_data['current_authority_form'] = current_authority_form context_data['existence_non_editable'] = existences.non_editable context_data['existence_formset'] = existences_formset context_data['entity_type_non_editable'] = entity_types.non_editable context_data['entity_type_formset'] = entity_types_formset context_data['name_non_editable'] = names.non_editable context_data['name_formset'] = names_formset context_data['note_formset'] = notes_formset context_data['note_non_editable'] = notes.non_editable context_data['entity_relationship_formset'] = entity_relationships_formset context_data['entity_relationship_non_editable'] = entity_relationships.non_editable context_data['subject_identifier_formset'] = subject_identifiers_formset context_data['subject_identifier_non_editable'] = subject_identifiers.non_editable user_preferences = get_user_preferences(request) context_data.update(user_preferences) preferred_name_assertion = entity.get_preferred_name( user_preferences['preferred_authority'], user_preferences['preferred_language'], user_preferences['preferred_script']) if preferred_name_assertion: context_data['preferred_name'] = preferred_name_assertion.name.assembled_form else: context_data['preferred_name'] = '[unnamed entity]' return render_to_response('eats/edit/entity_change.html', context_data, context_instance=RequestContext(request))
try: entity = get_topic_or_404(Entity, entity_id) except EATSMergedIdentifierException, e: return redirect('entity-change', entity_id=e.new_id, permanent=True) editor = request.user.eats_user context_data = {'entity': entity, 'is_valid': True} authority = editor.get_current_authority() editable_authorities = editor.editable_authorities.all() authority_data = {'current_authority': authority.get_id()} entity_data = None if request.method == 'POST': if '_change_authority' in request.POST: authority_data = request.POST else: entity_data = request.POST current_authority_form = CurrentAuthorityForm( topic_map, editable_authorities, authority_data) existences = ExistencePropertyAssertions(topic_map, entity, authority, entity_data) entity_types = EntityTypePropertyAssertions(topic_map, entity, authority, entity_data) names = NamePropertyAssertions(topic_map, entity, authority, entity_data) notes = NotePropertyAssertions(topic_map, entity, authority, entity_data) entity_relationships = EntityRelationshipPropertyAssertions( topic_map, entity, authority, entity_data) subject_identifiers = SubjectIdentifierPropertyAssertions( topic_map, entity, authority, entity_data) existences_formset = existences.formset entity_types_formset = entity_types.formset names_formset = names.formset notes_formset = notes.formset entity_relationships_formset = entity_relationships.formset
def entity_change (request, topic_map, entity_id): entity = get_topic_or_404(Entity, entity_id) editor = request.user.eats_user context_data = {'entity': entity} authority = editor.get_current_authority() editable_authorities = editor.editable_authorities.all() authority_data = {'current_authority': authority.get_id()} entity_data = None if request.method == 'POST': if '_change_authority' in request.POST: authority_data = request.POST else: entity_data = request.POST current_authority_form = CurrentAuthorityForm( topic_map, editable_authorities, authority_data) existences = ExistencePropertyAssertions(topic_map, entity, authority, entity_data) entity_types = EntityTypePropertyAssertions(topic_map, entity, authority, entity_data) names = NamePropertyAssertions(topic_map, entity, authority, entity_data) notes = NotePropertyAssertions(topic_map, entity, authority, entity_data) entity_relationships = EntityRelationshipPropertyAssertions( topic_map, entity, authority, entity_data) subject_identifiers = SubjectIdentifierPropertyAssertions( topic_map, entity, authority, entity_data) existences_formset = existences.formset entity_types_formset = entity_types.formset names_formset = names.formset notes_formset = notes.formset entity_relationships_formset = entity_relationships.formset subject_identifiers_formset = subject_identifiers.formset if request.method == 'POST': redirect_url = reverse('entity-change', kwargs={'entity_id': entity_id}) if '_change_authority' in request.POST: if current_authority_form.is_valid(): authority_id = current_authority_form.cleaned_data[ 'current_authority'] authority = Authority.objects.get_by_identifier(authority_id) editor.set_current_authority(authority) return HttpResponseRedirect(redirect_url) else: formsets = (existences_formset, entity_types_formset, names_formset, notes_formset, entity_relationships_formset, subject_identifiers_formset) is_valid = False for formset in formsets: is_valid = formset.is_valid() if not is_valid: break if is_valid: for formset in formsets: formset.save() return HttpResponseRedirect(redirect_url) context_data['current_authority_form'] = current_authority_form context_data['existence_non_editable'] = existences.non_editable context_data['existence_formset'] = existences_formset context_data['entity_type_non_editable'] = entity_types.non_editable context_data['entity_type_formset'] = entity_types_formset context_data['name_non_editable'] = names.non_editable context_data['name_formset'] = names_formset context_data['note_formset'] = notes_formset context_data['note_non_editable'] = notes.non_editable context_data['entity_relationship_formset'] = entity_relationships_formset context_data['entity_relationship_non_editable'] = entity_relationships.non_editable context_data['subject_identifier_formset'] = subject_identifiers_formset context_data['subject_identifier_non_editable'] = subject_identifiers.non_editable context_data['property_assertion_full_certainty'] = \ topic_map.property_assertion_full_certainty user_preferences = get_user_preferences(request) context_data.update(user_preferences) preferred_name_assertion = entity.get_preferred_name( user_preferences['preferred_authority'], user_preferences['preferred_language'], user_preferences['preferred_script']) if preferred_name_assertion: context_data['preferred_name'] = preferred_name_assertion.name.assembled_form else: context_data['preferred_name'] = UNNAMED_ENTITY_NAME return render_to_response('eats/edit/entity_change.html', context_data, context_instance=RequestContext(request))