Example #1
0
    def get(self):
        self.get_current_user()
        kwargs = dict(self.application.static_kwargs)
        kwargs['page_name'] = 'mobile_admin'
        kwargs['config'] = config
        kwargs['access_level'] = None

        ## check for logout
        logout_value = self.get_argument('logout', None)
        if logout_value == '1':
            self.clear_cookie('admin_code')
            self.redirect('/mobile/admin')

        ## check admin code
        admin_code = self.get_argument('admin_code', None)
        if admin_code is None:
            admin_code = self.get_secure_cookie('admin_code')

        if admin_code is None:
            kwargs['admin_status'] = False
            self.write(
                self.application.loader.load('mobile/admin.html').generate(
                    **kwargs))
            return

        resource = Resource(self.db, config)
        results = resource.verify_admin(admin_code)
        if results['meta']['status'] == 'OK':
            kwargs['admin_status'] = True
            kwargs['access_level'] = results['access_level']
            kwargs['resource_object'] = results['response']
            self.set_secure_cookie('admin_code', admin_code)
        else:
            kwargs['admin_status'] = False
            kwargs['access_level'] = False

        ## bedcount
        if kwargs['admin_status'] is True:
            addbed = self.get_argument('addbed', None)
            delbed = self.get_argument('delbed', None)

            if addbed == '1':
                resource = Resource(self.db, config)
                results2 = resource.add_bed(admin_code)

            if delbed == '1':
                resource = Resource(self.db, config)
                results2 = resource.del_bed(admin_code)

        resource = Resource(self.db, config)
        results = resource.verify_admin(admin_code)
        kwargs['resource_object'] = results['response']

        self.write(
            self.application.loader.load('mobile/admin.html').generate(
                **kwargs))
Example #2
0
 def post(self):
     admin_code = self.get_argument('admin_code', None)
     resource = Resource(self.db, config)
     self.write(resource.add_bed(admin_code))