<commit_before># -*- coding: UTF-8 -*-
from flask.ext.babel import gettext as _
from flask.ext.databrowser import ModelView, sa, filters
from flask.ext.databrowser.col_spec import ColSpec, InputColSpec
from flask.ext.databrowser.action import (DeleteAction, ACTION_OK,
                                          ACTION_IMPERMISSIBLE)
from flask.ext.principal import Permission, RoleNeed
from flask.ext.login import current_user
from genuine_ap.database import db
from genuine_ap.models import SKU, Vendor
from genuine_ap import const
from genuine_ap.apis import unwraps
from genuine_ap.spu import spu_model_view


class SKUModelView(ModelView):

    def try_edit(self, objs=None):
        if not Permission(self.edit_all_need).can():
            for obj in objs:
                Permission(spu_model_view.edit_need(obj.spu.id)).test()

    @property
    def can_batchly_edit(self):
        return Permission(RoleNeed(const.SUPER_ADMIN)).can()

    @property
    def sortable_columns(self):
        return ['id', 'manufacture_time', 'expire_time', 'create_time']

    @property
    def default_filters(self):
        if Permission(RoleNeed(const.VENDOR_GROUP)).can():
            return [filters.EqualTo('spu.vendor', self,
                                    value=unwraps(current_user.vendor))]
        return []

    @property
    def list_columns(self):
        return [ColSpec('id', _('id')),
                ColSpec('spu', _('spu')),
                ColSpec('spu.vendor', _('vendor')),
                ColSpec('manufacture_date', _('manufacture date')),
                ColSpec('expire_date', _('expire date')),
                ColSpec('token', _('token')),
                ColSpec('create_time', _('create time'))]

    @property
    def create_columns(self):
        def filter_(q):
            if Permission(RoleNeed(const.VENDOR_GROUP)).can():
                return q.filter(Vendor.id ==
                                current_user.vendor.id).join(Vendor)
            return q
        return [
            InputColSpec('spu', _('spu'), filter_=filter_),
            InputColSpec('manufacture_date', _('manufacture date')),
            InputColSpec('expire_date', _('expire date')),
            InputColSpec('token', _('token')),
            InputColSpec('checksum', _('checksum'))]

    @property<commit_msg>fix #47<commit_after># -*- coding: UTF-8 -*-
from flask.ext.babel import gettext as _
from flask.ext.databrowser import ModelView, sa, filters
from flask.ext.databrowser.col_spec import ColSpec, InputColSpec
from flask.ext.databrowser.action import (DeleteAction, ACTION_OK,
                                          ACTION_IMPERMISSIBLE)
from flask.ext.principal import Permission, RoleNeed
from flask.ext.login import current_user
from genuine_ap.database import db
from genuine_ap.models import SKU, Vendor
from genuine_ap import const
from genuine_ap.apis import unwraps
from genuine_ap.spu import spu_model_view


class SKUModelView(ModelView):

    def try_edit(self, objs=None):
        if not Permission(self.edit_all_need).can():
            for obj in objs:
                Permission(spu_model_view.edit_need(obj.spu.id)).test()

    @property
    def can_batchly_edit(self):
        return Permission(RoleNeed(const.SUPER_ADMIN)).can()

    @property
    def sortable_columns(self):
        return ['id', 'manufacture_time', 'expire_time', 'create_time']

    @property
    def default_filters(self):
        if Permission(RoleNeed(const.VENDOR_GROUP)).can():
            return [filters.EqualTo('spu.vendor', self,
                                    value=unwraps(current_user.vendor))]
        return []

    @property
    def list_columns(self):
        return [ColSpec('id', _('id')),
                ColSpec('spu', _('spu')),
                ColSpec('spu.vendor', _('vendor')),
                ColSpec('manufacture_date', _('manufacture date')),
                ColSpec('expire_date', _('expire date')),
                ColSpec('token', _('token')),
                ColSpec('checksum', _('checksum')),
                ColSpec('create_time', _('create time'))]

    @property
    def create_columns(self):
        def filter_(q):
            if Permission(RoleNeed(const.VENDOR_GROUP)).can():
                return q.filter(Vendor.id ==
                                current_user.vendor.id).join(Vendor)
            return q
        return [
            InputColSpec('spu', _('spu'), filter_=filter_),
            InputColSpec('manufacture_date', _('manufacture date')),
            InputColSpec('expire_date', _('expire date')),
            InputColSpec('token', _('token')),
            InputColSpec('checksum', _('checksum'))]

    @property
{'fraction_non_alphanumeric': 0.12195642887654848, 'fraction_numerical': 0.0008543357539513029, 'mean_word_length': 2.5210526315789474, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5735513', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1334, 'n_words': 280}