Exemple #1
0
def import_recipe(request):
    limit, msg = above_space_limit(request.space)
    if limit:
        messages.add_message(request, messages.WARNING, msg)
        return HttpResponseRedirect(reverse('index'))

    if request.method == "POST":
        form = ImportForm(request.POST, request.FILES)
        if form.is_valid() and request.FILES != {}:
            try:
                integration = get_integration(request, form.cleaned_data['type'])

                il = ImportLog.objects.create(type=form.cleaned_data['type'], created_by=request.user, space=request.space)
                files = []
                for f in request.FILES.getlist('files'):
                    files.append({'file': BytesIO(f.read()), 'name': f.name})
                t = threading.Thread(target=integration.do_import, args=[files, il, form.cleaned_data['duplicates']])
                t.setDaemon(True)
                t.start()

                return JsonResponse({'import_id': il.pk})
            except NotImplementedError:
                return JsonResponse(
                    {
                        'error': True,
                        'msg': _('Importing is not implemented for this provider')
                    },
                    status=400
                )
    else:
        form = ImportForm()

    return render(request, 'import.html', {'form': form})
Exemple #2
0
def import_url(request):
    limit, msg = above_space_limit(request.space)
    if limit:
        messages.add_message(request, messages.WARNING, msg)
        return HttpResponseRedirect(reverse('index'))

    if (api_token := Token.objects.filter(user=request.user).first()) is None:
        api_token = Token.objects.create(user=request.user)
Exemple #3
0
def internal_recipe_update(request, pk):
    limit, msg = above_space_limit(request.space)
    if limit:
        messages.add_message(request, messages.WARNING, msg)
        return HttpResponseRedirect(reverse('view_recipe', args=[pk]))

    recipe_instance = get_object_or_404(Recipe, pk=pk, space=request.space)

    return render(request, 'forms/edit_internal_recipe.html', {'recipe': recipe_instance})
Exemple #4
0
def sync(request):
    limit, msg = above_space_limit(request.space)
    if limit:
        messages.add_message(request, messages.WARNING, msg)
        return HttpResponseRedirect(reverse('index'))

    if request.space.demo or settings.HOSTED:
        messages.add_message(
            request, messages.ERROR,
            _('This feature is not yet available in the hosted version of tandoor!'
              ))
        return redirect('index')

    if request.method == "POST":
        if not has_group_permission(request.user, ['admin']):
            messages.add_message(
                request, messages.ERROR,
                _('You do not have the required permissions to view this page!'
                  ))
            return HttpResponseRedirect(reverse('data_sync'))
        form = SyncForm(request.POST, space=request.space)
        if form.is_valid():
            new_path = Sync()
            new_path.path = form.cleaned_data['path']
            new_path.storage = form.cleaned_data['storage']
            new_path.last_checked = datetime.now()
            new_path.space = request.space
            new_path.save()
            return redirect('data_sync')
    else:
        form = SyncForm(space=request.space)

    monitored_paths = SyncTable(Sync.objects.filter(space=request.space).all())
    RequestConfig(request, paginate={
        'per_page': 25
    }).configure(monitored_paths)

    return render(request, 'batch/monitor.html', {
        'form': form,
        'monitored_paths': monitored_paths
    })
Exemple #5
0
 def validate(self, data):
     above_limit, msg = above_space_limit(self.context['request'].space)
     if above_limit:
         raise serializers.ValidationError(msg)
     return super().validate(data)