<commit_before>import uuid
import hashlib
from datetime import datetime, date, timedelta
from flask.ext.sqlalchemy import SQLAlchemy
from tsundiary import app
from tsundiary.utils import uidify

db = SQLAlchemy(app)

##############
# ORM objects

class User(db.Model):
    """ A tsundiary user and all their settings. """
    __tablename__ = 'user'
    sid = db.Column(db.String, primary_key=True, index=True, unique=True)
    name = db.Column(db.String, index=True, unique=True)
    passhash = db.Column(db.String)
    email = db.Column(db.String, unique=True)
    invite_key = db.Column(db.String)
    join_time = db.Column(db.DateTime, index=True)
    num_entries = db.Column(db.Integer, index=True)
    combo = db.Column(db.Integer, index=True)
    timezone = db.Column(db.Integer)
    secret_days = db.Column(db.Integer)
    publicity = db.Column(db.Integer)
    theme = db.Column(db.String)
    color = db.Column(db.String)
    stalks = db.Column(db.String)
    latest_post_date = db.Column(db.Date, index=True)

    def verify_password(self, password):
        """ Checks whether a user's password is equal to the given string."""
        salt = self.passhash[:32].encode('utf-8')
        pas = hashlib.sha512(salt + password.encode('utf-8'))
        pash = pas.hexdigest().encode('utf-8')
        return salt + pash == self.passhash

    def set_password(self, password):
        salt = uuid.uuid4().hex.encode('utf-8')
        pas = hashlib.sha512(salt + password.encode('utf-8'))
        pash = pas.hexdigest().encode('utf-8')
        self.passhash = salt + pash

    def __init__(self, name, password, email=None, invite_key=""):
        self.sid = uidify(name)
        self.name = name
        self.set_password(password)
        self.email = email
        self.invite_key = invite_key
        self.join_time = datetime.now()
        self.num_entries = 0
        self.combo = 0
        self.timezone = 0 # UTC
        self.secret_days = 0
        # publicity
        # 0: completely hidden1: anyone with the link  2. link in user list
        self.publicity = 2
        self.theme = 'default'
        self.color = '0,100,100'
        self.stalks = ''
        self.latest_post_date = date(1900,1,1)

    def __repr__(self):
        return '<User %r>' % self.name

class Post(db.Model):
    """ A user's post. """
    __tablename__ = 'post'
    user_sid = db.Column(db.String,
                         db.ForeignKey('user.sid'),
                         primary_key=True,
                         index=True)
    posted_date = db.Column(db.Date, primary_key=True, index=True)
    update_time = db.Column(db.DateTime)
    content = db.Column(db.String)
    user = db.relationship('User',
                           backref=db.backref('posts', lazy='dynamic'))

    def __init__(self, user_sid, content, posted_date):
        self.user_sid = user_sid
        self.posted_date = posted_date
        self.content = content

    def __repr__(self):
        return '<Post by %r on %r>' % (self.user_sid, self.posted_date)<commit_msg>set default theme to classic<commit_after>import uuid
import hashlib
from datetime import datetime, date, timedelta
from flask.ext.sqlalchemy import SQLAlchemy
from tsundiary import app
from tsundiary.utils import uidify

db = SQLAlchemy(app)

##############
# ORM objects

class User(db.Model):
    """ A tsundiary user and all their settings. """
    __tablename__ = 'user'
    sid = db.Column(db.String, primary_key=True, index=True, unique=True)
    name = db.Column(db.String, index=True, unique=True)
    passhash = db.Column(db.String)
    email = db.Column(db.String, unique=True)
    invite_key = db.Column(db.String)
    join_time = db.Column(db.DateTime, index=True)
    num_entries = db.Column(db.Integer, index=True)
    combo = db.Column(db.Integer, index=True)
    timezone = db.Column(db.Integer)
    secret_days = db.Column(db.Integer)
    publicity = db.Column(db.Integer)
    theme = db.Column(db.String)
    color = db.Column(db.String)
    stalks = db.Column(db.String)
    latest_post_date = db.Column(db.Date, index=True)

    def verify_password(self, password):
        """ Checks whether a user's password is equal to the given string."""
        salt = self.passhash[:32].encode('utf-8')
        pas = hashlib.sha512(salt + password.encode('utf-8'))
        pash = pas.hexdigest().encode('utf-8')
        return salt + pash == self.passhash

    def set_password(self, password):
        salt = uuid.uuid4().hex.encode('utf-8')
        pas = hashlib.sha512(salt + password.encode('utf-8'))
        pash = pas.hexdigest().encode('utf-8')
        self.passhash = salt + pash

    def __init__(self, name, password, email=None, invite_key=""):
        self.sid = uidify(name)
        self.name = name
        self.set_password(password)
        self.email = email
        self.invite_key = invite_key
        self.join_time = datetime.now()
        self.num_entries = 0
        self.combo = 0
        self.timezone = 0 # UTC
        self.secret_days = 0
        # publicity
        # 0: completely hidden1: anyone with the link  2. link in user list
        self.publicity = 2
        self.theme = 'classic'
        self.color = '0,100,100'
        self.stalks = ''
        self.latest_post_date = date(1900,1,1)

    def __repr__(self):
        return '<User %r>' % self.name

class Post(db.Model):
    """ A user's post. """
    __tablename__ = 'post'
    user_sid = db.Column(db.String,
                         db.ForeignKey('user.sid'),
                         primary_key=True,
                         index=True)
    posted_date = db.Column(db.Date, primary_key=True, index=True)
    update_time = db.Column(db.DateTime)
    content = db.Column(db.String)
    user = db.relationship('User',
                           backref=db.backref('posts', lazy='dynamic'))

    def __init__(self, user_sid, content, posted_date):
        self.user_sid = user_sid
        self.posted_date = posted_date
        self.content = content

    def __repr__(self):
        return '<Post by %r on %r>' % (self.user_sid, self.posted_date)
{'fraction_non_alphanumeric': 0.12842831335194613, 'fraction_numerical': 0.011824601740844145, 'mean_word_length': 2.559322033898305, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3906659', 'n_tokens_mistral': 2016, 'n_tokens_neox': 1930, 'n_words': 431}