Ejemplo n.º 1
0
from dependencies.dependency import RecordField
from dependencies.dependency import registerField
from dependencies.dependency import *
from lims import bikaMessageFactory as _
from lims.utils import t


class DurationField(RecordField):

    """ Stores duration in Days/Hours/Minutes """
    security = ClassSecurityInfo()
    _properties = RecordField._properties.copy()
    _properties.update({
        'type': 'duration',
        'subfields': ('days', 'hours', 'minutes'),
        'subfield_labels': {'days': _('Days'),
                            'hours': _('Hours'),
                            'minutes': _('Minutes')},
        'subfield_sizes': {'days': 2,
                           'hours': 2,
                           'minutes': 2},
        'subfield_validators': {'days': 'duration_validator',
                                'hours': 'duration_validator',
                                'minutes': 'duration_validator'},
    })

registerField(DurationField,
              title="Duration",
              description="Used for storing durations",
              )
Ejemplo n.º 2
0
        value = self.getRaw(instance)
        if raw:
            # We actually wanted the raw value, should have called getRaw
            return value
        request = getSite().REQUEST
        request['catalog_name'] = self.catalog_name
        querybuilder = QueryBuilder(instance,
                                    request,
                                    catalog_name=self.catalog_name)

        sort_on = kwargs.get('sort_on', instance.getSort_on())
        sort_order = 'reverse' if instance.getSort_reversed() else 'ascending'
        limit = kwargs.get('limit', instance.getLimit())

        return querybuilder(query=value,
                            batch=kwargs.get('batch', False),
                            b_start=kwargs.get('b_start', 0),
                            b_size=kwargs.get('b_size', 30),
                            sort_on=sort_on,
                            sort_order=sort_order,
                            limit=limit,
                            brains=kwargs.get('brains', False))

    def getRaw(self, instance, **kwargs):
        return ObjectField.get(self, instance, **kwargs) or ()


registerField(QueryField,
              title='QueryField',
              description=('query field for storing a query'))
Ejemplo n.º 3
0
            val = None
        elif not isinstance(value, DateTime):
            for fmt in ['date_format_long', 'date_format_short']:
                fmtstr = instance.translate(fmt, domain='bika', mapping={})
                fmtstr = fmtstr.replace(r"${", '%').replace('}', '')
                try:
                    val = strptime(value, fmtstr)
                except ValueError:
                    continue
                try:
                    val = DateTime(*list(val)[:-6])
                except DateTimeError:
                    val = None
                if val.timezoneNaive():
                    # Use local timezone for tz naive strings
                    # see http://dev.plone.org/plone/ticket/10141
                    zone = val.localZone(safelocaltime(val.timeTime()))
                    parts = val.parts()[:-1] + (zone, )
                    val = DateTime(*parts)
                break
            else:
                logger.warning("DateTimeField failed to format date "
                               "string '%s' with '%s'" % (value, fmtstr))

        super(DateTimeField, self).set(instance, val, **kwargs)


registerField(DateTimeField,
              title='Date Time',
              description='Used for storing date/time')
Ejemplo n.º 4
0
        if delete_ids:
            # Note: subscriber might promote the AR
            instance.manage_delObjects(ids=delete_ids)
        return new_analyses

    security.declarePublic('Vocabulary')

    def Vocabulary(self, content_instance=None):
        """ Create a vocabulary from analysis services
        """
        vocab = []
        for service in self.Services():
            vocab.append((service.UID(), service.Title()))
        return vocab

    security.declarePublic('Services')

    def Services(self):
        """ Return analysis services
        """
        bsc = getToolByName(self.context, 'bika_setup_catalog')
        if not shasattr(self, '_v_services'):
            self._v_services = [service.getObject()
                                for service in bsc(portal_type='AnalysisService')]
        return self._v_services

registerField(ARAnalysesField,
              title='Analyses',
              description=('Used for Analysis instances')
              )
Ejemplo n.º 5
0
        if not value:
            val = None
        elif not isinstance(value, DateTime):
            for fmt in ['date_format_long', 'date_format_short']:
                fmtstr = instance.translate(fmt, domain='bika', mapping={})
                fmtstr = fmtstr.replace(r"${", '%').replace('}', '')
                try:
                    val = strptime(value, fmtstr)
                except ValueError:
                    continue
                try:
                    val = DateTime(*list(val)[:-6])
                except DateTimeError:
                    val = None
                if val.timezoneNaive():
                    # Use local timezone for tz naive strings
                    # see http://dev.plone.org/plone/ticket/10141
                    zone = val.localZone(safelocaltime(val.timeTime()))
                    parts = val.parts()[:-1] + (zone,)
                    val = DateTime(*parts)
                break
            else:
                logger.warning("DateTimeField failed to format date "
                               "string '%s' with '%s'" % (value, fmtstr))

        super(DateTimeField, self).set(instance, val, **kwargs)

