<commit_before># -*- coding: utf-8 -*-
"""
    flaskbb.user.models
    ~~~~~~~~~~~~~~~~~~~~

    This module provides the models for the user.

    :copyright: (c) 2013 by the FlaskBB Team.
    :license: BSD, see LICENSE for more details.
"""
from datetime import datetime

from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from itsdangerous import SignatureExpired
from werkzeug import generate_password_hash, check_password_hash
from flask import current_app
from flask.ext.login import UserMixin, AnonymousUserMixin
from flaskbb.extensions import db, cache
from flaskbb.forum.models import Post, Topic
from flaskbb.pms.models import PrivateMessage


groups_users = db.Table('groups_users',
        db.Column('user_id', db.Integer(), db.ForeignKey('users.id')),
        db.Column('group_id', db.Integer(), db.ForeignKey('groups.id')))


class Group(db.Model):
    __tablename__ = "groups"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True)
    description = db.Column(db.String(80))

    admin = db.Column(db.Boolean)
    super_mod = db.Column(db.Boolean)
    mod = db.Column(db.Boolean)
    guest = db.Column(db.Boolean)
    banned = db.Column(db.Boolean)

    editpost = db.Column(db.Boolean)
    deletepost = db.Column(db.Boolean)
    deletetopic = db.Column(db.Boolean)
    posttopic = db.Column(db.Boolean)
    postreply = db.Column(db.Boolean)


class User(db.Model, UserMixin):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, unique=True)
    email = db.Column(db.String, unique=True)
    _password = db.Column('password', db.String(80), nullable=False)
    date_joined = db.Column(db.DateTime, default=datetime.utcnow())
    post_count = db.Column(db.Integer, default=0)
    lastseen = db.Column(db.DateTime, default=datetime.utcnow())
    birthday = db.Column(db.DateTime)
    gender = db.Column(db.String)
    website = db.Column(db.String)
    location = db.Column(db.String)
    signature = db.Column(db.String)
    avatar = db.Column(db.String)
    notes = db.Column(db.Text(5000), default="User has not added any notes about him.")

    posts = db.relationship("Post", backref="user", lazy="dynamic")
    topics = db.relationship("Topic", backref="user", lazy="dynamic")

    post_count = db.Column(db.Integer, default=0) # Bye bye normalization

    primary_group_id = db.Column(db.Integer, db.ForeignKey('groups.id'))

    primary_group = db.relationship('Group', lazy="joined", backref="user_group", uselist=False, foreign_keys=[primary_group_id])

    #pms = db.relationship("PrivateMessage", lazy="dynamic", primaryjoin=(PrivateMessage.user_id == id))

    groups = db.relationship('Group',
                             secondary=groups_users,
                             primaryjoin=(groups_users.c.user_id == id),
                             backref=db.backref('users', lazy='dynamic'),
                             lazy='dynamic')

    unread_count = db.column_property(
        db.select([db.func.count(PrivateMessage.id)]).where(PrivateMessage.user_id == id).where(PrivateMessage.unread == True).as_scalar())

    def __repr__(self):
        return "Username: %s" % self.username

    def _get_password(self):
        return self._password

    def _set_password(self, password):
        self._password = generate_password_hash(password)

    # Hide password encryption by exposing password field only.<commit_msg>Fixed correlate bug<commit_after># -*- coding: utf-8 -*-
"""
    flaskbb.user.models
    ~~~~~~~~~~~~~~~~~~~~

    This module provides the models for the user.

    :copyright: (c) 2013 by the FlaskBB Team.
    :license: BSD, see LICENSE for more details.
"""
from datetime import datetime

from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from itsdangerous import SignatureExpired
from werkzeug import generate_password_hash, check_password_hash
from flask import current_app
from flask.ext.login import UserMixin, AnonymousUserMixin
from flaskbb.extensions import db, cache
from flaskbb.forum.models import Post, Topic
from flaskbb.pms.models import PrivateMessage


groups_users = db.Table('groups_users',
        db.Column('user_id', db.Integer(), db.ForeignKey('users.id')),
        db.Column('group_id', db.Integer(), db.ForeignKey('groups.id')))


class Group(db.Model):
    __tablename__ = "groups"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True)
    description = db.Column(db.String(80))

    admin = db.Column(db.Boolean)
    super_mod = db.Column(db.Boolean)
    mod = db.Column(db.Boolean)
    guest = db.Column(db.Boolean)
    banned = db.Column(db.Boolean)

    editpost = db.Column(db.Boolean)
    deletepost = db.Column(db.Boolean)
    deletetopic = db.Column(db.Boolean)
    posttopic = db.Column(db.Boolean)
    postreply = db.Column(db.Boolean)


class User(db.Model, UserMixin):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, unique=True)
    email = db.Column(db.String, unique=True)
    _password = db.Column('password', db.String(80), nullable=False)
    date_joined = db.Column(db.DateTime, default=datetime.utcnow())
    post_count = db.Column(db.Integer, default=0)
    lastseen = db.Column(db.DateTime, default=datetime.utcnow())
    birthday = db.Column(db.DateTime)
    gender = db.Column(db.String)
    website = db.Column(db.String)
    location = db.Column(db.String)
    signature = db.Column(db.String)
    avatar = db.Column(db.String)
    notes = db.Column(db.Text(5000), default="User has not added any notes about him.")

    posts = db.relationship("Post", backref="user", lazy="dynamic")
    topics = db.relationship("Topic", backref="user", lazy="dynamic")

    post_count = db.Column(db.Integer, default=0) # Bye bye normalization

    primary_group_id = db.Column(db.Integer, db.ForeignKey('groups.id'))

    primary_group = db.relationship('Group', lazy="joined", backref="user_group", uselist=False, foreign_keys=[primary_group_id])

    #pms = db.relationship("PrivateMessage", lazy="dynamic", primaryjoin=(PrivateMessage.user_id == id))

    groups = db.relationship('Group',
                             secondary=groups_users,
                             primaryjoin=(groups_users.c.user_id == id),
                             backref=db.backref('users', lazy='dynamic'),
                             lazy='dynamic')

    unread_count = db.column_property(
        db.select([db.func.count(PrivateMessage.id)]).\
            where(PrivateMessage.user_id == id).\
            where(PrivateMessage.unread == True).correlate("privatemessages").\
            as_scalar())

    def __repr__(self):
        return "Username: %s" % self.username

    def _get_password(self):
        return self._password

    def _set_password(self, password):
        self._password = generate_password_hash(password)

    # Hide password encryption by exposing password field only.
{'fraction_non_alphanumeric': 0.13156770610850063, 'fraction_numerical': 0.004271678769756515, 'mean_word_length': 3.5025641025641026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5272188', 'n_tokens_mistral': 2198, 'n_tokens_neox': 2109, 'n_words': 446}