<commit_before>#flask-admin views
from flask.ext.login import current_user
from flask.ext.admin.contrib.sqla import ModelView
from flask.ext.admin.base import AdminIndexView

from ..extensions import db

from ..radio.models import *
from ..onair.models import *
from ..telephony.models import *

class AdminView(ModelView):
    def is_accessible(self):
        if current_user.is_authenticated():
            return current_user.role_code == 0
        else:
            return False

class AdminHomeView(AdminIndexView):
    def is_accessible(self):
        return current_user.is_authenticated()

def admin_routes(admin):
    admin.add_view(AdminView(Person, db.session, category='RootIO'))
    admin.add_view(AdminView(Language, db.session, category='RootIO'))
    admin.add_view(AdminView(Network, db.session, category='RootIO'))
    admin.add_view(AdminView(Location, db.session, category='RootIO'))
    admin.add_view(AdminView(ProgramType, db.session, category='RootIO', name="ProgramType"))

    admin.add_view(AdminView(PhoneNumber, db.session, category='Telephony', name="PhoneNumber"))<commit_msg>flask-admin timestamp formatting<commit_after>#flask-admin views
from flask.ext.login import current_user
from flask.ext.admin.contrib.sqla import ModelView
from flask.ext.admin.base import AdminIndexView

from ..extensions import db

from ..radio.models import *
from ..onair.models import *
from ..telephony.models import *

def datetime_formatter(view, context, model, name):
    return getattr(model, name).strftime("%Y-%m-%d %H:%M:%S")

class AdminView(ModelView):
    column_formatters = {'created_at': datetime_formatter, 'updated_at': datetime_formatter}
    form_widget_args = {'created_at': {'readonly':True}, 'updated_at': {'readonly':True}}

    def is_accessible(self):
        if current_user.is_authenticated():
            return current_user.role_code == 0
        else:
            return False

class AdminHomeView(AdminIndexView):
    def is_accessible(self):
        return current_user.is_authenticated()

def admin_routes(admin):
    admin.add_view(AdminView(Person, db.session, category='RootIO'))
    admin.add_view(AdminView(Language, db.session, category='RootIO'))
    admin.add_view(AdminView(Network, db.session, category='RootIO'))
    admin.add_view(AdminView(Location, db.session, category='RootIO'))
    admin.add_view(AdminView(ProgramType, db.session, category='RootIO', name="ProgramType"))

    admin.add_view(AdminView(PhoneNumber, db.session, category='Telephony', name="PhoneNumber"))
{'fraction_non_alphanumeric': 0.12282780410742496, 'fraction_numerical': 0.0007898894154818325, 'mean_word_length': 4.946009389671362, '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': '6573779', 'n_tokens_mistral': 769, 'n_tokens_neox': 744, 'n_words': 154}