Shared gdrive access
This commit is contained in:
parent
4cef5800bc
commit
ef981e06e8
@ -106,13 +106,13 @@ class GDriveLinkStorage(Storage):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
def import_link(self, url) -> str:
|
def import_link(self, url) -> str:
|
||||||
file_id = self.extract_id(url, SHARED_FILE)
|
file_id = self.extract_id(url, SHARED_FILE)
|
||||||
meta = self.get_meta(file_id)
|
meta = self.get_meta(file_id)
|
||||||
return f"{file_id}/{meta['name']}"
|
return f"{file_id}/{meta['name']}"
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
def folder_import(self, url) -> list[str]:
|
def folder_import(self, url) -> list[str]:
|
||||||
folder_id = self.extract_id(url, SHARED_FOLDER)
|
folder_id = self.extract_id(url, SHARED_FOLDER)
|
||||||
_, files = self.listdir(folder_id)
|
_, files = self.listdir(folder_id)
|
||||||
|
|||||||
@ -4,6 +4,7 @@ from django.views.generic.detail import SingleObjectMixin
|
|||||||
from polyphonic.library.views import CollectionMixin
|
from polyphonic.library.views import CollectionMixin
|
||||||
from polyphonic.library.models import Work, Document
|
from polyphonic.library.models import Work, Document
|
||||||
from polyphonic.library import forms
|
from polyphonic.library import forms
|
||||||
|
from byostorage.models import UserStorage
|
||||||
|
|
||||||
|
|
||||||
class WorkGDriveView(CollectionMixin, SingleObjectMixin, FormView):
|
class WorkGDriveView(CollectionMixin, SingleObjectMixin, FormView):
|
||||||
@ -27,23 +28,19 @@ class WorkGDriveView(CollectionMixin, SingleObjectMixin, FormView):
|
|||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
link = form.cleaned_data["link"]
|
link = form.cleaned_data["link"]
|
||||||
|
|
||||||
storage = self.collection.storage.instance()
|
# storage = self.collection.storage.instance()
|
||||||
|
storage = UserStorage.objects.get(name="gdrive").instance()
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
|
||||||
try:
|
folderid = storage.get_folder_id(link)
|
||||||
folderid = storage.get_folder_id(link)
|
if folderid:
|
||||||
self.object.meta_info.update_or_create(
|
self.object.meta_info.update_or_create(
|
||||||
name="folderid", defaults={"value": folderid}
|
name="folderid", defaults={"value": folderid}
|
||||||
)
|
)
|
||||||
return redirect("work_detail", self.collection.pk, self.kwargs["pk"])
|
return redirect("work_detail", self.collection.pk, self.kwargs["pk"])
|
||||||
except FileNotFoundError:
|
|
||||||
pass # not a folder id
|
|
||||||
|
|
||||||
try:
|
link = storage.import_link(link)
|
||||||
link = self.collection.storage.instance().import_link(link)
|
if link is None:
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
except FileNotFoundError as e:
|
|
||||||
form.add_error("link", str(e))
|
form.add_error("link", str(e))
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
@ -51,7 +48,8 @@ class WorkGDriveView(CollectionMixin, SingleObjectMixin, FormView):
|
|||||||
|
|
||||||
doc = Document(
|
doc = Document(
|
||||||
work=work,
|
work=work,
|
||||||
upload=f"{self.collection.storage.name}:{link}",
|
upload=f"gdrive:{link}",
|
||||||
|
# upload=f"{self.collection.storage.name}:{link}",
|
||||||
doctype=Document.DOCTYPE_PDF,
|
doctype=Document.DOCTYPE_PDF,
|
||||||
)
|
)
|
||||||
doc.save()
|
doc.save()
|
||||||
|
|||||||
@ -129,16 +129,19 @@
|
|||||||
{% if request.is_admin %}
|
{% if request.is_admin %}
|
||||||
<div class="column is-one-quarter">
|
<div class="column is-one-quarter">
|
||||||
<h4 class="is-size-5">Add Files</h4>
|
<h4 class="is-size-5">Add Files</h4>
|
||||||
{% if "gdrive" in methods %}
|
|
||||||
<div class="has-text-centered mt-3">
|
|
||||||
<a class="button button-primary" href="{% url 'work_gdrive' collection.pk object.pk %}">Link Google Drive Files</a><br/>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% if "upload" in methods %}
|
{% if "upload" in methods %}
|
||||||
<form action="{% url 'document_add' collection.pk object.pk %}" class="dropzone" id="doc-upload" style="-moz-user-select: none">
|
<form action="{% url 'document_add' collection.pk object.pk %}" class="dropzone" id="doc-upload" style="-moz-user-select: none">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if "gdrive" in methods %}
|
||||||
|
<div class="has-text-centered mt-3">
|
||||||
|
<a class="button button-primary is-size-7" href="{% url 'work_gdrive' collection.pk object.pk %}">
|
||||||
|
<span class="icon"><i class="fa-brands fa-google-drive"></i></span>
|
||||||
|
Link Google Drive Files
|
||||||
|
</a><br/>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -319,11 +319,13 @@ class WorkDetailView(CollectionMixin, DetailView):
|
|||||||
def get_context_data(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
context = super().get_context_data(*args, **kwargs)
|
context = super().get_context_data(*args, **kwargs)
|
||||||
|
|
||||||
methods = set("upload")
|
methods = set(["upload"])
|
||||||
match self.collection.storage.storage:
|
match self.collection.storage.storage:
|
||||||
case "library.storage.GDriveLinkStorage":
|
case "library.gdrive.storage.GDriveLinkStorage":
|
||||||
methods.discard("upload")
|
methods.discard("upload")
|
||||||
methods.add("gdrive")
|
methods.add("gdrive")
|
||||||
|
case _:
|
||||||
|
methods.add("gdrive")
|
||||||
context["methods"] = methods
|
context["methods"] = methods
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user