Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NMRL-299 Replacement of FileField by BlobField #100

Merged
merged 8 commits into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions bika/lims/browser/analysisrequest/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ def getAttachments(self):
ar_atts = self.context.getAttachment()
analyses = self.context.getAnalyses(full_objects = True)
for att in ar_atts:
file = att.getAttachmentFile()
fsize = file.getSize() if file else 0
file_obj = att.getAttachmentFile()
fsize = file_obj.get_size() if file_obj else 0
if isinstance(fsize, tuple):
fsize = 0
if fsize < 1024:
fsize = '%s b' % fsize
else:
Expand All @@ -173,8 +175,8 @@ def getAttachments(self):
'keywords': att.getAttachmentKeys(),
'analysis': '',
'size': fsize,
'name': file.filename,
'Icon': file.icon,
'name': file_obj.filename,
'Icon': file_obj.icon,
'type': att.getAttachmentType().Title() if att.getAttachmentType() else '',
'absolute_url': att.absolute_url(),
'UID': att.UID(),
Expand All @@ -183,8 +185,8 @@ def getAttachments(self):
for analysis in analyses:
an_atts = analysis.getAttachment()
for att in an_atts:
file = att.getAttachmentFile()
fsize = file.getSize() if file else 0
file_obj = att.getAttachmentFile()
fsize = file_obj.get_size() if file_obj else 0
if fsize < 1024:
fsize = '%s b' % fsize
else:
Expand All @@ -193,8 +195,8 @@ def getAttachments(self):
'keywords': att.getAttachmentKeys(),
'analysis': analysis.Title(),
'size': fsize,
'name': file.filename,
'Icon': file.icon,
'name': file_obj.filename,
'Icon': file_obj.icon,
'type': att.getAttachmentType().Title() if att.getAttachmentType() else '',
'absolute_url': att.absolute_url(),
'UID': att.UID(),
Expand Down
3 changes: 2 additions & 1 deletion bika/lims/content/arimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from collective.progressbar.events import UpdateProgressEvent
from Products.Archetypes import atapi
from Products.Archetypes.public import *
from plone.app.blob.field import FileField as BlobFileField
from Products.Archetypes.references import HoldingReference
from Products.Archetypes.utils import addStatusMessage
from Products.CMFCore.utils import getToolByName
Expand All @@ -47,7 +48,7 @@

_p = MessageFactory(u"plone")

