Example #1
0
    def __init__(self, *args, **kwargs):

        ori_column_filters = []
        ori_column_filters.extend(self.column_filters)
        self.column_filters = ori_column_filters

        self.column_filters.extend([
            FilterLike(column=FlightLog.departureAirport, name='起飞机场'),
            FilterNotLike(column=FlightLog.departureAirport, name='起飞机场'),
            FilterEqual(column=FlightLog.departureAirport, name='起飞机场'),
            CaptainContainsFilter(column=FlightLog.captain, name='飞行人员'),
            FilterLike(column=FlightLog.landingAirport, name='降落机场'),
            FilterNotLike(column=FlightLog.landingAirport, name='降落机场'),
            FilterEqual(column=FlightLog.landingAirport, name='降落机场'),
            FilterLike(column=FlightLog.missionType, name='任务性质'),
            FilterNotLike(column=FlightLog.missionType, name='任务性质'),
            FilterEqual(column=FlightLog.missionType, name='任务性质'),
            FilterLike(column=FlightLog.flyProperty, name='飞行性质'),
            FilterNotLike(column=FlightLog.flyProperty, name='飞行性质'),
            FilterEqual(column=FlightLog.flyProperty, name='飞行性质'),
            FilterLike(column=FlightLog.workArea, name='作业区域'),
            FilterNotLike(column=FlightLog.workArea, name='作业区域'),
            FilterEqual(column=FlightLog.workArea, name='作业区域'),
        ])

        super(_FlightlogStatisticsView, self).__init__(*args, **kwargs)
Example #2
0
class CaseAdmin(sqla.ModelView):
    action_disallowed_list = [
        'delete',
    ]
    column_display_pk = True
    column_list = [
        'project', 'plan', 'tc_id', 'result', 'version', 'bug', 'executor',
        'execute_date'
    ]
    column_default_sort = [
        ('execute_date', False),
    ]  # sort on multiple columns

    # custom filter: each filter in the list is a filter operation (equals, not equals, etc)
    # filters with the same name will appear as operations under the same filter
    column_filters = [
        FilterEqual(column=Case.tc_id, name='TC_ID'),
        FilterEqual(column=Case.project, name='Project'),
        FilterEqual(column=Case.plan, name='Plan'),
        FilterEqual(column=Case.version, name='Version'),
        FilterEqual(column=Case.executor, name='Executor'),
    ]
    can_export = True
    export_max_rows = 1000
    export_types = ['csv', 'xls']
    column_searchable_list = [
        Case.tc_id, Case.plan, Case.project, Case.result, Case.version
    ]
    column_editable_list = ['bug', 'result']
    create_modal = True
    edit_modal = True
    can_view_details = True
Example #3
0
class UserAdmin(sqla.ModelView):
    can_view_details = True
    create_modal = True
    edit_modal = True
    column_auto_select_related = True
    column_default_sort = [('nickname', False)]  # sort on multiple columns
    action_disallowed_list = ['delete', ]

    form_choices = {
        'auth': USER_AUTH,
    }

    form_widget_args = {
        'id': {
            'readonly': True
        }
    }
    column_list = [
        'auth',
        'nickname',
        'email',
        'thumbnail'
    ]
    column_searchable_list = [
        'nickname',
        'email',
        'auth',
    ]
    column_editable_list = ['auth','thumbnail']
    column_details_list = [
        'id',
        'password',
    ] + column_list
    form_columns = [
        'id',
        'auth',
        'nickname',
        'email',
        'thumbnail'
    ]
    form_create_rules = [
        'nickname',
        'auth',
        'email',
    ]
    column_filters = [
        'nickname',
        FilterEqual(column=User.nickname, name='Nick Name'),
        'auth',
        'email',
    ]
    def edit_form(self, obj):
        return self._filtered_posts(
            super(UserAdmin, self).edit_form(obj)
        )
    def is_accessible(self):
        try :
            return current_user.is_admin
        except :
            False
