Esempio n. 1
0
    def getResponse(self, request, args):

        response = {'success': False, 'response': ''}
        args = self.reqparse.parse_args()
        result = ModelBroadcastEventOverride.updateordering(args.get('trackid'), int(args.get('position')))

        if result['error']:
            response['response'] = 'Could not reorder track'
        else:
            response['response'] = 'Success!'
            response['eventid'] = str(result['event_id'])
            response['trackid'] = str(result['track_id'])
            response['position'] = result['position']
            response['success'] = True

        return Response(response)
Esempio n. 2
0
    def getResponse(self, request, args):

        response = {'success': False, 'response': ''}
        args = self.reqparse.parse_args()
        result = ModelBroadcastEventOverride.remove(args.get('trackid'))

        if result['error']:
            if result['error'] == 1:
                response['response'] = 'Track not found'
            if result['error'] == 2:
                response['response'] = 'Could not remove track'
        else:
            response['response'] = 'Success!'
            response['trackid'] = str(result['preprod_id'])
            response['filename'] = os.path.basename(str(result['location']).replace('file://',''))
            response['success'] = True

        return Response(response)
Esempio n. 3
0
    def getResponse(self, request, args):

        def save_file(f, path):
            with open(path, 'wb+') as destination:
                for chunk in f.chunks():
                    destination.write(chunk)
                    
        response = {'success': False, 'response': ''}
        queries = Q()

        if args.get('identifier'):
            queries = queries & Q(identifier=args.get('identifier'))

        if args.get('programme_id'):
            queries = queries & Q(programme_id=args.get('programme_id'))

        if args.get('station_id'):
            queries = queries & Q(station_id=args.get('station_id'))

        if args.get('start'):
            t = datetime.datetime.strptime(args.get('start'), '%Y-%m-%dT%H:%M')
            queries = queries & Q(start=t)

        if args.get('end'):
            t = datetime.datetime.strptime(args.get('end'), '%Y-%m-%dT%H:%M')
            queries = queries & Q(end=t)


        events = BroadcastEvent.objects(queries)

        if len(events) == 0:
            raise Http404

        event = events[0]

        if args.get('audio'):
            file_object = request.FILES['audio']
            fileName = secure_filename(file_object.name)
            fid, path = tempfile.mkstemp()

            try:
                save_file(file_object, path)
            except:
                response['response'] = "Upload Error"
                return Response(response)
            result = ModelBroadcastEventOverride.add(event, settings.COMBA.get('upload_folder', '/var/audio/preprod/'), fileName, path)
        else:
            result = {'error': "Upload empty"}


        if result['error']:
            response['response'] = result['error']
        else:
            response['identifier'] = event.identifier
            if result['preprod_id']:
                response['trackid'] = str(result['preprod_id'])
            if result['ordering']:
                response['ordering'] = result['ordering']
            if result['location']:
                response['filename'] = os.path.basename(str(result['location']).replace('file://',''))
            response['success'] = True

        return Response(response)