registerField(DateTimeField,
              title='Date Time',
              description='Used for storing date/time')
Ejemplo n.º 6
0
        # singlevalued ref fields return only the object, not a list,
        # unless explicitely specified by the aslist option

        if not self.multiValued:
            if len(rd) > 1:
                log("%s references for non multivalued field %s of %s" %
                    (len(rd), self.getName(), instance))
            if not aslist:
                if rd:
                    rd = [rd[uid] for uid in rd.keys()][0]
                else:
                    rd = None

        if not self.referencesSortable or not hasattr(aq_base(instance),
                                                      'at_ordered_refs'):
            if isinstance(rd, dict):
                return [rd[uid] for uid in rd.keys()]
            else:
                return rd
        refs = instance.at_ordered_refs
        order = refs[self.relationship]

        return [rd[uid] for uid in order if uid in rd.keys()]


registerField(
    HistoryAwareReferenceField,
    title="History Aware Reference",
    description="",
)
Ejemplo n.º 7
0
        """Get the query dict from the request or from the object"""
        raw = kwargs.get("raw", None)
        value = self.getRaw(instance)
        if raw:
            # We actually wanted the raw value, should have called getRaw
            return value
        request = getSite().REQUEST
        request["catalog_name"] = self.catalog_name
        querybuilder = QueryBuilder(instance, request, catalog_name=self.catalog_name)

        sort_on = kwargs.get("sort_on", instance.getSort_on())
        sort_order = "reverse" if instance.getSort_reversed() else "ascending"
        limit = kwargs.get("limit", instance.getLimit())

        return querybuilder(
            query=value,
            batch=kwargs.get("batch", False),
            b_start=kwargs.get("b_start", 0),
            b_size=kwargs.get("b_size", 30),
            sort_on=sort_on,
            sort_order=sort_order,
            limit=limit,
            brains=kwargs.get("brains", False),
        )

    def getRaw(self, instance, **kwargs):
        return ObjectField.get(self, instance, **kwargs) or ()


registerField(QueryField, title="QueryField", description=("query field for storing a query"))
Ejemplo n.º 8
0
from dependencies.dependency import registerField
from dependencies.dependency import RecordField


class AddressField(RecordField):
    """ dedicated address field"""
    _properties = RecordField._properties.copy()
    _properties.update({
        'type': 'address',
        'subfields': ('address', 'city', 'zip', 'state', 'district', 'country'),
        'outerJoin': '<br />',
    })


registerField(AddressField,
              title="Address",
              description="Used for storing address information",
)

Ejemplo n.º 9
0
        'type':
        'angle',
        'subfields': ('degrees', 'minutes', 'seconds', 'bearing'),
        ##        'required_subfields' : ('degrees', 'minutes', 'seconds', 'bearing'),
        'subfield_labels': {
            'degrees': _('Degrees'),
            'minutes': _('Minutes'),
            'seconds': _('Seconds'),
            'bearing': _('Bearing')
        },
        'subfield_sizes': {
            'degrees': 3,
            'minutes': 2,
            'seconds': 2,
            'bearing': 1
        },
        'subfield_validators': {
            'degrees': 'coordinatevalidator',
            'minutes': 'coordinatevalidator',
            'seconds': 'coordinatevalidator',
            'bearing': 'coordinatevalidator',
        },
    })


registerField(
    CoordinateField,
    title="Coordinate",
    description="Used for storing coordinates",
)
Ejemplo n.º 10
0
    _properties = RecordsField._properties.copy()
    _properties.update({
        'fixedSize': 0,
        'minimalSize': 0,
        'maximalSize': 9999,
        'type': 'InterimFields',
        'subfields': ('keyword', 'title', 'value', 'unit', 'hidden', 'wide'),
        'required_subfields': ('keyword', 'title'),
        'subfield_labels': {'keyword': _('Keyword'),
                             'title': _('Field Title'),
                             'value': _('Default value'),
                             'unit': _('Unit'),
                             'hidden': _('Hidden Field'),
                             'wide': _('Apply wide')},
        'subfield_types': {'hidden': 'boolean', 'value': 'float', 'wide': 'boolean'},
        'subfield_sizes': {'keyword': 20,
                            'title': 20,
                            'value': 10,
                            'unit': 10},
        'subfield_validators': {'keyword': 'interimfieldsvalidator',
                                 'title': 'interimfieldsvalidator',
                                 'value': 'interimfieldsvalidator',
                                 'unit': 'interimfieldsvalidator'},
        })
    security = ClassSecurityInfo()

