예제 #1
0
def save_import(deferred, email):

    from openbudget.apps.transport.incoming.importers import TablibImporter

    importer = TablibImporter()
    save = importer.resolve(deferred)

    sender = settings.EMAIL_HOST_USER
    recipient = email

    if save:
        subject = 'IMPORT SAVED'
        message = 'HOORAH!'

    else:
        subject = 'IMPORT FAILED'
        message = 'BUMMER!'

    return send_mail(
        subject,
        message,
        sender,
        [recipient],
        fail_silently=True
    )
예제 #2
0
    def form_valid(self, form, *args, **kwargs):
        use_filename = True
        sourcefile = self.request.FILES['sourcefile']
        post_data = self.request.POST.copy()

        if 'type' in post_data and 'attributes' in post_data:
            use_filename = False

        importer = TablibImporter(sourcefile,
                                  post_data,
                                  dataset_meta_in_filename=use_filename)
        valid, errors = importer.validate()
        if not valid:
            error_dicts = [e.__dict__() for e in errors]
            return HttpResponseBadRequest(json.dumps(error_dicts),
                                          content_type='application/json')

        if self.request.is_ajax():
            save_import.apply_async(
                (importer.deferred(), self.request.user.email))
            return HttpResponse('OK')
        else:
            save = importer.save()
            if save:
                return redirect('import_success')
            else:
                return HttpResponseServerError('SAVE FAILED')
예제 #3
0
    def form_valid(self, form, *args, **kwargs):
        use_filename = True
        sourcefile = self.request.FILES['sourcefile']
        post_data = self.request.POST.copy()

        if 'type' in post_data and 'attributes' in post_data:
            use_filename = False

        importer = TablibImporter(
            sourcefile,
            post_data,
            dataset_meta_in_filename=use_filename
        )
        valid, errors = importer.validate()
        if not valid:
            error_dicts = [e.__dict__() for e in errors]
            return HttpResponseBadRequest(json.dumps(error_dicts), content_type='application/json')

        if self.request.is_ajax():
            save_import.apply_async((importer.deferred(), self.request.user.email))
            return HttpResponse('OK')
        else:
            save = importer.save()
            if save:
                return redirect('import_success')
            else:
                return HttpResponseServerError('SAVE FAILED')
예제 #4
0
def save_import(deferred, email):

    from openbudget.apps.transport.incoming.importers import TablibImporter

    importer = TablibImporter()
    save = importer.resolve(deferred)

    sender = settings.EMAIL_HOST_USER
    recipient = email

    if save:
        subject = 'IMPORT SAVED'
        message = 'HOORAH!'

    else:
        subject = 'IMPORT FAILED'
        message = 'BUMMER!'

    return send_mail(subject, message, sender, [recipient], fail_silently=True)