コード例 #1
0
class TweetView(ModelView):
    column_list = ('name', 'user_name', 'text')
    column_sortable_list = ('name', 'text')

    column_filters = (filters.FilterEqual('name', 'Name'),
                      filters.FilterNotEqual('name', 'Name'),
                      filters.FilterLike('name', 'Name'),
                      filters.FilterNotLike('name', 'Name'),
                      filters.BooleanEqualFilter('testie', 'Testie'))

    column_searchable_list = ('name', 'text')

    form = TweetForm

    def get_list(self, *args, **kwargs):
        count, data = super(TweetView, self).get_list(*args, **kwargs)

        # Grab user names
        query = {'_id': {'$in': [x['user_id'] for x in data]}}
        users = db.user.find(query, fields=('name', ))

        # Contribute user names to the models
        users_map = dict((x['_id'], x['name']) for x in users)

        for item in data:
            item['user_name'] = users_map.get(item['user_id'])

        return count, data

    # Contribute list of user choices to the forms
    def _feed_user_choices(self, form):
        users = db.user.find(fields=('name', ))
        form.user_id.choices = [(str(x['_id']), x['name']) for x in users]
        return form

    def create_form(self):
        form = super(TweetView, self).create_form()
        return self._feed_user_choices(form)

    def edit_form(self, obj):
        form = super(TweetView, self).edit_form(obj)
        return self._feed_user_choices(form)

    # Correct user_id reference before saving
    def on_model_change(self, form, model):
        user_id = model.get('user_id')
        model['user_id'] = ObjectId(user_id)

        return model
コード例 #2
0
class TweetView(ModelView):
    column_list = ('name', 'user_name', 'text')
    column_sortable_list = ('name', 'text')

    column_filters = (filters.FilterEqual('name', 'Name'),
                      filters.FilterNotEqual('name', 'Name'),
                      filters.FilterLike('name', 'Name'),
                      filters.FilterNotLike('name', 'Name'),
                      filters.BooleanEqualFilter('testie', 'Testie'))

    # column_searchable_list = ('name', 'text')

    form = TweetForm

    def get_list(self, *args, **kwargs):
        # not necessary but kept as example
        count, data = super(TweetView, self).get_list(*args, **kwargs)

        # Contribute user_name to the models
        for item in data:
            user = collection_users.find_one({'_id': item['user_id']})
            if user:
                item['user_name'] = user['_id']

        return count, data

    # Contribute list of user choices to the forms
    def _feed_user_choices(self, form):
        users = collection_users.find(fields=('_id', ))
        form.user_id.choices = [(str(x['_id']), x['_id']) for x in users]
        return form

    def create_form(self):
        form = super(TweetView, self).create_form()
        return self._feed_user_choices(form)

    def edit_form(self, obj):
        form = super(TweetView, self).edit_form(obj)
        return self._feed_user_choices(form)
コード例 #3
0
class SchoolView(ModelView):
    def is_accessible(self):
       
        
        return current_user.is_authenticated()
    
    
    
    column_list = ('name', 'branchName')
    column_sortable_list = ('name')

    column_filters = (filters.FilterEqual('name', 'name'),filters.FilterNotEqual('name', 'name'),filters.FilterLike('name', 'name'),filters.FilterNotLike('name', 'name'))
                     

    column_searchable_list = ('name', 'name')

    form = SchoolForm
    
 
    def get_list(self, *args, **kwargs):
        count, data = super(SchoolView, self).get_list(*args, **kwargs)

        # Grab user names
        #query = {'name': {'$in': [x['user_id'] for x in data]}}
       
        for d in data:
            bn=[]
            for b in d["Branch"]:
                bn.append(b["branch"])
            d["branchName"]=bn
                
           

        

        return count, data
コード例 #4
0
class StudentView(ModelView):
    def is_accessible(self):

        return current_user.is_authenticated()

    def user_link_formatter(view, context, model, name):

        id = model["_id"]
        url = "/admin/grades?sid=" + str(id)
        name = model["fname"]
        return Markup('<a href="{}">{}</a>').format(url, name)

    column_details_list = ('fname', 'mname', 'lname', 'schoolName', 'dob',
                           'className')

    def user_link_formatter(view, context, model, name):

        id = model["_id"]
        url = "/admin/grades?sid=" + str(id)
        name = model["fname"]
        return Markup('<a href="{}">{}</a>').format(url, name)

    column_details_list = ('fname', 'mname', 'lname', 'schoolName', 'dob',
                           'className')

    def user_link_formatter(view, context, model, name):

        id = model["_id"]
        url = "/admin/grades?sid=" + str(id)
        name = model["fname"]
        return Markup('<a href="{}">{}</a>').format(url, name)

    def action_link_formatter(view, context, model, name):

        id = model["_id"]
        url = "/admin/grades?sid=" + str(id)
        name = model["fname"]
        return Markup('<a href="{}">{}</a>').format(url, "Enter Grades")

    column_details_list = ('fname', 'mname', 'lname', 'schoolName', 'dob',
                           'className')
    column_list = ('fname', 'mname', 'lname', 'schoolName', 'dob', 'className',
                   'Action')
    column_formatters = {
        "fname": user_link_formatter,
        "Action": action_link_formatter
    }

    column_formatters = {"fname": user_link_formatter}

    column_formatters = {"fname": user_link_formatter}

    column_sortable_list = ('fname')
    column_searchable_list = ('fname', 'className')
    column_filters = (filters.FilterEqual('fname', 'fname'),
                      filters.FilterNotEqual('fname', 'fname'),
                      filters.FilterLike('fname', 'fname'),
                      filters.FilterEqual('className', 'className'),
                      filters.FilterLike('schoolName', 'schoolName'))
    form = StudentForm

    def get_list(self, *args, **kwargs):
        count, data = super(StudentView, self).get_list(*args, **kwargs)

        for d in data:
            sid = d["school"]
            school = db.School.find_one({"_id": ObjectId(sid)})
            cid = d["classAssigned"]
            classAssigned = db.Classes.find_one({"_id": ObjectId(cid)})
            #print(school)

            d["schoolName"] = school["name"]
            d["className"] = classAssigned["name"]

        return count, data

        # Contribute list of user choices to the forms
    def _feed_school_choices(self, form):
        school = db.School.find(fields=('name', ))
        form.school.choices = [(str(x['_id']), x['name']) for x in school]
        return form

    def create_form(self):
        form = super(StudentView, self).create_form()
        return self._feed_school_choices(form)

    def edit_form(self, obj):
        form = super(StudentView, self).edit_form(obj)
        return self._feed_school_choices(form)