Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit ee62dd7

Browse files
committed
implement the Forking this Concept and mapping
1 parent 1e5f277 commit ee62dd7

File tree

5 files changed

+4
-153
lines changed

5 files changed

+4
-153
lines changed

django-nonrel/ocl/collection/models.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,17 @@ def get_concept_id_by_version_information(self, expression):
8787
return Concept.objects.get(uri=expression).id
8888

8989
def validate(self, ref, expression):
90-
print 'collection/models.py validate ref: ', ref
91-
print 'collection/models.py validate expression: ', expression
9290
ref.full_clean()
9391

9492
drop_version = CollectionReferenceUtils.drop_version
95-
print 'collection/models.py validate self.references: ', self.references
9693
if drop_version(ref.expression) in [drop_version(reference.expression) for reference in self.references]:
97-
print 'collection/models.py validate ref.expression: ', ref.expression
98-
print 'collection/models.py validate drop_version ref.expression: ', drop_version(ref.expression)
9994
raise ValidationError({expression: [REFERENCE_ALREADY_EXISTS]})
10095

10196
if self.custom_validation_schema == CUSTOM_VALIDATION_SCHEMA_OPENMRS:
10297
if len(ref.concepts) < 1:
103-
print 'collection/models.py validate expression: < 1 return'
10498
return
10599

