예제 #1
0
 def create_type_event(self):
     """ makes an event object for a
         type entity
     """
     # validate start and end dates
     if self.start_date <= self.stop_date:
         start = self.start_date
         stop = self.stop_date
     else:
         start = self.stop_date
         stop = self.start_date
     event = Event()
     event.uuid = self.uuid
     event.item_type = 'types'
     event.project_uuid = self.project_uuid
     event.source_id = self.source_id
     event.event_id = self.event_id
     event.meta_type = self.meta_type
     event.when_type = self.when_type
     event.feature_id = 1
     event.earliest = start
     event.start = start
     event.stop = stop
     event.latest = stop
     event.save()
예제 #2
0
 def create_type_event(self):
     """ makes an event object for a
         type entity
     """
     # validate start and end dates
     if self.start_date <= self.stop_date:
         start = self.start_date
         stop = self.stop_date
     else:
         start = self.stop_date
         stop = self.start_date
     event = Event()
     event.uuid = self.uuid
     event.item_type = 'types'
     event.project_uuid = self.project_uuid
     event.source_id = self.source_id
     event.event_id = self.event_id
     event.meta_type = self.meta_type
     event.when_type = self.when_type
     event.feature_id = 1
     event.earliest = start
     event.start = start
     event.stop = stop
     event.latest = stop
     event.save()
예제 #3
0
 def add_update_date_range(self, post_data):
     """ Updates a file associated with a media item """
     ok = True
     errors = []
     note = ''
     required_params = [
         'source_id', 'hash_id', 'earliest', 'start', 'stop', 'latest',
         'meta_type', 'when_type', 'feature_id'
     ]
     for r_param in required_params:
         if r_param not in post_data:
             # we're missing some required data
             # don't create the item
             ok = False
             message = 'Missing paramater: ' + r_param + ''
             errors.append(message)
             note = '; '.join(errors)
     if ok:
         hash_id = post_data['hash_id'].strip()
         if len(hash_id) < 1:
             hash_id = False
         source_id = post_data['source_id'].strip()
         # validate the dates
         output = self.validate_int_param('earliest', post_data, errors)
         earliest = output['integer']
         errors = output['errors']
         output = self.validate_int_param('start', post_data, errors)
         start = output['integer']
         errors = output['errors']
         output = self.validate_int_param('stop', post_data, errors)
         stop = output['integer']
         errors = output['errors']
         output = self.validate_int_param('latest', post_data, errors)
         latest = output['integer']
         errors = output['errors']
         output = self.validate_int_param('feature_id', post_data, errors)
         feature_id = output['integer']
         if self.manifest.item_type == 'types':
             # we're adding a date range to a type
             feature_id = 0
         errors = output['errors']
         if (earliest is False or start is False \
            or stop is False or latest is False \
            or feature_id is False) and self.manifest.item_type != 'types':
             # 1 or more of the dates are bad
             ok = False
             note = '; '.join(errors)
         else:
             # the dates are all OK.
             # now sort the dates
             time_list = [earliest, start, stop, latest]
             time_list.sort()
             earliest = time_list[0]
             start = time_list[1]
             stop = time_list[2]
             latest = time_list[3]
             act_event = False
             if hash_id is not False:
                 try:
                     act_event = Event.objects.get(hash_id=hash_id)
                 except Event.DoesNotExist:
                     act_event = False
                     ok = False
                     message = 'Cannot find event for hash_id: ' + str(
                         hash_id)
                     errors.append(message)
                     note = '; '.join(errors)
                 if act_event is not False:
                     # get rid of the old event
                     act_event.delete()
             if ok:
                 # we're OK to add to an event
                 act_event = Event()
                 act_event.uuid = self.manifest.uuid
                 act_event.item_type = self.manifest.item_type
                 act_event.project_uuid = self.manifest.project_uuid
                 act_event.source_id = source_id
                 act_event.meta_type = post_data['meta_type'].strip()
                 act_event.when_type = post_data['when_type'].strip()
                 act_event.feature_id = feature_id
                 act_event.earliest = earliest
                 act_event.start = start
                 act_event.stop = stop
                 act_event.latest = latest
                 act_event.save()
                 note = 'Updated date range event for ' + self.manifest.uuid
     if ok:
         # now clear the cache a change was made
         cache.clear()
     self.response = {
         'action': 'add-update-date-range',
         'ok': ok,
         'change': {
             'note': note
         }
     }
     return self.response
