Exemplo n.º 1
0
class Note(db.Model, ModelMixin):
    __tablename__ = 'notes'
    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey('users.id'))
    body = Column(Text)
    parser = Column(String)
    deleted_at = Column(Date)
    created_at = Column(DateTime)
    last_modified_at = Column(DateTime)
    last_accessed_at = Column(DateTime)

    annotations = db.relationship('Annotation', lazy='dynamic')
    tags = db.relationship('Tag', secondary=lambda: notes_tags)

    tag_names = association_proxy(
        'tags',
        'name',
        creator=lambda name: db.session.query(Tag).filter_by(
            user_id=current_user.id, name=name).first())

    def to_dict(self):
        annotations = self.annotations.all()
        doc_id = None
        ann_id = None
        if len(annotations) > 0 and annotations[0].deleted_at is None:
            ann_id = annotations[0].id
            doc = annotations[0].document
            if doc.deleted_at is None:
                doc_id = doc.id
        return {
            'id':
            self.id,
            'user_id':
            self.user_id,
            'body':
            self.body,
            'parser':
            self.parser,
            'deleted_at':
            date_to_str(self.deleted_at),
            'last_modified_at':
            datetime_to_str(self.last_modified_at),
            'last_accessed_at':
            datetime_to_str(self.last_accessed_at),
            'tag_names':
            list(self.tag_names),
            'document_id':
            doc_id,
            'annotation_id':
            ann_id,
            'orphaned':
            len(annotations) > 0 and annotations[0].deleted_at is not None
        }
Exemplo n.º 2
0
class User(db.Model, UserMixin, ModelMixin):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    email = Column(String)
    password = Column(LargeBinary)
    verified_email = Column(Boolean)
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())

    fs_uniquifier = Column(String(255), unique=True, nullable=False)
    github_id = Column(Integer, unique=True, nullable=True)

    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))
    documents = db.relationship('Document', lazy='dynamic')
Exemplo n.º 3
0
class Document(db.Model, ModelMixin):
    __tablename__ = 'documents'
    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey('users.id'))
    note_id = Column(Integer, ForeignKey('notes.id', name='fkey_note_id'))
    url = Column(String)
    hash = Column(String)
    title = Column(String)
    author = Column(String)
    bibtex = Column(String)
    read = Column(Boolean)
    deleted_at = Column(Date)
    created_at = Column(DateTime)
    last_modified_at = Column(DateTime)
    last_accessed_at = Column(DateTime)

    note = db.relationship('Note')
    annotations = db.relationship('Annotation', lazy='dynamic')
    tags = db.relationship('Tag', secondary=lambda: documents_tags)

    tag_names = association_proxy(
        'tags',
        'name',
        creator=lambda name: db.session.query(Tag).filter_by(
            user_id=current_user.id, name=name).first())
    tag_ids = association_proxy(
        'tags',
        'id',
        creator=lambda tag_id: db.session.query(Tag).filter_by(
            user_id=current_user.id, id=tag_id).first())

    def to_dict(self):
        return {
            'id': self.id,
            'user_id': self.user_id,
            'url': self.url,
            'title': self.title,
            'author': self.author,
            'bibtex': self.bibtex,
            'read': self.read,
            'note_id': self.note_id,
            'deleted_at': date_to_str(self.deleted_at),
            'last_modified_at': datetime_to_str(self.last_modified_at),
            'last_accessed_at': datetime_to_str(self.last_accessed_at),
            'tag_names': list(self.tag_names),
            'tag_ids': list(self.tag_ids),
        }
Exemplo n.º 4
0
class Annotation(db.Model, ModelMixin):
    __tablename__ = 'annotations'
    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey('users.id'))
    doc_id = Column(Integer, ForeignKey('documents.id'))
    note_id = Column(Integer, ForeignKey('notes.id', name='fkey_note_id'))
    page = Column(String)
    type = Column(String)
    position = Column(
        String
    )  # Coordinate for points, bounding box for rect. Format: json string.
    deleted_at = Column(Date)
    #important = Column(Boolean) # If True, then this annotation marks something important
    #do_not_understand = Column(Boolean) # If True, then this annotation marks something the reader does not understand.

    document = db.relationship("Document")
    note = db.relationship('Note')

    def update(self, data):
        super().update(data)
        if 'position' in data:
            self.position = json.dumps(data['position'])

    def to_dict(self):
        return {
            'id':
            self.id,
            'user_id':
            self.user_id,
            'note_id':
            self.note_id,
            'doc_id':
            self.doc_id,
            'page':
            self.page,
            'type':
            self.type,
            'position':
            json.loads(self.position),
            'deleted_at':
            self.deleted_at.strftime('%Y-%m-%d')
            if self.deleted_at is not None else None
        }
Exemplo n.º 5
0
class EmailConfirmationCode(db.Model, ModelMixin):
    __tablename__ = 'email_confirmation_codes'
    user_id = Column(Integer, ForeignKey('users.id'))
    code = Column(String(), primary_key=True)
    created_at = db.Column(db.DateTime(), server_default=func.now())
    user = db.relationship('User')