class Consist(Model): email = Field() url = Field() ip = Field() image = Field.upload() emails = Field.string_list() emailsplit = Field.string_list() validation = { 'email': { 'is': 'email' }, 'url': { 'is': 'url' }, 'ip': { 'is': 'ip' }, 'image': { 'is': 'image' }, 'emails': { 'is': 'list:email' }, 'emailsplit': { 'is': { 'list:email': { 'splitter': ',;' } } } }
class Post(Signature): tablename = "posts" caption = Field.string(length=250) location = Field.string(length=250) photo = Field.upload() date = Field.datetime() default_values = {} validation = { 'caption': { 'presence': True }, 'location': { 'presence': True } } @after_insert def send_notification(self, fields, rid): # user_id = recover from created post user_id = 5 subscriptions = Subscription.by_user(user_id).select() message = { "title": "Post created", "body": "Este es el cuerpo de la notificación", "openUrl": "/#/" } for subscription in subscriptions: try: webpush(subscription_info=json.loads( json.dumps(subscription.subscription)), data=json.dumps(message), vapid_private_key=VAPID_PRIVATE_KEY, vapid_claims=VAPID_CLAIMS) except WebPushException as ex: if '410 Gone' in str(ex): subscription.delete_record()
class User(AuthUser): tablename = 'auth_users' avatar = Field.upload(autodelete=True) email = Field.string(length=255) has_many( {'suscripciones': 'Suscripcion.user'}, {'posts': 'Post.user'}, ) default_vales = {} validation = { 'email': { 'is': 'email' }, } form_labels = { 'email': 'Correo Electrónico', 'password': '******', 'first_name': 'Nombre', 'last_name': 'Apellido', } fields_rw = {} rest_rw = { # 'id': True, } @rowattr('nombre_completo') def _nombre_completo(self, row): return '%s %s' % (row.last_name.capitalize() or '', row.first_name.capitalize() or '')