OriginalFile = FileField(
OriginalFile = BlobFileField(
'OriginalFile',
widget=ComputedWidget(
visible=False
Expand Down
6 changes: 4 additions & 2 deletions bika/lims/content/arreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
from AccessControl import ClassSecurityInfo
from Products.ATExtensions.ateapi import RecordsField
from Products.Archetypes import atapi
from Products.Archetypes.public import ReferenceField, FileField, \
StringField, Schema, BaseFolder
from Products.Archetypes.public import ReferenceField
from Products.Archetypes.public import StringField
from Products.Archetypes.public import Schema
from Products.Archetypes.public import BaseFolder
from plone.app.blob.field import BlobField
from Products.Archetypes.references import HoldingReference
from bika.lims.config import PROJECTNAME
Expand Down
51 changes: 21 additions & 30 deletions bika/lims/content/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,37 @@
# Copyright 2011-2016 by it's authors.
# Some rights reserved. See LICENSE.txt, AUTHORS.txt.

from Products.ATContentTypes.content import schemata
from Products.Archetypes import atapi
from AccessControl import ClassSecurityInfo
from DateTime import DateTime
from Products.ATExtensions.ateapi import DateTimeField, DateTimeWidget, RecordsField
from Products.ATExtensions.ateapi import DateTimeField, DateTimeWidget
from Products.Archetypes.config import REFERENCE_CATALOG
from Products.Archetypes.public import *
from Products.CMFCore.permissions import ListFolderContents, View
from Products.Archetypes.public import Schema
from plone.app.blob.field import FileField
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import safe_unicode
from bika.lims.content.bikaschema import BikaSchema
from bika.lims.config import PROJECTNAME
from bika.lims import bikaMessageFactory as _
from bika.lims.utils import t
from zope.interface import implements

schema = BikaSchema.copy() + Schema((
ComputedField('RequestID',
expression = 'here.getRequestID()',
widget = ComputedWidget(
visible = True,
),
),
# It comes from blob
FileField('AttachmentFile',
widget = FileWidget(
widget = atapi.FileWidget(
label=_("Attachment"),
),
),
ReferenceField('AttachmentType',
atapi.ReferenceField('AttachmentType',
required = 0,
allowed_types = ('AttachmentType',),
relationship = 'AttachmentAttachmentType',
widget = ReferenceWidget(
widget = atapi.ReferenceWidget(
label=_("Attachment Type"),
),
),
StringField('AttachmentKeys',
atapi.StringField('AttachmentKeys',
searchable = True,
widget = StringWidget(
widget = atapi.StringWidget(
label=_("Attachment Keys"),
),
),
Expand All @@ -52,25 +44,14 @@
label=_("Date Loaded"),
),
),
ComputedField('AttachmentTypeUID',
expression="context.getAttachmentType().UID() if context.getAttachmentType() else ''",
widget = ComputedWidget(
visible = False,
),
),
ComputedField('ClientUID',
expression = 'here.aq_parent.UID()',
widget = ComputedWidget(
visible = False,
),
),
),
)

schema['id'].required = False
schema['title'].required = False

class Attachment(BaseFolder):

class Attachment(atapi.BaseFolder):
security = ClassSecurityInfo()
displayContentsTab = False
schema = schema
Expand Down Expand Up @@ -125,6 +106,16 @@ def getRequestID(self):
else:
return None

def getAttachmentTypeUID(self):
attachment_type = self.getAttachmentType()
if attachment_type:
return attachment_type.UID()
else:
return ''

def getClientUID(self):
return self.aq_parent.UID()

def getAnalysis(self):
""" Return the analysis to which this is linked """
""" it may not be linked to an analysis """
Expand Down
3 changes: 2 additions & 1 deletion bika/lims/content/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Products.ATContentTypes.content import schemata
from Products.ATExtensions.ateapi import RecordsField
from Products.Archetypes.atapi import *
from plone.app.blob.field import FileField as BlobFileField
from Products.Archetypes.references import HoldingReference
from Products.CMFCore.permissions import View, ModifyPortalContent
from Products.CMFCore.utils import getToolByName
Expand Down Expand Up @@ -300,7 +301,7 @@
)
),

FileField('InstallationCertificate',
BlobFileField('InstallationCertificate',
schemata = 'Additional info.',
widget = FileWidget(
label=_("Installation Certificate"),
Expand Down
3 changes: 2 additions & 1 deletion bika/lims/content/instrumentcertification.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Products.ATContentTypes.content import schemata
from Products.Archetypes import atapi
from Products.Archetypes.public import *
from plone.app.blob.field import FileField as BlobFileField
from bika.lims import bikaMessageFactory as _
from bika.lims.utils import t
from bika.lims.browser.widgets import DateTimeWidget, ReferenceWidget
Expand Down Expand Up @@ -118,7 +119,7 @@
),
),

FileField('Document',
BlobFileField('Document',
widget = FileWidget(
label=_("Report upload"),
description=_("Load the certificate document here"),
Expand Down
3 changes: 2 additions & 1 deletion bika/lims/content/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Products.CMFCore.permissions import ModifyPortalContent, View
from Products.CMFCore.utils import getToolByName
from Products.Archetypes.public import *
from plone.app.blob.field import FileField as BlobFileField
from Products.Archetypes.references import HoldingReference
from Products.ATExtensions.ateapi import RecordsField as RecordsField
from bika.lims.browser.fields import HistoryAwareReferenceField
Expand Down Expand Up @@ -42,7 +43,7 @@
description=_("Technical description and instructions intended for analysts"),
),
),
FileField('MethodDocument', # XXX Multiple Method documents please
BlobFileField('MethodDocument', # XXX Multiple Method documents please
widget = FileWidget(
label=_("Method Document"),
description=_("Load documents describing the method here"),
Expand Down
3 changes: 2 additions & 1 deletion bika/lims/content/multifile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from zope.interface import implements
from Products.Archetypes import atapi
from plone.app.blob.field import FileField
from Products.Archetypes.public import BaseContent
from bika.lims.interfaces import IMultifile
from bika.lims.content.bikaschema import BikaSchema
Expand All @@ -22,7 +23,7 @@
)
),

atapi.FileField('File',
FileField('File',
required=1,
widget = atapi.FileWidget(
label=_("Document"),
Expand Down
15 changes: 8 additions & 7 deletions bika/lims/content/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from Products.ATExtensions.ateapi import DateTimeField, DateTimeWidget
from Products.Archetypes.config import REFERENCE_CATALOG
from Products.Archetypes.public import *
from plone.app.blob.field import FileField as BlobFileField
from Products.CMFCore.permissions import ListFolderContents, View
from Products.CMFCore.utils import getToolByName
from bika.lims.content.bikaschema import BikaSchema
Expand All @@ -19,7 +20,7 @@
from zope.interface import implements

schema = BikaSchema.copy() + Schema((
FileField('ReportFile',
BlobFileField('ReportFile',
widget = FileWidget(
label=_("Report"),
),
Expand All @@ -37,12 +38,6 @@
label=_("Client"),
),
),
ComputedField('ClientUID',
expression = 'here.getClient() and here.getClient().UID()',
widget = ComputedWidget(
visible = False,
),
),
),
)

Expand All @@ -64,5 +59,11 @@ def current_date(self):
""" return current date """
return DateTime()

def getClientUID(self):
client = self.getClient()
if client:
return client.UID()
return ''


atapi.registerType(Report, PROJECTNAME)
3 changes: 2 additions & 1 deletion bika/lims/content/samplepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from AccessControl import ClassSecurityInfo
from Products.Archetypes.public import *
from plone.app.blob.field import FileField as BlobFileField
from Products.ATContentTypes.lib.historyaware import HistoryAwareMixin
from Products.CMFCore.permissions import View, ModifyPortalContent
from Products.CMFCore.utils import getToolByName
Expand Down Expand Up @@ -83,7 +84,7 @@
"The default, unchecked, indicates 'grab' samples"),
),
),
FileField('AttachmentFile',
BlobFileField('AttachmentFile',
widget = FileWidget(
label=_("Attachment"),
),
Expand Down
Loading