106100
concept = ref.concepts[0]
107-
print 'collection/models.py validate concept: ', concept
108101
self.check_concept_uniqueness_in_collection_and_locale_by_name_attribute(concept, attribute='is_fully_specified', value=True,
109102
error_message=CONCEPT_FULLY_SPECIFIED_NAME_UNIQUE_PER_COLLECTION_AND_LOCALE)
110103
self.check_concept_uniqueness_in_collection_and_locale_by_name_attribute(concept, attribute='locale_preferred', value=True,
@@ -114,37 +107,24 @@ def check_concept_uniqueness_in_collection_and_locale_by_name_attribute(self, co
114107
from concepts.models import Concept, ConceptVersion
115108
matching_names_in_concept = dict()
116109

117-
print 'collection/models.py check_concept_uniqueness_in_collection_and_locale_by_name_attribute'
118-
print 'collection/models.py check_concept_uniqueness_in_collection_and_locale_by_name_attribute concept: ', concept
119-
print 'collection/models.py check_concept_uniqueness_in_collection_and_locale_by_name_attribute attribute: ', attribute
120-
print 'collection/models.py check_concept_uniqueness_in_collection_and_locale_by_name_attribute value: ', value
121-
print '\n'
122-
123110
for name in [n for n in concept.names if getattr(n, attribute) == value]:
124-
print 'collection/models.py check_concept_uniqueness_in_collection_and_locale_by_name_attribute name: ', name
125111
validation_error = {'names': [error_message]}
126112
# making sure names in the submitted concept meet the same rule
127113
name_key = name.locale + name.name
128114
if name_key in matching_names_in_concept:
129-
print 'collection/models.py check_concept_uniqueness_in_collection_and_locale_by_name_attribute name_key: ', name_key
130-
print 'collection/models.py check_concept_uniqueness_in_collection_and_locale_by_name_attribute matching_names_in_concept: ', matching_names_in_concept
131115
raise ValidationError(validation_error)
132116

133117
matching_names_in_concept[name_key] = True
134118

135119
other_concepts_in_collection = list(ConceptVersion.objects.filter(uri__in=self.current_references()).values_list('id', flat=True))
136120

137-
print 'collection/models.py check_concept_uniqueness_in_collection_and_locale_by_name_attribute other_concepts_in_collection: ', other_concepts_in_collection
138-
139121
if len(other_concepts_in_collection) < 1:
140122
continue
141123

142124
other_concepts_in_collection = list(map(ObjectId, other_concepts_in_collection))
143-
print 'collection/models.py check_concept_uniqueness_in_collection_and_locale_by_name_attribute other_concepts_in_collection: ', other_concepts_in_collection
144125

145126
same_name_and_locale = {'_id': {'$in': other_concepts_in_collection},
146127
'names': {'$elemMatch': {'name': name.name, 'locale': name.locale}}}
147-
print 'collection/models.py check_concept_uniqueness_in_collection_and_locale_by_name_attribute same_name_and_locale: ', same_name_and_locale
148128

149129
if ConceptVersion.objects.raw_query(same_name_and_locale).count() > 0:
150130
raise ValidationError(validation_error)
@@ -446,27 +426,16 @@ class CollectionReferenceUtils():
446426
@classmethod
447427
def get_all_related_mappings(cls, expressions, collection):
448428

449-
print 'CollectionReferenceUtils get_all_related_mappings'
450-
print 'CollectionReferenceUtils get_all_related_mappings expressions: ', expressions
451-
print 'CollectionReferenceUtils get_all_related_mappings collection: ', collection
452-
453429
all_related_mappings = []
454430
unversioned_mappings = concept_expressions = []
455431

456432
for expression in expressions:
457-
print 'CollectionReferenceUtils get_all_related_mappings expression: ', expression
458433
if cls.is_mapping(expression):
459434
unversioned_mappings.append(cls.drop_version(expression))
460-
print 'CollectionReferenceUtils get_all_related_mappings unversioned_mappings111: ', unversioned_mappings
461435
elif cls.is_concept(expression):
462436
concept_expressions.append(expression)
463-
print 'CollectionReferenceUtils get_all_related_mappings concept_expressions111: ', concept_expressions
464-
465-
print 'CollectionReferenceUtils get_all_related_mappings unversioned_mappings222: ', unversioned_mappings
466-
print 'CollectionReferenceUtils get_all_related_mappings concept_expressions222: ', concept_expressions
467437

468438
for concept_expression in concept_expressions:
469-
print 'CollectionReferenceUtils get_all_related_mappings concept_expression: ', concept_expression
470439
ref = CollectionReference(expression=concept_expression)
471440
try:
472441
collection.validate(ref, concept_expression)
@@ -492,8 +461,6 @@ def get_related_mappings(cls, expression, existing_unversioned_mappings):
492461

493462
@classmethod
494463
def get_concept_id_by_version_information(cls, expression):
495-
print 'collection/models.py CollectionReferenceUtils get_concept_id_by_version_information'
496-
print 'collection/models.py CollectionReferenceUtils get_concept_id_by_version_information expression: ', expression
497464
if CollectionReference.version_specified(expression):
498465
return ConceptVersion.objects.get(uri=expression).versioned_object_id
499466
else:

django-nonrel/ocl/collection/views.py

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,19 @@ class CollectionReferencesView(CollectionBaseView,
101101
):
102102
serializer_class = CollectionDetailSerializer
103103

104-
print 'CollectionReferencesView'
105-
106104
def initialize(self, request, path_info_segment, **kwargs):
107-
print 'CollectionReferencesView initialize'
108-
print 'CollectionReferencesView initialize request: ', request
109-
print 'CollectionReferencesView initialize path_info_segment: ', path_info_segment
110-
print 'CollectionReferencesView initialize kwargs: ', kwargs
105+
111106
if request.method in ['GET', 'HEAD']:
112107
self.permission_classes = (CanViewConceptDictionary,)
113108
else:
114109
self.permission_classes = (CanEditConceptDictionary,)
115110
super(CollectionReferencesView, self).initialize(request, path_info_segment, **kwargs)
116111

117112
def get_level(self):
118-
print 'CollectionReferencesView get_level'
119113
return 1
120114

121115
def update(self, request, *args, **kwargs):
122-
print 'CollectionReferencesView update'
123-
print 'CollectionReferencesView update request: ', request
124-
print 'CollectionReferencesView update request DATA: ', request.DATA
125-
print 'CollectionReferencesView update args: ', args
126-
print 'CollectionReferencesView update kwargs: ', kwargs
116+
127117
if not self.parent_resource:
128118
return HttpResponse(status=status.HTTP_405_METHOD_NOT_ALLOWED)
129119

@@ -139,16 +129,6 @@ def update(self, request, *args, **kwargs):
139129

140130
adding_all = mapping_expressions == '*' or concept_expressions == '*'
141131

142-
print 'CollectionReferencesView update data: ', data
143-
print 'CollectionReferencesView update expressions: ', expressions
144-
print 'CollectionReferencesView update concept_expressions: ', concept_expressions
145-
print 'CollectionReferencesView update mapping_expressions: ', mapping_expressions
146-
print 'CollectionReferencesView update cascade_mappings_flag: ', cascade_mappings_flag
147-
print 'CollectionReferencesView update cascade_mappings: ', cascade_mappings
148-
print 'CollectionReferencesView update host_url: ', host_url
149-
print 'CollectionReferencesView update adding_all: ', adding_all
150-
151-
152132
if adding_all:
153133
add_references.delay(
154134
self.serializer_class, self.request.user, data, self.parent_resource, host_url, cascade_mappings
@@ -160,8 +140,6 @@ def update(self, request, *args, **kwargs):
160140
self.serializer_class, self.request.user, data, self.parent_resource, host_url, cascade_mappings
161141
)
162142

163-
print 'CollectionReferencesView update added_references: ', added_references
164-
165143
all_expression = expressions + concept_expressions + mapping_expressions
166144

167145
added_expression = [references.expression for references in added_references]
@@ -171,32 +149,22 @@ def update(self, request, *args, **kwargs):
171149

172150
for expression in added_original_expression:
173151
response_item = self.create_response_item(added_expression, errors, expression)
174-
print 'CollectionReferencesView update response_item: ', response_item
175152
if response_item:
176153
response.append(response_item)
177154

178-
print 'CollectionReferencesView update all_expression: ', all_expression
179-
print 'CollectionReferencesView update added_expression: ', added_expression
180-
print 'CollectionReferencesView update added_original_expression: ', added_original_expression
181-
print 'CollectionReferencesView update response: ', response
182-
183155
return Response(response, status=status.HTTP_200_OK)
184156

185157
def create_response_item(self, added_references, errors, expression):
186-
print 'CollectionReferencesView create_response_item'
187158
adding_expression_failed = len(errors) > 0 and errors[0].has_key(expression)
188159
if adding_expression_failed:
189160
return self.create_error_message(errors, expression)
190161
return self.create_success_message(added_references, expression)
191162

192163
def create_success_message(self, added_references, expression):
193-
print 'CollectionReferencesView create_success_message'
194164
message = self.select_update_message(expression)
195165

196166
references = filter(lambda reference: reference.startswith(expression), added_references)
197167

198-
print 'CollectionReferencesView create_success_message message: ', message
199-
print 'CollectionReferencesView create_success_message references: ', references
200168
if len(references) < 1:
201169
return
202170

@@ -207,24 +175,18 @@ def create_success_message(self, added_references, expression):
207175
}
208176

209177
def create_error_message(self, errors, expression):
210-
print 'CollectionReferencesView create_error_message'
211178
error_message = errors[0].get(expression, {})
212-
print 'CollectionReferencesView create_error_message errors: ', errors
213-
print 'CollectionReferencesView create_error_message error_message: ', error_message
214-
print 'CollectionReferencesView create_error_message expression: ', expression
215179
return {
216180
'added': False,
217181
'expression': expression,
218182
'message': error_message
219183
}
220184

221185
def retrieve(self, request, *args, **kwargs):
222-
print 'CollectionReferencesView retrieve'
223186
self.serializer_class = CollectionReferenceSerializer
224187
return self.list(request, *args, **kwargs)
225188

226189
def get_queryset(self):
227-
print 'CollectionReferencesView get_queryset'
228190
search_query = self.request.QUERY_PARAMS.get('q', '')
229191
sort = self.request.QUERY_PARAMS.get('search_sort', 'ASC')
230192

@@ -233,7 +195,6 @@ def get_queryset(self):
233195
return references if sort == 'ASC' else list(reversed(references))
234196

235197
def destroy(self, request, *args, **kwargs):
236-
print 'CollectionReferencesView destroy'
237198
if not self.parent_resource:
238199
return HttpResponse(status=status.HTTP_405_METHOD_NOT_ALLOWED)
239200

@@ -253,17 +214,13 @@ def destroy(self, request, *args, **kwargs):
253214
return Response({'message': 'ok!'}, status=status.HTTP_200_OK)
254215

255216
def get_related_mappings_with_version_information(self, cascade_mappings_flag, references):
256-
print 'CollectionReferencesView get_related_mappings_with_version_information'
257-
print 'CollectionReferencesView get_related_mappings_with_version_information references: ', references
217+
258218
related_mappings = []
259219

260220
for reference in references:
261221
if CollectionReferenceUtils.is_concept(reference):
262222
concept_id = CollectionReferenceUtils.get_concept_id_by_version_information(reference)
263223
related_mappings += Concept.objects.get(id=concept_id).get_unidirectional_mappings()
264-
print 'CollectionReferencesView get_related_mappings_with_version_information concept_id: ', concept_id
265-
print 'CollectionReferencesView get_related_mappings_with_version_information reference: ', reference
266-
print 'CollectionReferencesView get_related_mappings_with_version_information related_mappings: ', related_mappings
267224

268225
return self.get_version_information_of_related_mappings(related_mappings)
269226

@@ -278,7 +235,6 @@ def get_version_information_of_related_mappings(self, related_mappings):
278235
return related_mappings_with_version
279236

280237
def cascade_mapping_resolver(self, cascade_mappings_flag):
281-
print 'CollectionReferencesView cascade_mapping_resolver'
282238
cascade_mappings_flag_resolver = {
283239
'none': False,
284240
'sourcemappings': True
@@ -287,7 +243,6 @@ def cascade_mapping_resolver(self, cascade_mappings_flag):
287243
return cascade_mappings_flag_resolver.get(cascade_mappings_flag.lower(), False)
288244

289245
def select_update_message(self, expression):
290-
print 'CollectionReferencesView select_update_message'
291246
adding_head_version = not CollectionReference.version_specified(expression)
292247

293248
expression_parts = expression.split('/')
@@ -298,20 +253,14 @@ def select_update_message(self, expression):
298253

299254
resource_name = expression_parts[6]
300255

301-
print 'CollectionReferencesView select_update_message adding_head_version: ', adding_head_version
302-
print 'CollectionReferencesView select_update_message expression_parts: ', expression_parts
303-
print 'CollectionReferencesView select_update_message resource_type: ', resource_type
304-
305256
return self.version_added_message_by_type(resource_name, self.parent_resource.name, resource_type)
306257

307258
def adding_to_head_message_by_type(self, resource_type):
308-
print 'CollectionReferencesView adding_to_head_message_by_type'
309259
if resource_type == 'concepts':
310260
return HEAD_OF_CONCEPT_ADDED_TO_COLLECTION
311261
return HEAD_OF_MAPPING_ADDED_TO_COLLECTION
312262

313263
def version_added_message_by_type(self, resource_name, collection_name, resource_type):
314-
print 'CollectionReferencesView version_added_message_by_type'
315264
if resource_type == 'concepts':
316265
return CONCEPT_ADDED_TO_COLLECTION_FMT.format(resource_name, collection_name)
317266
return MAPPING_ADDED_TO_COLLECTION_FMT.format(resource_name, collection_name)

django-nonrel/ocl/concepts/models.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -529,12 +529,3 @@ def propagate_parent_attributes(sender, instance=None, created=False, **kwargs):
529529
concept_version.save()
530530
concept.save()
531531

532-
533-
class ConceptUtils():
534-
535-
@classmethod
536-
def get_concept_id_by_version_information(cls, expression):
537-
print 'concept/models.py ConceptUtils get_concept_id_by_version_information'
538-
print 'concept/models.py ConceptUtils get_concept_id_by_version_information expression: ', expression
539-
540-
return Concept.objects.get(uri=expression).id

django-nonrel/ocl/concepts/views.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from collection.models import Collection, CollectionVersion, CollectionReference, CollectionReferenceUtils
1313

1414
from concepts.filters import LimitSourceVersionFilter, PublicConceptsSearchFilter, LimitCollectionVersionFilter
15-
from concepts.models import Concept, ConceptVersion, LocalizedText, ConceptUtils
15+
from concepts.models import Concept, ConceptVersion, LocalizedText
1616
from concepts.permissions import CanViewParentDictionary, CanEditParentDictionary
1717
from concepts.serializers import (ConceptDetailSerializer, ConceptVersionListSerializer,
1818
ConceptVersionDetailSerializer, ConceptVersionUpdateSerializer,
@@ -162,8 +162,6 @@ def get_queryset(self):
162162
class ConceptCreateView(ConceptBaseView,
163163
mixins.CreateModelMixin):
164164

165-
print 'ConceptCreateView'
166-
167165
@csrf_exempt
168166
def dispatch(self, request, *args, **kwargs):
169167
if request.method != 'POST':
@@ -199,7 +197,6 @@ def create(self, request, *args, **kwargs):
199197

200198
class ConceptForkView(ConceptBaseView,
201199
mixins.CreateModelMixin):
202-
print 'ConceptForkView'
203200

204201
@csrf_exempt
205202
def dispatch(self, request, *args, **kwargs):
@@ -216,20 +213,6 @@ def post(self, request, *args, **kwargs):
216213
def create(self, request, *args, **kwargs):
217214
serializer = self.get_serializer(data=request.DATA, files=request.FILES)
218215

219-
print 'ConceptForkView create: request Data: ', request.DATA
220-
print 'ConceptForkView create: request args: ', args
221-
print 'ConceptForkView create: request kwargs: ', kwargs
222-
223-
fork_mappings = request.DATA.get('Fork_Mappings')
224-
concept_id = ConceptUtils.get_concept_id_by_version_information(request.DATA.get('forked_from_url'))
225-
related_mappings = self.get_related_mappings_with_version_information(concept_id)
226-
227-
print 'ConceptForkView create: request concept_id: ', concept_id
228-
print 'ConceptForkView create: request fork_mappings: ', fork_mappings
229-
print 'ConceptForkView create: request related_mappings: ', related_mappings
230-
231-
# return None
232-
233216
if serializer.is_valid():
234217
self.pre_save(serializer.object)
235218
save_kwargs = {
@@ -248,16 +231,6 @@ def create(self, request, *args, **kwargs):
248231

249232
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
250233

251-
def validate(self):
252-
queryset = ConceptVersion.objects.filter(is_active=True)
253-
print 'ConceptForkView queryset: ', queryset
254-
255-
def get_related_mappings_with_version_information(self, concept_id):
256-
print 'ConceptForkView get_related_mappings_with_version_information'
257-
related_mappings = []
258-
related_mappings += Concept.objects.get(id=concept_id).get_unidirectional_mappings()
259-
return related_mappings
260-
261234

262235
class ConceptVersionsView(ConceptDictionaryMixin, ListWithHeadersMixin):
263236
serializer_class = ConceptVersionListSerializer
@@ -352,8 +325,6 @@ class ConceptVersionRetrieveView(ConceptVersionMixin, ResourceVersionMixin, Retr
352325
permission_classes = (CanViewParentDictionary,)
353326
versioned_object = None
354327

355-
print 'ConceptVersionRetrieveView'
356-
357328
def initialize(self, request, path_info_segment, **kwargs):
358329
self.versioned_object = kwargs.pop('versioned_object', None)
359330
super(ConceptVersionRetrieveView, self).initialize(request, path_info_segment, **kwargs)

0 commit comments

Comments
 (0)