Example #4
0
class PersistentIdentifierModelView(ModelView):
    """ModelView for the PersistentIdentifier."""

    can_create = False
    can_edit = False
    can_delete = False
    can_view_details = True
    column_display_all_relations = True
    column_list = (
        'pid_type', 'pid_value', 'status', 'object_type',
        'object_uuid', 'created', 'updated', 'object',
    )
    column_labels = dict(
        pid_type=_('PID Type'),
        pid_value=_('PID'),
        pid_provider=_('Provider'),
        status=_('Status'),
        object_type=_('Object Type'),
        object_uuid=_('Object UUID'),
    )
    column_filters = (
        'pid_type', 'pid_value', 'object_type',
        FilterUUID(PersistentIdentifier.object_uuid, _('Object UUID')),
        FilterEqual(PersistentIdentifier.status, _('Status'),
                    options=[(s.value, s.title) for s in PIDStatus]),
    )
    column_searchable_list = ('pid_value', )
    column_default_sort = ('updated', True)
    column_formatters = dict(object=object_formatter)
    page_size = 25
class UserAdmin(sqla.ModelView):
    # each filter in the list is a filter operation (equals, not equals, etc)
    # filters with the same name will appear as operations under the same filter
    column_filters = [
        FilterEqual(User.last_name, 'Last Name'),
        FilterLastNameBrown(User.last_name, 'Last Name', options=(('1', 'Yes'),('0', 'No')))
    ]
Example #6
0
class SectionView(ModelView):
    # can_create = False
    can_delete = False
    can_export = True
    can_view_details = True

    column_filters = (
        FilterEqual(Section.function,
                    "Function",
                    options=[["notify", "Notify"],
                             ["animeEpisode", "AnimeEpisode"],
                             ["device", "Device"]]),
        FilterEqual(Section.function,
                    "Type",
                    options=[["json", "Json"], ["rawText", "RawText"]]),
    )
Example #7
0
class UserAdmin(sqla.ModelView):
    # each filter in the list is a filter operation (equals, not equals, etc)
    # filters with the same name will appear as operations under the same filter
    column_filters = [
        FilterEqual(column=User.last_name, name="Last Name"),
        FilterLastNameBrown(column=User.last_name,
                            name="Last Name",
                            options=(("1", "Yes"), ("0", "No"))),
    ]
Example #8
0
class AdminWPTUserLoginLogModelView(AdminBaseModelView):
    column_default_sort = ('id', True)

    column_filters = [
        FilterEqual(column=WPTUserLoginLog.user_id, name='User Id')
    ]

    def is_visible(self):
        return False
Example #9
0
class AdminBIUserBillModelView(AdminBaseModelView):
    def product_formatter(v, c, m, p):
        return '%s: %s' % (m.category, m.goods)

    def user_id_formatter(v, c, m, p):
        return Markup('<a href="/data/bi_user/details/?user_id=%s" target="_blank">%s</a>' % (m.user_id, m.user_id))

    column_formatters = dict(product=product_formatter, user_id=user_id_formatter)

    column_default_sort = ('created_at', True)
    column_list = ['user_id', 'platform', 'currency_type', 'currency_amount', 'product', 'quantity', 'created_at']
    column_sortable_list = ['currency_amount', 'quantity', 'created_at']

    currency_type_options = (
        ('Gold', 'Gold'),
        ('MasterPoints', 'MasterPoints'),
        ('Dollar', 'Dollar'),
        ('Silver Coins', 'Silver Coins')
    )

    category_options = (
        ('Gold', 'Gold'),
        ('Silver Coins', 'Silver Coins'),
        ('Lucky Spin Set', 'Lucky Spin Set'),
        ('Poker Lucky Charm Set', 'Poker Lucky Charm Set'),
        ('Avatar Set', 'Avatar Set'),
        ('Poker Ticket Set', 'Poker Ticket Set'),
        ('Emoji Set', 'Emoji Set')
    )

    platform_options = (
        ('Web', 'Web'),
        ('iOS', 'iOS'),
        ('Android', 'Android'),
        ('Facebook Game', 'Facebook Game'),
        ('Unknown', 'Unknown')
    )

    column_filters = [
        FilterEqual(column=BIUserBill.user_id, name='User Id'),
        FilterEqual(column=BIUserBill.currency_type, name='Paid Currency', options=currency_type_options),
        FilterEqual(column=BIUserBill.category, name='Product Category', options=category_options),
        FilterEqual(column=BIUserBill.platform, name='Platform', options=platform_options),
    ]
