Skip to content

Commit

Permalink
implement default db file field
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed Oct 12, 2017
1 parent 0b3b04f commit 72dbbef
Show file tree
Hide file tree
Showing 17 changed files with 783 additions and 568 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.rst
@@ -1,7 +1,8 @@
1.4.8 (unreleased)
1.5.0 (unreleased)
------------------

- Nothing changed yet.
- Provide default cloud file implementation
[vangheem]


1.4.7 (2017-10-10)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
1.4.8.dev0
1.5.9.dev0
9 changes: 9 additions & 0 deletions docs/source/developer/behavior.md
Expand Up @@ -193,3 +193,12 @@ DELETE behaviors : DELETE on the object/@behaviors:
"behavior": "guillotina.behaviors.dublincore.IDublinCore"
}
```



## OOTB Behaviors

Guillotina comes with a couple behaviors OOTB.

- guillotina.behaviors.dublincore.IDublinCore: Dublin core field
- guillotina.behaviors.attachment.IAttachment: Provide file field
3 changes: 2 additions & 1 deletion guillotina/_settings.py
Expand Up @@ -73,5 +73,6 @@
("application/json", interfaces.IRendererFormatJson),
("text/html", interfaces.IRendererFormatHtml),
("text/plain", interfaces.IRendererFormatPlain)
))
)),
'cloud_storage': "guillotina.interfaces.IDBFileField"
}
9 changes: 9 additions & 0 deletions guillotina/api/files.py
Expand Up @@ -7,6 +7,7 @@
from guillotina.api.service import TraversableDownloadService
from guillotina.api.service import TraversableFieldService
from guillotina.component import getMultiAdapter
from guillotina.interfaces import IAsyncBehavior
from guillotina.interfaces import IFileManager
from guillotina.interfaces import IResource
from guillotina.interfaces import IStaticDirectory
Expand Down Expand Up @@ -82,6 +83,10 @@ async def __call__(self):
class UploadFile(TraversableFieldService):

async def __call__(self):
if (self.behavior is not None and
IAsyncBehavior.implementedBy(self.behavior.__class__)):
# providedBy not working here?
await self.behavior.load(create=True)
# We need to get the upload as async IO and look for an adapter
# for the field to save there by chunks
adapter = getMultiAdapter(
Expand Down Expand Up @@ -155,6 +160,10 @@ async def __call__(self):
class TusCreateFile(UploadFile):

async def __call__(self):
if (self.behavior is not None and
IAsyncBehavior.implementedBy(self.behavior.__class__)):
# providedBy not working here?
await self.behavior.load(create=True)
# We need to get the upload as async IO and look for an adapter
# for the field to save there by chunks
adapter = getMultiAdapter(
Expand Down
1 change: 1 addition & 0 deletions guillotina/behaviors/__init__.py
@@ -1,4 +1,5 @@
# so we can scan guillotina.behaviors and load behavior configuration
from . import attachment # noqa
from . import dublincore # noqa
from guillotina.interfaces import IBehaviorAssignable
from zope.interface import alsoProvides
Expand Down
22 changes: 22 additions & 0 deletions guillotina/behaviors/attachment.py
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
from guillotina import configure
from guillotina.behaviors.instance import AnnotationBehavior
from guillotina.files import CloudFileField
from zope.interface import Interface


class IAttachmentMarker(Interface):
"""Marker interface for content with dublin core."""


class IAttachment(Interface):
file = CloudFileField()


@configure.behavior(
title="Attachment behavior",
provides=IAttachment,
marker=IAttachmentMarker,
for_="guillotina.interfaces.IResource")
class Attachment(AnnotationBehavior):
pass

0 comments on commit 72dbbef

Please sign in to comment.