-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
80 lines (64 loc) · 2.4 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from settings import *
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime, timedelta
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
"""
User - user model that supports public key authentication
"""
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(64))
public_key = db.Column(db.String(64))
challenge = db.Column(db.String(32), unique=True)
created = db.Column(db.DateTime, default=db.func.current_timestamp())
verified = db.Column(db.DateTime)
deleted = db.Column(db.DateTime)
modified = db.Column(db.DateTime, default=db.func.current_timestamp())
def __init__(self, username, public_key, challenge=None, bad_attempts=0):
self.username = username
self.public_key = public_key
self.challenge = challenge
self.bad_attempts = bad_attempts
def __repr__(self):
return '<User %r>' % self.public_key
"""
Trust - models a trust relationship from user1 (source) to user2 (target) with value on an integer scale
"""
class Trust(db.Model):
__tablename__ = 'trusts'
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer)
user_id2 = db.Column(db.Integer)
value = db.Column(db.Integer)
created = db.Column(db.DateTime, default=db.func.current_timestamp())
deleted = db.Column(db.DateTime)
modified = db.Column(db.DateTime, default=db.func.current_timestamp())
def __init__(self, user_id, uri, value):
self.user_id = user_id
self.uri = uri
self.value = value
def __repr__(self):
return "<Trust %r>" % self.id
"""
Rating - for rating a piece of content on an integer scale
"""
class Rating(db.Model):
__tablename__ = 'ratings'
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer)
uri = db.Column(db.String(1024))
value = db.Column(db.Integer)
created = db.Column(db.DateTime, default=db.func.current_timestamp())
deleted = db.Column(db.DateTime)
modified = db.Column(db.DateTime, default=db.func.current_timestamp())
def __init__(self, user_id, uri, value):
self.user_id = user_id
self.uri = uri
self.value = value
def __repr__(self):
return "<Rating %r>" % self.id