Example #10
0
class UserAdmin(TahModelView):
    column_default_sort = 'id'
    extra_js = [
        '//cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.1.0/paho-mqtt.min.js',
        '//cdnjs.cloudflare.com/ajax/libs/jquery-color/2.1.2/jquery.color.min.js',
        '/static/js/mq.js',
        '/static/js/admin-style.js',
    ]
    extra_css = ['/static/css/admin-style.css']
    page_size = False
    action_disallowed_list = [
        'delete',
    ]
    column_display_pk = True
    column_list = [
        'id',
        'last_name',
        'first_name',
        'email',
        'pets',
    ]
    column_editable_list = [
        #'id',
        'last_name',
        'first_name',
        'email',
        'pets',
    ]
    #column_default_sort = [('last_name', False), ('first_name', False)]  # sort on multiple columns

    # custom filter: each filter in the list is a filter operation (equals, not equals, etc)
    # filters with the same name will appear as operations under the same filter
    column_filters = [
        FilterEqual(column=User.last_name, name='Last Name'),
        FilterLastNameBrown(column=User.last_name,
                            name='Last Name',
                            options=(('1', 'Yes'), ('0', 'No')))
    ]
    inline_models = [
        (UserInfo, inline_form_options),
    ]

    # setup create & edit forms so that only 'available' pets can be selected
    def create_form(self):
        return self._use_filtered_parent(super(UserAdmin, self).create_form())

    def edit_form(self, obj):
        return self._use_filtered_parent(super(UserAdmin, self).edit_form(obj))

    def _use_filtered_parent(self, form):
        form.pets.query_factory = self._get_parent_list
        return form

    def _get_parent_list(self):
        # only show available pets in the form
        return Pet.query.filter_by(available=True).all()
Example #11
0
 def index_view(self):
     self.dynamic_filters = []
     self.dynamic_filters.extend([
         FilterEqual(column=Timesheet.belongto_team,
                     name=u'班组',
                     options=get_all_team_names),
         # Add further dynamic filters here
     ])
     self._refresh_filters_cache()
     return super(PendingApprovedModelView, self).index_view()
Example #12
0
class CitiesAdmin(AdminModelView):
    page_size = 100
    can_create = True
    can_edit = True
    column_list = ('country_code', 'city_name', 'lat', 'lng')
    column_hide_backrefs = True
    column_display_all_relations = False
    form_columns = ['country_code', 'city_name', 'lat', 'lng']
    column_filters = [
        FilterEqual(column=Cities.country_code, name='Country code'),
    ]
Example #13
0
class AdminBIUserCurrencyModelView(AdminBaseModelView):
    def transaction_type_formatter(v, c, m, p):
        return m.transaction_type_display()

    def user_id_formatter(v, c, m, p):
        return Markup('<a href="/data/bi_user/details/?user_id=%s" target="_blank">%s</a>' % (m.user_id, m.user_id))

    column_formatters = dict(transaction_type=transaction_type_formatter, user_id=user_id_formatter)

    column_default_sort = ('created_at', True)
    column_list = ['user_id', 'og_account', 'currency_type', 'transaction_type', 'transaction_amount', 'balance',
                   'created_at']
    column_sortable_list = ['transaction_amount', 'balance', 'created_at']

    column_filters = [
        FilterEqual(column=BIUserCurrency.user_id, name='User Id'),
        FilterEqual(column=BIUserCurrency.currency_type, name='Currency Type',
                    options=(('Gold', 'Gold'), ('Silver', 'Silver'))),
        FilterEqual(column=BIUserCurrency.transaction_type, name='Transaction Type'),
        FilterInStringList(column=BIUserCurrency.transaction_type, name='Transaction Type')
    ]
