示例#1
0
 def __call__(self):
     return dict(
         business_types=BusinessType.query().all(),
         file_types=FileType.query().all(),
         items=self._collect_items(),
         breadcrumb=self.breadcrumb,
         back_link=self.back_link,
         help_message=self.help_message,
     )
示例#2
0
 def __call__(self):
     return dict(
         business_types=BusinessType.query().all(),
         file_types=FileType.query().all(),
         items=self._collect_items(),
         breadcrumb=self.breadcrumb,
         back_link=self.back_link,
         help_message=self.help_message,
     )
示例#3
0
    def _collect_available_types(self, context):
        """
        Collect file types that may be loaded for the given context

        :param obj context: The current object we're attaching a file to
        :returns: A list of FileType instances
        """
        result = []
        if isinstance(context, File):
            context = context.parent

        if isinstance(context, Task) or isinstance(context, Business):
            business_type_id = context.business_type_id

            result = BusinessTypeFileType.get_file_type_options(
                business_type_id, context.type_)
        else:
            result = FileType.query().options(load_only('id', 'label')).all()
        return result
示例#4
0
    def _collect_available_types(self, context):
        """
        Collect file types that may be loaded for the given context

        :param obj context: The current object we're attaching a file to
        :returns: A list of FileType instances
        """
        result = []
        if isinstance(context, File):
            context = context.parent

        if isinstance(context, Task) or isinstance(context, Business):
            business_type_id = context.business_type_id

            result = BusinessTypeFileType.get_file_type_options(
                business_type_id, context.type_
            )
        else:
            result = FileType.query().options(load_only('id', 'label')).all()
        return result
示例#5
0
    def get_file_type_options(cls, business_type_id, doctype):
        """
        Collect FileTypes associated to (business_type_id, doctype)

        :param int business_type_id: The business type id
        :param str doctype: One of the available doctypes
        :returns: A :class:`sqlalchemy.orm.Query`
        """
        id_query = cls.query('file_type_id')
        id_query = id_query.filter_by(business_type_id=business_type_id)
        id_query = id_query.filter_by(doctype=doctype)
        ids = [i[0] for i in id_query]

        result = []
        if ids is not None:
            from autonomie.models.files import FileType
            query = FileType.query().options(load_only('id', 'label')).filter(
                FileType.id.in_(ids)
            )
            result = query.all()
        return result