Exemple #1
0
def sync_all(request):
    if request.space.demo:
        messages.add_message(
            request, messages.ERROR, _('This feature is not available in the demo version!')
        )
        return redirect('index')

    monitors = Sync.objects.filter(active=True).filter(space=request.user.userpreference.space)

    error = False
    for monitor in monitors:
        if monitor.storage.method == Storage.DROPBOX:
            ret = Dropbox.import_all(monitor)
            if not ret:
                error = True
        if monitor.storage.method == Storage.NEXTCLOUD:
            ret = Nextcloud.import_all(monitor)
            if not ret:
                error = True
        if monitor.storage.method == Storage.LOCAL:
            ret = Local.import_all(monitor)
            if not ret:
                error = True

    if not error:
        messages.add_message(
            request, messages.SUCCESS, _('Sync successful!')
        )
        return redirect('list_recipe_import')
    else:
        messages.add_message(
            request, messages.ERROR, _('Error synchronizing with Storage')
        )
        return redirect('list_recipe_import')
Exemple #2
0
def delete_recipe_source(request, pk):
    recipe = get_object_or_404(Recipe, pk=pk, space=request.space)

    if recipe.storage.method == Storage.DROPBOX:
        # TODO central location to handle storage type switches
        Dropbox.delete_file(recipe)
    if recipe.storage.method == Storage.NEXTCLOUD:
        Nextcloud.delete_file(recipe)
    if recipe.storage.method == Storage.LOCAL:
        Local.delete_file(recipe)

    recipe.storage = None
    recipe.file_path = ''
    recipe.file_uid = ''
    recipe.save()

    return HttpResponseRedirect(reverse('edit_recipe', args=[recipe.pk]))
Exemple #3
0
    def form_valid(self, form):
        self.object = form.save(commit=False)
        old_recipe = Recipe.objects.get(pk=self.object.pk,
                                        space=self.request.space)
        if not old_recipe.name == self.object.name:
            # TODO central location to handle storage type switches
            if self.object.storage.method == Storage.DROPBOX:
                Dropbox.rename_file(old_recipe, self.object.name)
            if self.object.storage.method == Storage.NEXTCLOUD:
                Nextcloud.rename_file(old_recipe, self.object.name)
            if self.object.storage.method == Storage.LOCAL:
                Local.rename_file(old_recipe, self.object.name)

            self.object.file_path = "%s/%s%s" % (
                os.path.dirname(self.object.file_path), self.object.name,
                os.path.splitext(self.object.file_path)[1])

        messages.add_message(self.request, messages.SUCCESS,
                             _('Changes saved!'))
        return super(ExternalRecipeUpdate, self).form_valid(form)