Example #14
0
class UserAdmin(sqla.ModelView):
    action_disallowed_list = [
        'delete',
    ]
    column_display_pk = True
    column_list = [
        'id',
        'last_name',
        'first_name',
        'email',
        'pets',
    ]
    column_default_sort = [('last_name', False),
                           ('first_name', False)]  # sort on multiple columns

    # custom filter: each filter in the list is a filter operation (equals, not equals, etc)
    # filters with the same name will appear as operations under the same filter
    column_filters = [
        FilterEqual(column=User.last_name, name='Last Name'),
    ]
    inline_models = [
        (UserInfo, inline_form_options),
    ]
    can_export = True
    export_max_rows = 1000
    export_types = ['csv', 'xls']
    column_searchable_list = [
        User.first_name,
        User.last_name,
        User.email,
    ]

    # setup create & edit forms so that only 'available' pets can be selected
    def create_form(self):
        return self._use_filtered_parent(super(UserAdmin, self).create_form())

    def edit_form(self, obj):
        return self._use_filtered_parent(super(UserAdmin, self).edit_form(obj))

    def _use_filtered_parent(self, form):
        form.pets.query_factory = self._get_parent_list
        return form

    def _get_parent_list(self):
        # only show available pets in the form
        return Pet.query.filter_by(available=True).all()
Example #15
0
class UserAdmin(sqla.ModelView):

    can_view_details = True  # show a modal dialog with records details
    action_disallowed_list = [
        'delete',
    ]

    form_choices = {
        'type': AVAILABLE_USER_TYPES,
    }
    form_args = {
        'dialling_code': {
            'label': 'Dialling code'
        },
        'local_phone_number': {
            'label': 'Phone number',
            'validators': [is_numberic_validator]
        },
    }
    form_widget_args = {'id': {'readonly': True}}
    column_list = [
        'type',
        'first_name',
        'last_name',
        'email',
        'ip_address',
        'currency',
        'timezone',
        'phone_number',
    ]
    column_searchable_list = [
        'first_name',
        'last_name',
        'phone_number',
        'email',
    ]
    column_editable_list = ['type', 'currency', 'timezone']
    column_details_list = [
        'id',
        'featured_post',
        'website',
        'enum_choice_field',
        'sqla_utils_choice_field',
        'sqla_utils_enum_choice_field',
    ] + column_list
    form_columns = [
        'id',
        'type',
        'featured_post',
        'enum_choice_field',
        'sqla_utils_choice_field',
        'sqla_utils_enum_choice_field',
        'last_name',
        'first_name',
        'email',
        'website',
        'dialling_code',
        'local_phone_number',
    ]
    form_create_rules = [
        'last_name',
        'first_name',
        'type',
        'email',
    ]

    column_auto_select_related = True
    column_default_sort = [('last_name', False),
                           ('first_name', False)]  # sort on multiple columns

    # custom filter: each filter in the list is a filter operation (equals, not equals, etc)
    # filters with the same name will appear as operations under the same filter
    column_filters = [
        'first_name',
        FilterEqual(column=User.last_name, name='Last Name'),
        FilterLastNameBrown(column=User.last_name,
                            name='Last Name',
                            options=(('1', 'Yes'), ('0', 'No'))),
        'phone_number',
        'email',
        'ip_address',
        'currency',
        'timezone',
    ]
    column_formatters = {'phone_number': phone_number_formatter}

    # setup edit forms so that only posts created by this user can be selected as 'featured'
    def edit_form(self, obj):
        return self._filtered_posts(super(UserAdmin, self).edit_form(obj))

    def _filtered_posts(self, form):
        form.featured_post.query_factory = lambda: Post.query.filter(
            Post.user_id == form._obj.id).all()
        return form
