예제 #1
0
    def testSmallUpload(self):
        small_file = relative('small.txt')
        assert False, small_file
        upload = Upload(name="Test upload",
                             file=small_file,
                             created_by=self.mrtest,
                             last_edited_by=self.mrtest)
        upload.save()

        self.assertIsNotNone(Upload.objects.get(name="Test upload"))

        from pannel.tasks import Convert
        from celery.task import subtask

        task_opts = {'user_pk': self.mrtest.pk,
                     'upload_pk': upload.pk,
                     'cache': 'cachekey',
                     'converter': '1'} # matches format in small.txt

        result = Convert.delay(task_opts, callback=subtask(tasks.delete_upload))
예제 #2
0
파일: add.py 프로젝트: airstrike/athena
class UploadAdd(UploadMixin, MenuMixin, FormView):
    form_class = UploadForm
    template_name = 'upload/add.html'
    success_url = '/pannel/upload/list/'
    selected = ['upload', 'new_upload']
    action = 'add'

    def get_context_data(self, **kwargs):
        context = super(UploadAdd, self).get_context_data(**kwargs)
        context['template_title'] = _('Pannel | Upload')

        return context

    def form_valid(self, form):
        logging.info("Upload form is valid: %s" % form)
        self.upload = Upload()
        self.upload.created_by = self.request.user
        self.upload.last_edited_by = self.request.user
        self.status = 1
        self.upload.timestamp = datetime.datetime.now()
        self.cache_key = None

        if 'X-Progress-ID' in self.request.GET:
            self.progress_id = self.request.GET['X-Progress-ID']
            self.cache_key = "%s_%s" % (self.request.META['REMOTE_ADDR'], self.progress_id)
            self.upload.cache_key = self.cache_key

        save_instance(form, self.upload, commit=False)

        self.upload.save()
        self.uploaded = self.upload.file
        upload_task = tasks.Convert
        task_opts = {'user_pk': self.request.user.pk,
                     'upload_pk': self.upload.pk,
                     'cache': self.cache_key,
                     'converter': form.cleaned_data.get('converter', None)}

        logging.debug(task_opts)
        result = upload_task.delay(task_opts, callback=subtask(tasks.delete_upload))

        self.upload.celery_task_id = result.task_id
        self.upload.result = result.status
        self.upload.update_progress()
        self.upload.save()

        logging.info("Saved upload: %s" % self.upload)

        error(self.request, u'%s' % _('File %s is being processed.') % self.uploaded)

        return super(UploadAdd, self).form_valid(form)
예제 #3
0
파일: add.py 프로젝트: airstrike/athena
    def form_valid(self, form):
        logging.info("Upload form is valid: %s" % form)
        self.upload = Upload()
        self.upload.created_by = self.request.user
        self.upload.last_edited_by = self.request.user
        self.status = 1
        self.upload.timestamp = datetime.datetime.now()
        self.cache_key = None

        if 'X-Progress-ID' in self.request.GET:
            self.progress_id = self.request.GET['X-Progress-ID']
            self.cache_key = "%s_%s" % (self.request.META['REMOTE_ADDR'], self.progress_id)
            self.upload.cache_key = self.cache_key

        save_instance(form, self.upload, commit=False)

        self.upload.save()
        self.uploaded = self.upload.file
        upload_task = tasks.Convert
        task_opts = {'user_pk': self.request.user.pk,
                     'upload_pk': self.upload.pk,
                     'cache': self.cache_key,
                     'converter': form.cleaned_data.get('converter', None)}

        logging.debug(task_opts)
        result = upload_task.delay(task_opts, callback=subtask(tasks.delete_upload))

        self.upload.celery_task_id = result.task_id
        self.upload.result = result.status
        self.upload.update_progress()
        self.upload.save()

        logging.info("Saved upload: %s" % self.upload)

        error(self.request, u'%s' % _('File %s is being processed.') % self.uploaded)

        return super(UploadAdd, self).form_valid(form)