コード例 #1
0
class StatisticSheet(DBBASE):  # , PersistentACLMixin):
    __table_args__ = default_table_args
    id = Column(Integer, primary_key=True)
    created_at = Column(
        DateTime(),
        info={'colanderalchemy': forms.EXCLUDED},
        default=datetime.now,
    )
    updated_at = Column(
        DateTime(),
        info={'colanderalchemy': forms.EXCLUDED},
        default=datetime.now,
        onupdate=datetime.now,
    )
    title = Column(String(255))
    active = Column(Boolean(), default=True)
    _acl = Column(MutableList.as_mutable(ACLType), )

    def __json__(self, request):
        return dict(
            id=self.id,
            title=self.title,
            active=self.active,
        )

    def duplicate(self):
        new_sheet = StatisticSheet(title=u"{0} {1}".format(
            self.title, ''.join(
                random.choice(string.ascii_uppercase + string.digits)
                for _ in range(5))))
        for entry in self.entries:
            new_sheet.entries.append(entry.duplicate())
        return new_sheet
コード例 #2
0
class Job(DBBASE, PersistentACLMixin):
    """
    Base job model, used to communicate a job's status between the main pyramid
    app and celery asynchronous tasks
    """
    __tablename__ = 'job'
    __table_args__ = default_table_args
    __mapper_args__ = {
        'polymorphic_on': 'type_',
        'polymorphic_identity': 'job'
    }
    label = u"Tâche générique"
    id = Column(
        Integer,
        primary_key=True,
    )
    jobid = Column(
        String(255),
        nullable=True,
    )
    status = Column(
        String(20),
        default='planned',
    )
    created_at = Column(
        DateTime(),
        default=datetime.now,
    )
    updated_at = Column(DateTime(),
                        default=datetime.now,
                        onupdate=datetime.now)
    type_ = Column(
        'type_',
        String(30),
        nullable=False,
    )
    _acl = Column(MutableList.as_mutable(ACLType), )

    def todict(self):
        return dict(
            label=self.label,
            jobid=self.jobid,
            status=self.status,
            created_at=self.created_at.strftime("%d/%m/%Y à %H:%M"),
            updated_at=self.updated_at.strftime("%d/%m/%Y à %H:%M"),
        )

    def __json__(self, request):
        return self.todict()

    def set_owner(self, login):
        """
        Set the job owner's acls
        """
        self._acl = [(Allow, login, (
            'add',
            'edit',
            'view',
        ))]
コード例 #3
0
class StatisticEntry(DBBASE):  # , PersistentACLMixin):
    __table_args__ = default_table_args
    id = Column(Integer, primary_key=True)
    title = Column(String(255))
    description = Column(Text())
    _acl = Column(MutableList.as_mutable(ACLType), )
    sheet_id = Column(ForeignKey('statistic_sheet.id', ondelete='cascade'))
    sheet = relationship(
        "StatisticSheet",
        backref=backref("entries"),
    )

    def __json__(self, request):
        return dict(
            id=self.id,
            title=self.title,
            description=self.description,
        )

    def duplicate(self):
        entry = StatisticEntry(title=self.title, description=self.description)
        for criterion in self.criteria:
            entry.criteria.append(criterion.duplicate())
        return entry
コード例 #4
0
class Node(DBBASE, PersistentACLMixin):
    """
    A base node providing a parent<->children structure for most of the models
    (usefull for file attachment)
    """
    __tablename__ = 'node'
    __table_args__ = default_table_args
    __mapper_args__ = {
        'polymorphic_on': 'type_',
        'polymorphic_identity': 'nodes',
    }
    id = Column(
        Integer,
        primary_key=True,
    )
    name = Column(
        String(255),
        info={
            'colanderalchemy': {
                'title': u"Nom"
            },
        },
        nullable=True,
    )

    created_at = Column(
        DateTime(),
        info={'colanderalchemy': {
            'exclude': True,
            'title': u"Créé(e) le",
        }},
        default=datetime.now(),
    )

    updated_at = Column(DateTime(),
                        info={
                            'colanderalchemy': {
                                'exclude': True,
                                'title': u"Mis(e) à jour le",
                            }
                        },
                        default=datetime.now(),
                        onupdate=datetime.now())

    parent_id = Column(
        ForeignKey('node.id'),
        info={'colanderalchemy': forms.EXCLUDED},
    )

    children = relationship(
        'Node',
        primaryjoin='Node.id==Node.parent_id',
        backref=backref(
            'parent',
            remote_side=[id],
            info={
                'colanderalchemy': forms.EXCLUDED,
            },
        ),
        cascade='all',
        info={'colanderalchemy': forms.EXCLUDED},
    )

    type_ = Column(
        'type_',
        String(30),
        info={'colanderalchemy': forms.EXCLUDED},
        nullable=False,
    )
    _acl = Column(
        MutableList.as_mutable(ACLType),
        info={
            'colanderalchemy': forms.EXCLUDED,
            'export': {
                'exclude': True
            }
        },
    )