Exemplo n.º 1
0
 def get(self):
     try:
         current_user = self.current_user['name']
         notice_str = ''
         self.render('admin_public_goods.html', name=current_user,
                     notice=notice_str)
     except Exception, e:
         log.d(e)
Exemplo n.º 2
0
 def __insert_records(self, records):
     """
     insert records to collections named with api_name
     """
     api_names = list(set(r.api_name for r in records))
     for name in api_names:
         self.dh.insert_many(
             name, [r.__dict__ for r in records if r.api_name == name])
         log.d(' done to insert %s' % name)
Exemplo n.º 3
0
 def get_current_user(self):
     "返回值即为self.current_user的值."
     try:
         cookie = self.get_secure_cookie(etc.cookie_name)
         if cookie:
             user = sql.get_user_base_by_cookie(cookie)
             if user:
                 return user
             return {}
         return {}
     except Exception, e:
         log.d(e)
Exemplo n.º 4
0
 def __insert_pkg_names(self, records):
     """
     insert pkg_names to COLLECTION_PKG_NAMES
     """
     existed_pkg_names = [
         n.get(KEY_NAME) for n in self.dh.find(COLLECTION_PKG_NAMES)
     ]
     log.d('db_pns: %s' % existed_pkg_names)
     pkg_names = list(set(r.app_pkg_name for r in records))
     pkg_names = [n for n in pkg_names if n not in existed_pkg_names]
     log.d('insert_pns: %s' % pkg_names)
     if pkg_names:
         self.dh.insert_many(COLLECTION_PKG_NAMES, [{
             KEY_NAME: n
         } for n in pkg_names])
Exemplo n.º 5
0
 def get(self):
     try:
         goods = sql.query_goods_by_userid(self.current_user['id'])
         current_user = self.current_user['name']
         if goods:
             goods_name = goods['name']
             del goods['name']
             goods['goods_name'] = goods_name
             notice_str = ''
         else:
             notice_str = '您还没有发布商品!'
         self.render('admin_check_goods.html', name=current_user, goods=goods,
                     notice=notice_str)
     except Exception, e:
         log.d(e)
Exemplo n.º 6
0
 def post(self):
     try:
         name = self.get_argument('name')
         password = self.get_argument('password')
         if not name or not password:
             notice_str = '不能为空!'
             self.render('admin_login.html', notice=notice_str)
             return
         user = sql.get_user_base_by_name_password(name, password)
         if user:
             cookie = base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes)
             sql.save_session_by_userid_and_cookie(user['id'], cookie)
             self.set_secure_cookie(etc.cookie_name, cookie)
             self.redirect('/admin/')
         else:
             notice_str = '没有该用户,请重新输入!'
             self.render('admin_login.html', notice = notice_str)
     except Exception, e:
         log.d(e)
Exemplo n.º 7
0
    def __insert_app_version(self, records):
        """
        insert app_version to COLLECTION_APP_VERSION
        the data format like {name: appA, value: 2}, {name: appA, value: 3}, {name: appB, value: 10}
        """
        existed_versions = list(v
                                for v in self.dh.find(COLLECTION_APP_VERSIONS)
                                if v.pop('_id'))

        unique_version_str_list = list(
            set(r.app_pkg_name + '@' + r.app_version for r in records
                if r.app_pkg_name != '' and r.app_version != ''))
        uvs = list({
            KEY_NAME: v.split('@')[0],
            KEY_VALUE: v.split('@')[1]
        } for v in unique_version_str_list if len(v.split('@')) >= 2)
        filtered_vs = list(v for v in uvs if v not in existed_versions)
        log.d('insert app_version: ')
        pprint(filtered_vs)
        if filtered_vs:
            self.dh.insert_many(COLLECTION_APP_VERSIONS, filtered_vs)
Exemplo n.º 8
0
    def post(self):
        try:
            name = self.get_argument('name')
            price = self.get_argument('price')
            picture = self.get_argument('picture')
            types = self.get_argument('types')
            explain = self.get_argument('explain', '')
            current_user = self.current_user['name']

            if not name or not price or not picture or not types:
                notice_str = '商品名称、商品价格、图片、种类必须填写!'
            else:
                userid = self.current_user['id']
                goodsid = sql.save_goods_info(userid, name, price, picture, types, explain)
                if goodid:
                    notice_str = '您成功添加一件商品,请继续添加!'
                else:
                    notice_str = '商品添加失败,请重新添加!'
            self.render('admin_public_goods.html', name=current_user,
                        notice=notice_str)
        except Exception, e:
            log.d(e)
Exemplo n.º 9
0
 def get(self):
     try:
         self.clear_cookie(etc.cookie_name)
         self.redirect('/admin/')
     except Exception, e:
         log.d(e)
Exemplo n.º 10
0
 def get(self):
     try:
         current_user = self.current_user['name']
         self.render('admin.html', name=current_user)
     except Exception, e:
         log.d(e)
Exemplo n.º 11
0
 def get(self):
     try:
         notice_str = ''
         self.render('admin_login.html', notice=notice_str)
     except Exception, e:
         log.d(e)