Esempio n. 1
0
def _handle_upload(request, form):
    if form.is_valid():
        file_name = 'uploads/gedcoms/%d_%s' % (
            time.time(), form.cleaned_data['gedcom_file'].name)
        default_storage.save(file_name, form.cleaned_data['gedcom_file'])
        async_update.delay(form.cleaned_data['gedcom_id'],
                           os.path.join(settings.MEDIA_ROOT, file_name),
                           form.cleaned_data['email_users'],
                           form.cleaned_data['message'], request.get_host(),
                           request.user.id)
        messages.success(
            request,
            'Your gedcom file has been uploaded and the database will '
            'be updated momentarily.')
    else:
        error_message = ('Something went wrong with your upload, '
                         'please try again later.')
        if hasattr(form, 'error_message'):
            error_message = form.error_message
        messages.error(request, error_message)
Esempio n. 2
0
def update_view(request, gedcom_id):
    if not request.user.is_superuser:
        return redirect('/gedgo')

    g = get_object_or_404(Gedcom, id=gedcom_id)
    message = ''
    celerystate = inspect()

    if celerystate.active() is not None:  # TODO: Check task names.
        form = ''
        message = 'This gedcom is currently being updated already. Please check back later.'
    elif request.method == 'POST':
        form = UpdateForm(request.POST, request.FILES)
        # check for temp file
        if form.is_valid():
            # TODO: Make friendly to other OSes.
            content = request.FILES['gedcom_file'].read().split("\r")

            # Call celery worker
            async_update.delay(g, content)

            # Redirect to the document list after POST
            form = ''
            message = 'Upload successful. Gedcom updating.'
        else:
            form = UpdateForm()
            message = 'Did you correctly upload a gedcom file?'

    else:
        form = UpdateForm()

    # Render list page with the documents and the form
    return render_to_response('gedgo/update.html', {
        'form': form,
        'message': message,
        'gedcom': g
    },
                              context_instance=RequestContext(
                                  request, site_context(request)))
Esempio n. 3
0
File: update.py Progetto: RaD/gedgo
def update_view(request, gedcom_id):
    if not request.user.is_superuser:
        return redirect('/gedgo')

    g = get_object_or_404(Gedcom, id=gedcom_id)
    message = ''
    celerystate = inspect()

    if celerystate.active() is not None:  # TODO: Check task names.
        form = ''
        message = 'This gedcom is currently being updated already. Please check back later.'
    elif request.method == 'POST':
        form = UpdateForm(request.POST, request.FILES)
        # check for temp file
        if form.is_valid():
            # TODO: Make friendly to other OSes.
            content = request.FILES['gedcom_file'].read().split("\r")

            # Call celery worker
            async_update.delay(g, content)

            # Redirect to the document list after POST
            form = ''
            message = 'Upload successful. Gedcom updating.'
        else:
            form = UpdateForm()
            message = 'Did you correctly upload a gedcom file?'

    else:
        form = UpdateForm()

    # Render list page with the documents and the form
    return render_to_response(
        'gedgo/update.html',
        {'form': form, 'message': message, 'gedcom': g},
        context_instance=RequestContext(request, site_context(request)))
Esempio n. 4
0
def _handle_upload(request, form):
    if form.is_valid():
        file_name = 'uploads/gedcoms/%d_%s' % (
            time.time(), form.cleaned_data['gedcom_file'].name)
        default_storage.save(file_name, form.cleaned_data['gedcom_file'])
        async_update.delay(
            form.cleaned_data['gedcom_id'],
            os.path.join(settings.MEDIA_ROOT, file_name),
            form.cleaned_data['email_users'],
            form.cleaned_data['message'],
            request.get_host(),
            request.user.id
        )
        messages.success(
            request,
            'Your gedcom file has been uploaded and the database will '
            'be updated momentarily.'
        )
    else:
        error_message = ('Something went wrong with your upload, '
                         'please try again later.')
        if hasattr(form, 'error_message'):
            error_message = form.error_message
        messages.error(request, error_message)