Ejemplo n.º 1
0
 def post(self, request, *args, **kwargs):
     if request.is_ajax():
         if 'params' in request.POST:
             ajax = AJAXRequests(json.loads(request.POST['params']))
             
             if ajax.isView() and ajax.isTargetApp():
                 app = Application.objects.get(app_id=ajax.id)
                 
                 app_info = serializers.serialize(
                                                          "json", 
                                                          [app], 
                                                          fields=(
                                                                  'app_name',
                                                                  'app_type',
                                                                  'upload_date',
                                                                  'app_output',
                                                                  )
                                                          )
                 return HttpResponse(app_info)
             elif ajax.isOutput() and ajax.isTargetApp():
                 output = 'terminate'
                 app = Application.objects.get(app_id=ajax.id)
                 if app.interface_bits != AppState.bits['FINISHED']:
                     output = app.app_output[ajax.position:]
                 
                 return HttpResponse(output)
Ejemplo n.º 2
0
 def post(self, request, *args, **kwargs):
     if request.is_ajax:
         if 'params' in request.POST:
             ajax = AJAXRequests(json.loads(request.POST['params']))
             
             if ajax.isPlay() and ajax.isTargetInput():
                 try:
                     input_element = InputElement.objects.get(input_id=ajax.id)
                     
                     if input_element.interface_bits == InputState.bits['NEW']:
                         app_group = ApplicationGroup.create()
                         app_group.save()
                         
                         input_element.interface_bits = InputState.bits['PREPROCESSING']
                         input_element.save()
                         
                         message = messaging.createMessage(
                                                     'preprocess', 
                                                     return_queue=settings.WEB_INTERFACE_QUEUE,
                                                     input_id=input_element.input_id,
                                                     input_file=input_element.input_file.name,
                                                     group_id=app_group.group_id,
                                                     input_param='old',
                                                     )
                         producerPreprocessor.publish(message)
                 except ObjectDoesNotExist:
                     pass
             elif ajax.isTrash() and ajax.isTargetInput():
                 try:
                     input_element = InputElement.objects.get(input_id=ajax.id)
                     if input_element.interface_bits == InputState.bits['NEW']:
                         input_element.delete()
                 except ObjectDoesNotExist:
                     pass
     return redirect(reverse('input_upload'))
Ejemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        if request.is_ajax:
            if 'params' in request.POST:
                ajax = AJAXRequests(json.loads(request.POST['params']))
                
                if ajax.isTrash() and ajax.isTargetApp():
                    try:
                        app = Application.objects.get(app_id=ajax.id)
                        self._trashApp(app)
                    except ObjectDoesNotExist:
                        pass
                elif ajax.isTrash() and ajax.isTargetGroup():
                    try:
                        app_group = ApplicationGroup.objects.get(group_id=ajax.id)
                        apps_list = Application.objects.filter(app_group=app_group)
                        for app in apps_list:
                            self._trashApp(app)
                    except ObjectDoesNotExist:
                        pass
                elif ajax.isPlay() and ajax.isTargetApp():
                    try:
                        app = Application.objects.get(app_id=ajax.id)
                        self._playApp(app)
                    except ObjectDoesNotExist:
                        pass
                elif ajax.isPlay() and ajax.isTargetGroup():
                    try:
                        app_group = ApplicationGroup.objects.get(group_id=ajax.id)
                        apps_list = Application.objects.filter(app_group=app_group)
                        for app in apps_list:
                            self._playApp(app)
                        app_group.interface_bits = GroupState.bits['STARTED']
                        app_group.save()
                    except ObjectDoesNotExist:
                        pass
                elif ajax.isInfo() and ajax.isTargetApp():
                    return redirect(reverse('view_application', kwargs={'app_id': ajax.id}))
                elif ajax.isRequest() and ajax.isTargetGroup():
                    try:
                        app_group = ApplicationGroup.objects.get(group_id=ajax.id)
                        
                        try:
                            default_storage.delete(app_group.output.name)
                            app_group.output_file_ready = False
                            app_group.interface_bits = GroupState.bits['FINISHED']
                            app_group.save()
                        except S3ResponseError:
                            pass
                        except:
                            pass
                        
                        
                        apps_list = Application.objects.filter(app_group=app_group)

                        outputs_list = []
                        apps_ids_list = []
                        for app in apps_list:
                            if app.app_output_file_ready:
                                app.interface_bits = AppState.bits['TRANSITIONING']
                                app.save()
                                
                                apps_ids_list.append(app.app_id)
                                outputs_list.append(app.app_output_file.name)
                                
                        message = messaging.createMessage(
                                            'postprocess', 
                                            return_queue=settings.WEB_INTERFACE_QUEUE,
                                            group_id=app_group.group_id, 
                                            outputs_list=outputs_list,
                                            apps_ids_list=apps_ids_list,
                                            )
                        producerPostprocessor.publish(message)
                        
                        app_group.interface_bits = GroupState.bits['TRANSITIONING']
                        app_group.save()
                    except ObjectDoesNotExist:
                        pass
                elif ajax.isDownload() and ajax.isTargetApp():
                    try:
                        app = Application.objects.get(app_id=ajax.id)
                        
                        fileopen = default_storage.open(app.app_output_file.name, 'r')
                        fileopen.close()
                        url = s3tools.botoGetURL(settings.CONFIG, app.app_output_file.name)
                        
                        # a temporary hack
                        url_split = url.split('/', 3)
                        n_url = settings.OUTSIDE_ADDRESS + url_split[3]
                        
                        return HttpResponse(json.dumps(n_url))
                    except ObjectDoesNotExist:
                        pass
                    except IOError:
                        app.app_output_file_ready = False
                        app.interface_bits = AppState.bits['NEW']
                        app.save()
                    except S3ResponseError:
                        app.app_output_file_ready = False
                        app.interface_bits = AppState.bits['NEW']
                        app.save()
                elif ajax.isDownload() and ajax.isTargetGroup():
                    try:
                        app_group = ApplicationGroup.objects.get(group_id=ajax.id)
                        
                        fileopen = default_storage.open(app_group.output.name, 'r')
                        fileopen.close()
                        url = s3tools.botoGetURL(settings.CONFIG, app_group.output.name)
                        
                        # a temporary hack
                        url_split = url.split('/', 3)
                        n_url = settings.OUTSIDE_ADDRESS + url_split[3]
                        
                        return HttpResponse(json.dumps(n_url))
                    except ObjectDoesNotExist:
                        pass
                    except IOError:
                        app_group.output_file_ready = False
                        app_group.interface_bits = GroupState.bits['FINISHED']
                        app_group.save()
                    except S3ResponseError:
                        app_group.output_file_ready = False
                        app_group.interface_bits = GroupState.bits['FINISHED']
                        app_group.save()
                elif ajax.isTrashOutput() and ajax.isTargetGroup():
                    try:
                        app_group = ApplicationGroup.objects.get(group_id=ajax.id)
                        
                        default_storage.delete(app_group.output.name)
                        app_group.output_file_ready = False
                        app_group.interface_bits = GroupState.bits['FINISHED']
                        app_group.save()
                    except ObjectDoesNotExist:
                        pass
                    except S3ResponseError:
                        pass
                    
        return redirect(reverse('application_list'))