def delete(self, request, *args, **kwargs): self.object = self.get_object() if self.object.storage.method == Storage.DROPBOX: Dropbox.delete_file( self.object ) # TODO central location to handle storage type switches if self.object.storage.method == Storage.NEXTCLOUD: Nextcloud.delete_file(self.object) return super(RecipeSourceDelete, self).delete(request, *args, **kwargs)
def form_valid(self, form): self.object = form.save(commit=False) old_recipe = Recipe.objects.get(pk=self.object.pk) if not old_recipe.name == self.object.name: if self.object.storage.method == Storage.DROPBOX: Dropbox.rename_file(old_recipe, self.object.name) # TODO central location to handle storage type switches if self.object.storage.method == Storage.NEXTCLOUD: Nextcloud.rename_file(old_recipe, self.object.name) self.object.file_path = 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)
def delete_recipe_source(request, pk): recipe = get_object_or_404(Recipe, pk=pk) if recipe.storage.method == Storage.DROPBOX: Dropbox.delete_file(recipe) # TODO central location to handle storage type switches if recipe.storage.method == Storage.NEXTCLOUD: Nextcloud.delete_file(recipe) recipe.storage = None recipe.file_path = '' recipe.file_uid = '' recipe.save() return HttpResponseRedirect(reverse('edit_recipe', args=[recipe.pk]))
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')
def sync_all(request): monitors = Sync.objects.filter(active=True) 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 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')