<commit_before># -*- coding: utf-8 -*-
# http://google-styleguide.googlecode.com/svn/trunk/pyguide.html

import os
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.dialects import mysql
from smsgw.models import BaseModel, DateMixin
from smsgw.extensions import db
from smsgw.lib.utils import generate_uuid


class Application(BaseModel, DateMixin):
    """ Application model """

    id = db.Column(mysql.INTEGER(10, unsigned=True), primary_key=True)
    userId = db.Column(mysql.INTEGER(10, unsigned=True), ForeignKey('user.id'))
    uuid = db.Column(mysql.CHAR(36), unique=True, nullable=False,
                     default=generate_uuid)
    label = db.Column(db.String(32), nullable=False)
    token = db.Column(db.String(32), unique=True, nullable=False)
    prefix = db.Column(db.String(5), unique=True)
    callbackUrl = db.Column(db.String(128))
    note = db.Column(db.String(255))

    outbox = relationship("Outbox", backref='application', lazy='dynamic')
    sent_items = relationship("SentItem", backref='application', lazy='dynamic')


    def __init__(self, **kwargs):
        """
        Create token on inicialization
        """
        super(Application, self).__init__(**kwargs)
        # generate token
        self.regenerate_token()


    def regenerate_token(self):
        """
        Regenerate token for API access
        """
        self.token = os.urandom(16).encode('hex')


    def to_dict(self, properties=None):
        """<commit_msg>ApplicationModel: added relation to inbox<commit_after># -*- coding: utf-8 -*-
# http://google-styleguide.googlecode.com/svn/trunk/pyguide.html

import os
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.dialects import mysql
from smsgw.models import BaseModel, DateMixin
from smsgw.extensions import db
from smsgw.lib.utils import generate_uuid


class Application(BaseModel, DateMixin):
    """ Application model """

    id = db.Column(mysql.INTEGER(10, unsigned=True), primary_key=True)
    userId = db.Column(mysql.INTEGER(10, unsigned=True), ForeignKey('user.id'))
    uuid = db.Column(mysql.CHAR(36), unique=True, nullable=False,
                     default=generate_uuid)
    label = db.Column(db.String(32), nullable=False)
    token = db.Column(db.String(32), unique=True, nullable=False)
    prefix = db.Column(db.String(5), unique=True)
    callbackUrl = db.Column(db.String(128))
    note = db.Column(db.String(255))

    outbox = relationship("Outbox", backref='application', lazy='dynamic')
    inbox = relationship("Inbox", backref='application', lazy='dynamic')
    sent_items = relationship("SentItem", backref='application', lazy='dynamic')


    def __init__(self, **kwargs):
        """
        Create token on inicialization
        """
        super(Application, self).__init__(**kwargs)
        # generate token
        self.regenerate_token()


    def regenerate_token(self):
        """
        Regenerate token for API access
        """
        self.token = os.urandom(16).encode('hex')


    def to_dict(self, properties=None):
        """
{'fraction_non_alphanumeric': 0.13200897148349888, 'fraction_numerical': 0.01281640499839795, 'mean_word_length': 3.5777126099706744, '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': '3487606', 'n_tokens_mistral': 975, 'n_tokens_neox': 925, 'n_words': 198}