class Reference(db.Model): __tablename__ = 'rule_references' id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String(140)) rule_id = db.Column(db.Integer, db.ForeignKey('rules.id'))
class PasswdReset(db.Model): id = db.Column(db.Integer, primary_key=True) hashstr = db.Column(db.String(40)) created = db.Column(db.DateTime(), default=datetime.utcnow) active = db.Column(db.Boolean()) user_id = db.Column(db.Integer, db.ForeignKey(User.id)) user = db.relationship(User, uselist=False) @property def email_body(self): from hnp import hnp return render_template('auth/reset-email.html', hashstr=self.hashstr, server_url=hnp.config['SERVER_BASE_URL'], email=self.user.email)
class ApiKey(db.Model): all_fields = { 'api_key': { 'required': True, 'editable': False }, 'user_id': { 'required': True, 'editable': False } } id = db.Column(db.Integer, primary_key=True) api_key = db.Column(db.String(32), unique=True) user_id = db.Column('user_id', db.Integer, db.ForeignKey("user.id"), nullable=False)
class DeployScript(db.Model, APIModel): all_fields = { 'script': { 'required': True, 'editable': True }, 'name': { 'required': True, 'editable': True }, 'date': { 'required': False, 'editable': False }, 'notes': { 'required': True, 'editable': True }, } __tablename__ = 'deploy_scripts' id = db.Column(db.Integer, primary_key=True) script = db.Column(db.String(102400)) date = db.Column(db.DateTime(), default=datetime.utcnow) notes = db.Column(db.String(140)) name = db.Column(db.String(140)) user_id = db.Column(db.Integer, db.ForeignKey(User.id)) user = db.relationship(User, uselist=False) def __init__(self, name=None, script=None, notes=None): self.name = name self.script = script self.notes = notes def __repr__(self): return '<DeployScript>{}'.format(self.to_dict()) def to_dict(self): return dict(script=self.script, date=self.date, notes=self.notes, user=self.user.email, id=self.id)
from datetime import datetime from flask_security import UserMixin, RoleMixin from flask import render_template from hnp import db from hnp.api import APIModel roles_users = db.Table( 'roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) class User(db.Model, APIModel, UserMixin): all_fields = { 'email': { 'required': True, 'editable': False }, 'password': { 'required': True, 'editable': True }, 'active': {