Exemple #1
0
class User(db.Model, UserMixin, UidMixin, PropsMixin):
    kind = K_USER
    kins_name = 'user'
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(255), unique=True)
    password = db.Column(db.String(255))
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role', secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))

    last_login_at = PropsItem('ll')
    current_login_at = PropsItem('cl')
    last_login_ip = PropsItem('llip')
    current_login_ip = PropsItem('clip')
    login_count = PropsItem('lc')
    name = PropsItem('name')
    locale = PropsItem('locale', BABEL_DEFAULT_LOCALE)
    timezone = PropsItem('timezone', BABEL_DEFAULT_TIMEZONE)

    @property
    def display_name(self):
        return self.name or (self.uid if self.uid else self.email.split('@')[0])

Account = User

user_datastore = SQLAlchemyUserDatastore(db, User, Role)

add_kind(K_USER, User)
Exemple #2
0
    title = db.Column(db.String(255), nullable=False)
    link = db.Column(db.String(255), nullable=False)
    create_at = db.Column(db.DateTime, default=datetime.now, nullable=False)
    content = db.Column(db.Text())

    _DEFAULT_PIC = lazy_static_url('img/article-default-%s.png')

    def url(self):
        return self.link

    def abstract(self, limit=140):
        return truncate(striptags(self.content or '').strip(), limit, killwords=True)

    @property
    def thumb_url(self):
        return self.picture_url('sqr120')

    def serialize(self):
        pics = [dict(title=x.title, desc=x.desc, large_url=x.url('large'),
                     thumb_url=x.thumb_url)
                for x in self.attachment_pics()]
        return dict(id=self.id, title=self.title,
                url=self.url(),
                abstract=self.abstract(),
                thumb_url = self.thumb_url,
                median_url = self.picture_url('median'),
                pics=pics)


add_kind(K_EVENT, Event)
Exemple #3
0
class Work(BaseWork):

    cat_choices = [(str(cat_id), _(cls.__name__)) for cat_id, cls in cat2type.items()]

    cat_id = None

    @classmethod
    def get(cls, ident):
        item = BaseWork.get(ident)
        if item:
            return cat2type[item.cat](item)

    @property
    def extended_self(self):
        return cat2type[self.cat](self)

class Music(BaseWork):
    cat_id = C_MUSIC

class Movie(BaseWork):
    cat_id = C_MOVIE

class TV(BaseWork):
    cat_id = C_TV


# Export Work kind
add_kind(K_WORK, Work)

Exemple #4
0

@lazyget
def all_artists():
    return [(str(a.id), a.name) for a in Artist.query.all()]

class Artist(db.Model, UidMixin, PictureMixin):
    kind = K_ARTIST
    kind_name = 'artist'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
    summary = db.Column(db.Text())
    desc = db.Column(db.Text())

    _DEFAULT_PIC = lazy_static_url('img/artist-default-%s.png')

    def __str__(self):
        return self.name

    def __eq__(self, other):
        return self.id == other.id

    def url(self):
        return SITE_ROOT + 'artist/' + self.slug

    def abstract(self, limit=140):
        return truncate((self.summary or '').strip() or striptags(self.desc or '').strip(), limit)


add_kind(K_ARTIST, Artist)
Exemple #5
0
# coding: utf-8
from .article import K_ARTICLE, Article
from .tag import K_TAG, Tag
from .article import add_cat, CATS

from david.core.mapper import add_kind

add_kind(K_ARTICLE, Article)
add_kind(K_TAG, Tag)
Exemple #6
0
# -*- coding: utf-8 -*-
from flask import url_for

from david.core.db import db, UidMixin
from david.lib.mixins.props import PropsMixin, PropsItem

from david.core.mapper import add_kind


K_PAGE = 300


class Page(db.Model, UidMixin, PropsMixin):
    kind = K_PAGE
    kind_name = 'page'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255), nullable=False)
    content = db.Column(db.Text())

    def url(self):
        return url_for('pages.show', page=self.slug)


add_kind(K_PAGE, Page)