added renaming for nextcloud/webdav backends
This commit is contained in:
@ -26,7 +26,8 @@ class Nextcloud(Provider):
|
||||
import_count = 0
|
||||
for file in files:
|
||||
path = monitor.path + '/' + file
|
||||
if not Recipe.objects.filter(file_path=path).exists() and not RecipeImport.objects.filter(file_path=path).exists():
|
||||
if not Recipe.objects.filter(file_path=path).exists() and not RecipeImport.objects.filter(
|
||||
file_path=path).exists():
|
||||
name = os.path.splitext(file)[0]
|
||||
new_recipe = RecipeImport(name=name, file_path=path, storage=monitor.storage)
|
||||
new_recipe.save()
|
||||
@ -51,7 +52,8 @@ class Nextcloud(Provider):
|
||||
|
||||
data = {'path': recipe.file_path, 'shareType': 3}
|
||||
|
||||
r = requests.post(url, headers=headers, auth=HTTPBasicAuth(recipe.storage.username, recipe.storage.password), data=data)
|
||||
r = requests.post(url, headers=headers, auth=HTTPBasicAuth(recipe.storage.username, recipe.storage.password),
|
||||
data=data)
|
||||
|
||||
response_json = r.json()
|
||||
|
||||
@ -74,3 +76,17 @@ class Nextcloud(Provider):
|
||||
return element['url']
|
||||
|
||||
return Nextcloud.create_share_link(recipe)
|
||||
|
||||
@staticmethod
|
||||
def rename_file(recipe, new_name):
|
||||
options = {
|
||||
'webdav_hostname': recipe.storage.url + '/remote.php/dav/files/' + recipe.storage.username,
|
||||
'webdav_login': recipe.storage.username,
|
||||
'webdav_password': recipe.storage.password
|
||||
}
|
||||
client = wc.Client(options)
|
||||
|
||||
client.move(recipe.file_path,
|
||||
os.path.dirname(recipe.file_path) + '/' + new_name + os.path.splitext(recipe.file_path)[1])
|
||||
|
||||
return True
|
||||
|
@ -14,7 +14,3 @@ class Provider:
|
||||
@staticmethod
|
||||
def rename_file(recipe, new_name):
|
||||
raise Exception('Method not implemented in storage provider')
|
||||
|
||||
@staticmethod
|
||||
def delete_file(recipe):
|
||||
raise Exception('Method not implemented in storage provider')
|
||||
|
@ -13,6 +13,7 @@ from django.views.generic import UpdateView, DeleteView
|
||||
from cookbook.forms import ExternalRecipeForm, KeywordForm, StorageForm, SyncForm, InternalRecipeForm, CommentForm
|
||||
from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage, Comment, RecipeIngredients
|
||||
from cookbook.provider.dropbox import Dropbox
|
||||
from cookbook.provider.nextcloud import Nextcloud
|
||||
|
||||
|
||||
@login_required
|
||||
@ -198,8 +199,10 @@ class RecipeUpdate(LoginRequiredMixin, UpdateView):
|
||||
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]
|
||||
# TODO add nextcloud
|
||||
|
||||
messages.add_message(self.request, messages.SUCCESS, _('Changes saved!'))
|
||||
return super(RecipeUpdate, self).form_valid(form)
|
||||
|
@ -10,6 +10,6 @@ markdown
|
||||
simplejson
|
||||
lxml
|
||||
webdavclient3
|
||||
python-dotenv==0.7.1
|
||||
python-dotenv==0.10.3
|
||||
psycopg2
|
||||
gunicorn==19.7.1
|
||||
|
Reference in New Issue
Block a user