예제 #4
0
 def add_update_date_range(self, post_data):
     """ Updates a file associated with a media item """
     ok = True
     errors = []
     note = ''
     required_params = ['source_id',
                        'hash_id',
                        'earliest',
                        'start',
                        'stop',
                        'latest',
                        'meta_type',
                        'when_type',
                        'feature_id']
     for r_param in required_params:
         if r_param not in post_data:
             # we're missing some required data
             # don't create the item
             ok = False
             message = 'Missing paramater: ' + r_param + ''
             errors.append(message)
             note = '; '.join(errors)
     if ok:
         hash_id = post_data['hash_id'].strip()
         if len(hash_id) < 1:
             hash_id = False
         source_id = post_data['source_id'].strip()
         # validate the dates
         output = self.validate_int_param('earliest', post_data, errors)
         earliest = output['integer']
         errors = output['errors']
         output = self.validate_int_param('start', post_data, errors)
         start = output['integer']
         errors = output['errors']
         output = self.validate_int_param('stop', post_data, errors)
         stop = output['integer']
         errors = output['errors']
         output = self.validate_int_param('latest', post_data, errors)
         latest = output['integer']
         errors = output['errors']
         output = self.validate_int_param('feature_id', post_data, errors)
         feature_id = output['integer']
         if self.manifest.item_type == 'types':
             # we're adding a date range to a type
             feature_id = 0
         errors = output['errors']
         if (earliest is False or start is False \
            or stop is False or latest is False \
            or feature_id is False) and self.manifest.item_type != 'types':
             # 1 or more of the dates are bad
             ok = False
             note = '; '.join(errors)
         else:
             # the dates are all OK.
             # now sort the dates
             time_list = [earliest, start, stop, latest]
             time_list.sort()
             earliest = time_list[0]
             start = time_list[1]
             stop = time_list[2]
             latest = time_list[3]
             act_event = False
             if hash_id is not False:
                 try:
                     act_event = Event.objects.get(hash_id=hash_id)
                 except Event.DoesNotExist:
                     act_event = False
                     ok = False
                     message = 'Cannot find event for hash_id: ' + str(hash_id)
                     errors.append(message)
                     note = '; '.join(errors)
                 if act_event is not False:
                     # get rid of the old event
                     act_event.delete()
             if ok:
                 # we're OK to add to an event
                 act_event = Event()
                 act_event.uuid = self.manifest.uuid
                 act_event.item_type = self.manifest.item_type
                 act_event.project_uuid = self.manifest.project_uuid
                 act_event.source_id = source_id
                 act_event.meta_type = post_data['meta_type'].strip()
                 act_event.when_type = post_data['when_type'].strip()
                 act_event.feature_id = feature_id
                 act_event.earliest = earliest
                 act_event.start = start
                 act_event.stop = stop
                 act_event.latest = latest
                 act_event.save()
                 note = 'Updated date range event for ' + self.manifest.uuid
     if ok:
         # now clear the cache a change was made
         cache.clear()
     self.response = {'action': 'add-update-date-range',
                      'ok': ok,
                      'change': {'note': note}}
     return self.response
예제 #5
0
 def process_date_item(self,
                       subject_field_num,
                       subject_in_rows,
                       subject_uuid):
     """ adds early late data if it exists for an item
     """
     if subject_field_num in self.date_fields:
         # this subject field has associated early - late data
         # now make a list where of rows that have non-blank lat data
         act_date_fields = self.date_fields[subject_field_num]
         validated_rows = {}
         date_fields_list = [act_date_fields['early'],
                             act_date_fields['late']]
         early_late_recs = ImportCell.objects\
                                     .filter(source_id=self.source_id,
                                             field_num__in=date_fields_list,
                                             row_num__in=subject_in_rows)
         for date_rec in early_late_recs:
             act_row = date_rec.row_num
             act_date = self.validate_date_value(date_rec.record)
             if act_row not in validated_rows:
                 validated_rows[act_row] = []
             if isinstance(act_date, float):
                 validated_rows[act_row].append(act_date)
         # the validated_rows dict now has rows (key), with validated dates
         # data. Now we can add these to the database!
         geo_feature = 1
         date_keys_done = []
         for row_key, date_list in validated_rows.items():
             if len(date_list) > 0:
                 early = min(date_list)
                 late = max(date_list)
                 if early == late:
                     when_type = Event.DEFAULT_WHENTYPE
                 else:
                     when_type = Event.DEFAULT_WHENTYPE
                 date_key = str(early) + ',' + str(late)
                 if date_key not in date_keys_done:
                     # we havent checked this set of dates yet
                     date_keys_done.append(date_key)
                     # now check to make sure we don't already have these coordinates
                     # on this item
                     same_dates = Event.objects\
                                       .filter(uuid=subject_uuid,
                                               start=early,
                                               stop=late)[:1]
                     if len(same_dates) < 1:
                         # it is a new date, ok to add
                         event = Event()
                         event.uuid = str(subject_uuid)
                         event.project_uuid = self.project_uuid
                         event.source_id = self.source_id
                         event.item_type = 'subjects'
                         event.feature_id = geo_feature
                         event.meta_type = ImportFieldAnnotation.PRED_DATE_EVENT
                         event.when_type = when_type
                         event.earliest = early
                         event.start = early
                         event.stop = late
                         event.latest = late
                         try:
                             event.save()
                         except:
                             print('Did not like ' + str(row) + ' with ' + str(subject_uuid))
                             quit()