registerField(InterimFieldsField,
              title="Interim Fields",
              description="Used for storing Interim Fields or Interim Results.",
              )
Ejemplo n.º 11
0
import sys
from lims import bikaMessageFactory as _
from lims.utils import t

class CoordinateField(RecordField):
    """ Stores angle in deg, min, sec, bearing """
    security = ClassSecurityInfo()
    _properties = RecordField._properties.copy()
    _properties.update({
        'type' : 'angle',
        'subfields' : ('degrees', 'minutes', 'seconds', 'bearing'),
##        'required_subfields' : ('degrees', 'minutes', 'seconds', 'bearing'),
        'subfield_labels':{'degrees':_('Degrees'),
                           'minutes':_('Minutes'),
                           'seconds':_('Seconds'),
                           'bearing':_('Bearing')},
        'subfield_sizes': {'degrees':3,
                           'minutes':2,
                           'seconds':2,
                           'bearing':1},
        'subfield_validators' : {'degrees':'coordinatevalidator',
                                 'minutes':'coordinatevalidator',
                                 'seconds':'coordinatevalidator',
                                 'bearing':'coordinatevalidator',},
        })

registerField(CoordinateField,
              title = "Coordinate",
              description = "Used for storing coordinates",
              )
Ejemplo n.º 12
0
            rd[uid] = o

        # singlevalued ref fields return only the object, not a list,
        # unless explicitely specified by the aslist option

        if not self.multiValued:
            if len(rd) > 1:
                log("%s references for non multivalued field %s of %s" %
                    (len(rd), self.getName(), instance))
            if not aslist:
                if rd:
                    rd = [rd[uid] for uid in rd.keys()][0]
                else:
                    rd = None

        if not self.referencesSortable or not hasattr(aq_base(instance),
                                                      'at_ordered_refs'):
            if isinstance(rd, dict):
                return [rd[uid] for uid in rd.keys()]
            else:
                return rd
        refs = instance.at_ordered_refs
        order = refs[self.relationship]

        return [rd[uid] for uid in order if uid in rd.keys()]

registerField(HistoryAwareReferenceField,
              title="History Aware Reference",
              description="",
              )
Ejemplo n.º 13
0
            'unit': _('Unit'),
            'hidden': _('Hidden Field'),
            'wide': _('Apply wide')
        },
        'subfield_types': {
            'hidden': 'boolean',
            'value': 'float',
            'wide': 'boolean'
        },
        'subfield_sizes': {
            'keyword': 20,
            'title': 20,
            'value': 10,
            'unit': 10
        },
        'subfield_validators': {
            'keyword': 'interimfieldsvalidator',
            'title': 'interimfieldsvalidator',
            'value': 'interimfieldsvalidator',
            'unit': 'interimfieldsvalidator'
        },
    })
    security = ClassSecurityInfo()


registerField(
    InterimFieldsField,
    title="Interim Fields",
    description="Used for storing Interim Fields or Interim Results.",
)
Ejemplo n.º 14
0
from dependencies.dependency import makeDisplayList
from dependencies.dependency import RecordField, RecordsField
from dependencies.dependency import registerField
from dependencies.dependency import *
from dependencies.dependency import getToolByName
from dependencies.dependency import RegexValidator
import sys
from lims import bikaMessageFactory as _
from lims.utils import t


class ReferenceResultsField(RecordsField):

    """a list of reference sample results """
    _properties = RecordsField._properties.copy()
    _properties.update({
        'type': 'referenceresult',
        'subfields': ('uid', 'result', 'min', 'max', 'error'),
        'subfield_labels': {'uid': _('Analysis Service'),
                           'result': _('Expected Result'),
                           'error': _('Permitted Error %'),
                           'min': _('Min'),
                           'max': _('Max')},
        })
    security = ClassSecurityInfo()

registerField(ReferenceResultsField,
              title="Reference Values",
              description="Used for storing reference results",
              )