def obj_update(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] if self.is_finalized( Incident, kwargs['pk'], 'most_recent_status_incident') and can_finalize(user) is False: raise ImmediateHttpResponse( HttpForbidden('This item has been finalized')) if can_assign_users(user) is False and 'assigned_user' in bundle.data: del (bundle.data['assigned_user']) status_id = self.id_from_url(bundle.data) status_update = StatusUpdate.filter_by_perm_objects.get_update_status( user, status_id) comment_uri = self.create_comment(bundle.data['comment'], status_update.id, user) try: bundle.data['incident_comments'].append(comment_uri) except KeyError: bundle.data['incident_comments'] = [ comment_uri, ] with reversion.create_revision(): bundle = super(IncidentResource, self)\ .obj_update(bundle, **kwargs) reversion.add_meta(VersionStatus, user=user, status='edited') reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle
def multi_save_incidents(request, incident_dict, username): ''' main run loop for indident save, return the HttpResponse object that has the json object ''' passed, error_response = validate_status_update(incident_dict) if passed is False: return HttpResponseForbidden( error_response, mimetype='application/json' ) incident_id_list = extract_ids(incident_dict, 'incidents') incident_id_list = filter( incident_finalized, incident_id_list) incident_dict = process_incident_dict(incident_dict) incident_dict.pop('incidents') incident_objects = Incident.objects.filter( pk__in=incident_id_list ) incident_dict['user'] = request.user update_incidents(incident_dict, incident_objects) from corroborator_app.api.IncidentApi import IncidentResource response_content = get_result_objects( incident_id_list, username, request, IncidentResource, Incident ) update_object.delay(username) return HttpResponse( response_content, mimetype='application/json' )
def obj_create(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] status_update = StatusUpdate.objects.get(status_en='Human Created') if can_assign_users(user) is False and 'assigned_user' in bundle.data: del(bundle.data['assigned_user']) comment_uri = self.create_comment( bundle.data['comment'], status_update.id, user ) bundle.data['bulletin_comments'] = [ comment_uri ] with reversion.create_revision(): bundle = super(BulletinResource, self)\ .obj_create(bundle, **kwargs) reversion.add_meta( VersionStatus, status='created', user=user ) reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle
def multi_save_actors(request, actor_dict, username): ''' main save actor function save a bunch of attributes to a bunch of actors element_data: QueryDict ''' passed, error_response = validate_status_update(actor_dict) if passed is False: return HttpResponseForbidden(error_response, mimetype='application/json') status_id = parse_id_from_uri(actor_dict['status_uri']) actor_id_list = extract_ids(actor_dict, 'selectedActors') actor_id_list = filter(actor_finalized, actor_id_list) actor_dict = process_actor_data(actor_dict) actor_dict['user'] = request.user actor_dict.pop('selectedActors') actor_objects = Actor.objects.filter(id__in=actor_id_list) update_actors(actor_dict, actor_objects) from corroborator_app.api.ActorApi import ActorResource response_content = get_result_objects(actor_id_list, username, request, ActorResource, Actor) update_object.delay(username) return HttpResponse(response_content, mimetype='application/json')
def obj_create(self, bundle, **kwargs): username = bundle.request.GET['username'] media_file = bundle.data['media_file'] bundle.data['media_type'] = 'Document' if 'video' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Video' #ffmpeg_wrapper = MiniFFMPEGWrapper() #ffmpeg_wrapper.video_file = media_file.temporary_file_path() #ffmpeg_wrapper.create_jpeg_from_video() #thumb_source_file = UploadedFile(ffmpeg_wrapper.out_filename) #thumbnailer = Thumbnailer() #bundle.data['media_thumb_file'] =\ #thumbnailer.construct_thumb_from_image( #thumb_source_file #) if 'image' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Picture' media_thumb_file = Thumbnailer()\ .construct_thumb_from_image(media_file) bundle.data['media_thumb_file'] = media_thumb_file if 'pdf' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Pdf' parts = media_file.name.split('.') media_file_type = parts[len(parts) - 1] bundle.data['media_file_type'] = media_file_type bundle = super(MediaResource, self).obj_create(bundle, **kwargs) update_object.delay(username) return bundle
def obj_create(self, bundle, **kwargs): ''' created objects should automatically have a status of Human Created ''' status_update = StatusUpdate.objects.get(status_en='Human Created') username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] status_id = status_update.id if can_assign_users(user) is False and 'assigned_user' in bundle.data: del(bundle.data['assigned_user']) comment_uri = self.create_comment( bundle.data['comment'], status_id, user ) bundle.data['actor_comments'] = [ comment_uri ] with reversion.create_revision(): bundle = super(ActorResource, self)\ .obj_create(bundle, **kwargs) reversion.add_meta( VersionStatus, status='created', user=user ) reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle
def obj_create(self, bundle, **kwargs): username = bundle.request.GET['username'] media_file = bundle.data['media_file'] bundle.data['media_type'] = 'Document' if 'video' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Video' #ffmpeg_wrapper = MiniFFMPEGWrapper() #ffmpeg_wrapper.video_file = media_file.temporary_file_path() #ffmpeg_wrapper.create_jpeg_from_video() #thumb_source_file = UploadedFile(ffmpeg_wrapper.out_filename) #thumbnailer = Thumbnailer() #bundle.data['media_thumb_file'] =\ #thumbnailer.construct_thumb_from_image( #thumb_source_file #) if 'image' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Picture' media_thumb_file = Thumbnailer()\ .construct_thumb_from_image(media_file) bundle.data['media_thumb_file'] = media_thumb_file if 'pdf' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Pdf' parts = media_file.name.split('.') media_file_type = parts[len(parts)-1] bundle.data['media_file_type'] = media_file_type bundle = super(MediaResource, self).obj_create(bundle, **kwargs) update_object.delay(username) return bundle
def obj_create(self, bundle, **kwargs): username = bundle.request.GET['username'] media_file = bundle.data['media_file'] bundle.data['media_type'] = 'Document' #todo: perhaps don't fail the upload if thumbnailing fails if 'video' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Video' if settings.VIDEO_THUMBNAILING: ffmpeg_wrapper = MiniFFMPEGWrapper() # Files < 2.5MB get stored in memory rather than on disk if hasattr(media_file, 'temporary_file_path'): # file_object is file path file_location = 'disk' file_object = media_file file_name = file_object.temporary_file_path() #filetype = mime.from_file(file_object) #file_info = m.from_file(file_object) else: # file_object is an actual file object file_location = 'memory' file_object = media_file file_buffer = media_file.read() #filetype = mime.from_buffer(file_buffer) #file_info = m.from_buffer(file_buffer) file_object.seek(0) # write it to a temporary file on disk so we can get a path to pass to the ffmpeg command file_object = tempfile.NamedTemporaryFile( dir=settings.FILE_UPLOAD_TEMP_DIR) file_object.write(file_buffer) file_object.flush() os.fsync(file_object.fileno()) file_name = file_object.name ffmpeg_wrapper.video_file = file_name ffmpeg_wrapper.create_jpeg_from_video() thumb_source_file = UploadedFile( open(ffmpeg_wrapper.out_filename)) thumbnailer = Thumbnailer() bundle.data['media_thumb_file'] =\ thumbnailer.construct_thumb_from_image( thumb_source_file ) if 'image' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Picture' media_thumb_file = Thumbnailer()\ .construct_thumb_from_image(media_file) bundle.data['media_thumb_file'] = media_thumb_file if 'pdf' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Pdf' parts = media_file.name.split('.') media_file_type = parts[len(parts) - 1] bundle.data['media_file_type'] = media_file_type bundle = super(MediaResource, self).obj_create(bundle, **kwargs) update_object.delay(username) return bundle
def obj_create(self, bundle, **kwargs): username = bundle.request.GET['username'] media_file = bundle.data['media_file'] bundle.data['media_type'] = 'Document' #todo: perhaps don't fail the upload if thumbnailing fails if 'video' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Video' if settings.VIDEO_THUMBNAILING: ffmpeg_wrapper = MiniFFMPEGWrapper() # Files < 2.5MB get stored in memory rather than on disk if hasattr(media_file, 'temporary_file_path'): # file_object is file path file_location = 'disk' file_object = media_file file_name = file_object.temporary_file_path() #filetype = mime.from_file(file_object) #file_info = m.from_file(file_object) else: # file_object is an actual file object file_location = 'memory' file_object = media_file file_buffer = media_file.read() #filetype = mime.from_buffer(file_buffer) #file_info = m.from_buffer(file_buffer) file_object.seek(0) # write it to a temporary file on disk so we can get a path to pass to the ffmpeg command file_object = tempfile.NamedTemporaryFile(dir=settings.FILE_UPLOAD_TEMP_DIR) file_object.write(file_buffer) file_object.flush() os.fsync(file_object.fileno()) file_name = file_object.name ffmpeg_wrapper.video_file = file_name ffmpeg_wrapper.create_jpeg_from_video() thumb_source_file = UploadedFile(open(ffmpeg_wrapper.out_filename)) thumbnailer = Thumbnailer() bundle.data['media_thumb_file'] =\ thumbnailer.construct_thumb_from_image( thumb_source_file ) if 'image' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Picture' media_thumb_file = Thumbnailer()\ .construct_thumb_from_image(media_file) bundle.data['media_thumb_file'] = media_thumb_file if 'pdf' in bundle.data['media_file'].content_type: bundle.data['media_type'] = 'Pdf' parts = media_file.name.split('.') media_file_type = parts[len(parts)-1] bundle.data['media_file_type'] = media_file_type bundle = super(MediaResource, self).obj_create(bundle, **kwargs) update_object.delay(username) return bundle
def obj_update(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] bundle.data['id'] = kwargs['pk'] if self.can_edit(user, bundle, Actor) is False: raise ImmediateHttpResponse( HttpForbidden('You do not have permission to edit this entity') ) if self.is_finalized( Actor, kwargs['pk'], 'most_recent_status_actor' ) and can_finalize(user) is False: raise ImmediateHttpResponse( HttpForbidden('This item has been finalized') ) if can_assign_users(user) is False and 'assigned_user' in bundle.data: del(bundle.data['assigned_user']) status_id = self.id_from_url(bundle.data) status_update = StatusUpdate.filter_by_perm_objects.get_update_status( user, status_id ) comment_uri = self.create_comment( bundle.data['comment'], status_update.id, user ) if "condition" not in bundle.data: bundle.data['condition'] = None if "POB" not in bundle.data: bundle.data['POB'] = None if "current_location" not in bundle.data: bundle.data['current_location'] = None try: bundle.data['actor_comments'].append(comment_uri) except KeyError: bundle.data['actor_comments'] = [comment_uri, ] with reversion.create_revision(): bundle = super(ActorResource, self)\ .obj_update(bundle, **kwargs) reversion.add_meta( VersionStatus, status='edited', user=user ) reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle
def obj_delete(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] with reversion.create_revision(): bundle = super(BulletinResource, self)\ .obj_delete(bundle, **kwargs) reversion.add_meta(VersionStatus, status='deleted', user=user) reversion.set_user(user) reversion.set_comment('Deleted') update_object.delay(username) return bundle
def obj_update(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] if self.can_edit(user, bundle, Bulletin) is False: raise ImmediateHttpResponse( HttpForbidden('You do not have permission to edit this entity') ) # permission checks if self.is_finalized( Bulletin, kwargs['pk'], 'most_recent_status_bulletin' ) and can_finalize(user) is False: raise ImmediateHttpResponse( HttpForbidden('This item has been finalized') ) if can_assign_users(user) is False and 'assigned_user' in bundle.data: del(bundle.data['assigned_user']) # decide on available status status_id = self.id_from_url(bundle.data) status_update = StatusUpdate.filter_by_perm_objects.get_update_status( user, status_id ) # create the commnt from the status update and the bundled comment comment_uri = self.create_comment( bundle.data['comment'], status_update.id, user ) try: bundle.data['bulletin_comments'].append(comment_uri) except KeyError: bundle.data['bulletin_comments'] = [comment_uri, ] with reversion.create_revision(): bundle = super(BulletinResource, self)\ .obj_update(bundle, **kwargs) reversion.add_meta( VersionStatus, status='edited', user=user ) reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle
def obj_delete(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] with reversion.create_revision(): bundle = super(BulletinResource, self)\ .obj_delete(bundle, **kwargs) reversion.add_meta( VersionStatus, status='deleted', user=user ) reversion.set_user(user) reversion.set_comment('Deleted') update_object.delay(username) return bundle
def obj_update(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] bundle.data['id'] = kwargs['pk'] if self.can_edit(user, bundle, Actor) is False: raise ImmediateHttpResponse( HttpForbidden( 'You do not have permission to edit this entity')) if self.is_finalized( Actor, kwargs['pk'], 'most_recent_status_actor') and can_finalize(user) is False: raise ImmediateHttpResponse( HttpForbidden('This item has been finalized')) if can_assign_users(user) is False and 'assigned_user' in bundle.data: del (bundle.data['assigned_user']) status_id = self.id_from_url(bundle.data) status_update = StatusUpdate.filter_by_perm_objects.get_update_status( user, status_id) comment_uri = self.create_comment(bundle.data['comment'], status_update.id, user) if "condition" not in bundle.data: bundle.data['condition'] = None if "POB" not in bundle.data: bundle.data['POB'] = None if "current_location" not in bundle.data: bundle.data['current_location'] = None try: bundle.data['actor_comments'].append(comment_uri) except KeyError: bundle.data['actor_comments'] = [ comment_uri, ] with reversion.create_revision(): bundle = super(ActorResource, self)\ .obj_update(bundle, **kwargs) reversion.add_meta(VersionStatus, status='edited', user=user) reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle
def obj_update(self, bundle, **kwargs): username = bundle.request.GET['username'] user = User.objects.filter(username=username)[0] if self.is_finalized( Incident, kwargs['pk'], 'most_recent_status_incident' ) and can_finalize(user) is False: raise ImmediateHttpResponse( HttpForbidden('This item has been finalized') ) if can_assign_users(user) is False and 'assigned_user' in bundle.data: del(bundle.data['assigned_user']) status_id = self.id_from_url(bundle.data) status_update = StatusUpdate.filter_by_perm_objects.get_update_status( user, status_id ) comment_uri = self.create_comment( bundle.data['comment'], status_update.id, user ) try: bundle.data['incident_comments'].append(comment_uri) except KeyError: bundle.data['incident_comments'] = [comment_uri, ] with reversion.create_revision(): bundle = super(IncidentResource, self)\ .obj_update(bundle, **kwargs) reversion.add_meta( VersionStatus, user=user, status='edited' ) reversion.set_user(user) reversion.set_comment(bundle.data['comment']) update_object.delay(username) return bundle
def multi_save_incidents(request, incident_dict, username): ''' main run loop for indident save, return the HttpResponse object that has the json object ''' passed, error_response = validate_status_update(incident_dict) if passed is False: return HttpResponseForbidden(error_response, mimetype='application/json') incident_id_list = extract_ids(incident_dict, 'incidents') incident_id_list = filter(incident_finalized, incident_id_list) incident_dict = process_incident_dict(incident_dict) incident_dict.pop('incidents') incident_objects = Incident.objects.filter(pk__in=incident_id_list) incident_dict['user'] = request.user update_incidents(incident_dict, incident_objects) from corroborator_app.api.IncidentApi import IncidentResource response_content = get_result_objects(incident_id_list, username, request, IncidentResource, Incident) update_object.delay(username) return HttpResponse(response_content, mimetype='application/json')
def multi_save_actors(request, actor_dict, username): ''' main save actor function save a bunch of attributes to a bunch of actors element_data: QueryDict ''' passed, error_response = validate_status_update(actor_dict) if passed is False: return HttpResponseForbidden( error_response, mimetype='application/json' ) status_id = parse_id_from_uri(actor_dict['status_uri']) actor_id_list = extract_ids(actor_dict, 'selectedActors') actor_id_list = filter(actor_finalized, actor_id_list) actor_dict = process_actor_data(actor_dict) actor_dict['user'] = request.user actor_dict.pop('selectedActors') actor_objects = Actor.objects.filter( id__in=actor_id_list ) update_actors(actor_dict, actor_objects) from corroborator_app.api.ActorApi import ActorResource response_content = get_result_objects( actor_id_list, username, request, ActorResource, Actor ) update_object.delay(username) return HttpResponse( response_content, mimetype='application/json' )
def multi_save_bulletins(request, bulletin_dict, username): ''' main run loop for bulletin save, return the HttpResponse object that has the json object ''' passed, error_response = validate_status_update(bulletin_dict) if passed is False: return HttpResponseForbidden(error_response, mimetype='application/json') bulletin_id_list = extract_ids(bulletin_dict, 'bulletins') bulletin_id_list = filter(bulletin_finalized, bulletin_id_list) bulletin_dict = process_bulletin_dict(bulletin_dict) bulletin_dict.pop('bulletins') bulletin_objects = Bulletin.objects.filter(pk__in=bulletin_id_list) bulletin_dict['user'] = request.user update_bulletins(bulletin_dict, bulletin_objects) from corroborator_app.api.BulletinApi import BulletinResource response_content = get_result_objects(bulletin_id_list, username, request, BulletinResource, Bulletin) update_object.delay(username) return HttpResponse(response_content, mimetype='application/json')
def multi_save_bulletins(request, bulletin_dict, username): ''' main run loop for bulletin save, return the HttpResponse object that has the json object ''' passed, error_response = validate_status_update(bulletin_dict) if passed is False: return HttpResponseForbidden( error_response, mimetype='application/json' ) bulletin_id_list = extract_ids(bulletin_dict, 'bulletins') bulletin_id_list = filter(bulletin_finalized, bulletin_id_list) bulletin_dict = process_bulletin_dict(bulletin_dict) bulletin_dict.pop('bulletins') bulletin_objects = Bulletin.objects.filter( pk__in=bulletin_id_list ) bulletin_dict['user'] = request.user update_bulletins(bulletin_dict, bulletin_objects) from corroborator_app.api.BulletinApi import BulletinResource response_content = get_result_objects( bulletin_id_list, username, request, BulletinResource, Bulletin ) update_object.delay(username) return HttpResponse( response_content, mimetype='application/json' )