Example #16
0
class UserView(MyModelView):
    #id, username, confirmed, email, __password_hash, role_id, location, about_me, member_since, last_seen
    can_view_details = True  # show a modal dialog with records details

    form_widget_args = {'id': {'readonly': True}}
    column_list = [
        'id', 'role_id', 'username', 'confirmed', 'email', 'location',
        'about_me', 'member_since', 'last_seen'
    ]

    column_auto_select_related = True

    column_searchable_list = [
        'id', 'role_id', 'username', 'confirmed', 'email', 'location',
        'about_me', 'member_since', 'last_seen'
    ]

    column_editable_list = [
        'username',
        'confirmed',
        'email',
        'location',
        'about_me',
        'member_since',
    ]

    column_default_sort = [('username', False),
                           ('last_seen', False)]  # sort on multiple columns

    # custom filter: each filter in the list is a filter operation (equals, not equals, etc)

    # filters with the same name will appear as operations under the same filter
    column_filters = [
        'username',
        FilterEqual(column=User.username, name='User Name'),
        #FilterLastNameBrown(column=User.last_name, name='Last Name',
        #                    options=(('1', 'Yes'), ('0', 'No'))),
        'member_since',
        'email',
        'confirmed',
        'last_seen',
        'location',
    ]
    #    column_formatters = {'phone_number': phone_number_formatter}

    # setup edit forms so that only posts created by this user can be selected as 'featured'
    form_create_rules = [
        # Header and four fields. Email field will go above phone field.
        rules.FieldSet(('username', 'email', 'role', 'confirmed',
                        'member_since', 'last_seen'), 'Personal'),
        # Separate header and few fields
        rules.Header('Location'),
        rules.Field('location'),
        # String is resolved to form field, so there's no need to explicitly use `rules.Field`
        # Show macro that's included in the templates
        rules.Container('rule_demo.wrap', rules.Field('about_me'))
    ]

    form_edit_rules = form_create_rules

    create_template = 'admin/create_user.html'
    edit_template = 'admin/edit_user.html'

    def edit_form(self, obj):
        return self._filtered_roles(super(UserView, self).edit_form(obj))

    def _filtered_roles(self, form):
        form.role.query_factory = lambda: Role.query.filter(
            Role.permission == form._obj.id).all()
        return form
Example #17
0
class ComplianceView(ModelView):
    """View for managing Compliance results."""

    can_edit = False
    can_export = True
    can_delete = False
    can_create = False
    can_view_details = True
    column_default_sort = ('updated', True)

    column_list = ('publisher', 'journal', 'updated', 'recid', 'doi', 'arxiv', 'accepted', 'results', 'history_count')
    column_formatters = {
        'results': macro('render_results'),
        'doi': macro('render_doi'),
        'arxiv': macro('render_arxiv'),
        'accepted': macro('render_accepted'),
        'recid': macro('render_url'),
    }
    column_labels = {
        'results': 'Problems',
        'arxiv': 'arXiv number',
    }
    column_sortable_list = (
        Compliance.updated,
        Compliance.publisher,
        Compliance.journal,
        Compliance.doi,
        Compliance.arxiv,
    )
    column_filters = (
        Compliance.created,
        Compliance.updated,
        FilterByAccepance(column=None, name='Acceptance'),
        FilterLike(column=Compliance.publisher, name='Publisher'),
        FilterLike(column=Compliance.journal, name='Journal'),
        FilterEqual(column=Compliance.doi, name='DOI'),
        FilterEqual(column=Compliance.arxiv, name='arXiv'),
    )

    column_export_list = ('updated', 'publisher', 'journal', 'doi', 'arxiv', 'accepted', 'problems', 'url')
    column_formatters_export = {
        'doi': lambda v, c, m, p: m.doi,
        'arxiv': lambda v, c, m, p: m.arxiv,
        'accepted': lambda v, c, m, p: 'YES' if m.accepted else 'NO',
        'url': lambda v, c, m, p: url_for('compliance.details_view', id='%s,%s' % (m.id, m.id_record), _external=True),
        'problems': export_generate_problems,
    }

    list_template = 'scoap3_compliance/admin/list.html'
    details_template = 'scoap3_compliance/admin/details.html'

    def action_base(self, ids, action):
        """Calls given function for all id separately.
        @:return count of successful actions
        """
        count = 0
        for id in ids:
            id, _ = id.split(',')
            if action(id):
                count += 1

        db.session.commit()
        return count

    @action('accept', 'Accept', 'Are you sure you want to mark all selected record as accepted?')
    def action_accept(self, ids):
        count = self.action_base(ids, Compliance.accept)
        if count > 0:
            flash('%d compliance record(s) were successfully accepted.' % count, 'success')

    @action('reject', 'Reject', 'Are you sure you want to mark all selected record as rejected?')
    def action_reject(self, ids):
        count = self.action_base(ids, Compliance.reject)
        if count > 0:
            flash('%d compliance record(s) were successfully rejected.' % count, 'success')

    @action('rerun', 'Rerun', 'Are you sure you want to run again the compliance check for selected records?')
    def action_rerun(self, ids):
        self.action_base(ids, Compliance.rerun)
        flash('%d record(s) will be checked shortly for compliance. '
              'This process can a few minutes to complete.' % len(ids), 'success')