示例#1
0
def receiveInput(request,xsl):
    ConvForm = ConversionForm(request.REQUEST, request.FILES)
    if ConvForm.is_valid():
        conv = Conversion(xsl=xsl,
                   upload=ConvForm.cleaned_data['upload'],
                   url=ConvForm.cleaned_data['url'] )
        conv.save(force_insert=True)

        # start the work in the background
        bg = DoWork(conv)
        bg.start()
        # give it a second, so we might skip the
        # waiting-page for quick transforms
        sleep(2)
        return HttpResponseRedirect(settings.DEPLOY_URL+'applyXSL/%s/result/%s'%(xsl,conv.pk))
    else:
        return HttpResponseRedirect(settings.DEPLOY_URL+'applyXSL/%s/'%xsl)
示例#2
0
文件: medida.py 项目: esw/SapInt
 def get_valor(self,unidad=None):
     if not unidad: return self.valor
     if isinstance(unidad,str): u = UnidadMedida.buscar(unidad)
     else: u = unidad
     if not u or u == self.unidad: return self.valor
     if isinstance(u,UnidadMedida) and u != self.unidad:
         return self.valor * Conversion.buscar_factor(self.unidad,u)
     return None
示例#3
0
def receiveInput(request, xsl):
    ConvForm = ConversionForm(request.POST, request.FILES)
    if ConvForm.is_valid():
        conv = Conversion(xsl=xsl,
                          upload=ConvForm.cleaned_data['upload'],
                          url=ConvForm.cleaned_data['url'])
        conv.save(force_insert=True)

        # start the work in the background
        bg = DoWork(conv)
        bg.start()
        # give it a second, so we might skip the
        # waiting-page for quick transforms
        sleep(2)
        return HttpResponseRedirect(APPURL + '%s/result/%s' % (xsl, conv.pk))
    else:
        return HttpResponseRedirect(APPURL + '%s/' % xsl)
示例#4
0
    def get_for_me(userId):
        pr = Collaborative.predict(userId)

        uids = []
        for (mid, rating) in pr:
            imdb_id = Conversion.getImdbId(mid)
            if imdb_id != -1:
                uids.append(int(imdb_id))
        return jsonify({'results': cont.get_rec_json_imdb(uids)})
示例#5
0
def download():
    docId = request.json.get('docId')
    conversion = Conversion.get_by_doc_id(docId, g.user.id)
    if conversion and conversion.status == STATUS.completed:
        return jsonify({
            'status': conversion.status,
            'signed_url': get_signed_url(conversion.get_remote_location()),
            'doc_id': docId
            }
        ), 200
    return jsonify({'status': conversion.status, 'doc_id': docId}), 200
示例#6
0
def request_fetcher():
    # Get conversions by priority
    conversions = Conversion.get_requests_by_priority()

    # Forward request ids to document converter
    conversion_ids = map(lambda conversion: conversion.id, conversions)

    if conversion_ids:
        document_converter.delay(conversion_ids)

        # Mark Queued
        for conversion in conversions:
            conversion.status = STATUS.queued
            db.session.commit()
def destination(request, page_id, destination_id=None):
    """
    controller to set the (new) destination page for the passed in id

    similar to edit page, but slightly different processing
    """

    cur_destination = None
    destination_options = Page.objects.filter(id=destination_id)
    if len(destination_options):
        cur_destination = destination_options[0]

    page_options = Page.objects.filter(id=page_id)
    if len(page_options):
        cur_page = page_options[0]

    if request.method == 'POST':
        #print "POST!"
        pageform = PageForm(request.POST, instance=cur_destination,
                            prefix='pages')

        if pageform.is_valid(): # All validation rules pass

            existing = check_pageform(pageform, request, cur_destination)
            if existing:
                messages.warning(request, 'Found an existing destination with that URL. Setting it as a destination for source page.')
                new_destination = existing
                
            else:
                #now it's ok to save the changes:
                new_destination = pageform.save()

            #all_conversions = Conversion.objects.all()
            #print all_conversions
            
            #look for existing Conversion first!
            conversion_options = Conversion.objects.filter(source=cur_page).filter(destination=new_destination)
            print conversion_options
            if len(conversion_options):
                messages.warning(request, 'These pages are already associated')
                cur_conversion = conversion_options[0]
            else:

                #associate new_destination and cur_page via new Conversion object
                conversion = Conversion()
                conversion.source = cur_page
                conversion.destination = new_destination

                #TODO:
                #consider if notes are useful here
                #conversion.notes = '?'
                conversion.save()

                messages.info(request, 'New destination was added')

            
            finished_url = reverse('pages:details', kwargs={'page_id':cur_page.id})

            return redirect(finished_url)

    else:
        pageform = PageForm(prefix='pages', instance=cur_destination)

    context = { 'pageform': pageform,
                }
    return render(request, 'pages-edit.html', context)
示例#8
0
def upload():
    # Get priority
    priority = int(request.form.get('priority', PRIORITY.medium))
    if priority not in PRIORITY.get_values():
        priority = PRIORITY.medium

    # Get output formats
    output_formats = request.form.get('output-formats', '')
    output_formats = list(set(
        filter(
            lambda format: format in app.config['ALLOWED_EXTENSIONS'],
            output_formats.split(';')
        )
    ))
    if not output_formats:
        return jsonify({'Error': 'Must provide valid output formats'}), 400

    # Get file (either directly or via URL)
    file = request.files.get('file')
    allowed_extensions = app.config['ALLOWED_EXTENSIONS']

    if file:
        if allowed_filename(file.filename, allowed_extensions):
            filename = secure_filename(file.filename).strip()[-FILE_NAME_LIMIT]
            local_path = os.path.join(app.config['UPLOAD_FOLDER'],
                                      timestamp_filename(filename))
            file.save(local_path)
        else:
            return jsonify({'Error': 'File format not allowed'}), 400
    else:
        fileURL = request.form.get('fileURL')
        if fileURL:
            filename = get_filename_from_url(fileURL)

            try:
                local_path = download_url(
                    fileURL, app.config['UPLOAD_FOLDER'], timestamp=True)
            except FileAccessDenied as fad:
                return jsonify({
                    'status': 'error',
                    'code': fad.status_code,
                    'message': fad.message
                }), 500

        else:
            return jsonify({'status': 'error',
                            'message': 'Unable to decode uploaded file'}), 500

    # Upload to remote and remove file from local
    remote_destination = os.path.join(app.config['REMOTE_INPUT_FOLDER'],
                                      get_uuid(), filename)
    upload_to_remote(remote_destination, local_path)
    os.remove(local_path)

    # Register the file for conversions and return docIds
    docIds = Conversion.register_file(filename, remote_destination,
                                      g.user, output_formats, priority)

    # Call request fetcher
    request_fetcher.delay()

    return jsonify({'status': STATUS.introduced, 'doc_ids': docIds})