def GET(self): self._init_form() if request.method != 'POST': return self._view.render('app_add', form=self._form) if self._form.validate(): try: r = re.search(r"""itunes\.apple\.com\/(.*?)\/app\/.*?\/id(.*?)\?.*?""", request.form['apple_url']) track_id = int(r.group(2)) url = 'http://itunes.apple.com/%s/lookup?id=%s' % (r.group(1), track_id) apple_data = requests.get(url) data = str(apple_data.content).decode('utf-8') data = cjson.decode(data) if int(data['resultCount']) == 0: message = {'status':'error', 'message':'找不到苹果官方数据,可能此应用已经下架'} else: data = data['results'][0] app = DB.AppBase.find_one({'trackId':track_id}) if app is None: _id = DB.AppBase.insert(data) app = DB.AppBase.find_one({'trackId':track_id}) else: _id = app['_id'] DB.AppBase.update({'_id':ObjectId(_id)}, {'$set':data}) return redirect(url_for("admin_app_edit") + "?_id=" + str(app["_id"])) except Exception, ex: message = {'status':'error', 'message':str(ex)}
def post(self): genre_id = request.form["genre_id"] if request.files["icon"].filename != '': icon = request.files["icon"] hash_str, abs_save_file, save_file = upload_hash_file(icon, settings["pic_upload_dir"]) DB.app_genre.update({'genreId': int(genre_id)}, {'$set':{"icon_file": save_file}}, upsert=True) return redirect(url_for("admin_genre_list"))
def post(self): if not self.login_form.has_error(): username, password = request.form["username"], request.form["password"] user = User.find_one(username=username) if user and user.verify_password(password): login_user(user) return redirect(url_for('admin_app_collection_list')) flash(u"错误的用户名或者密码") return self._view.render('login', title="维享管理系统", form=self.login_form)
def get(self): logout_user() return redirect(url_for('LoginView:get'))
if self._form.validate(): _id = MongoId() data = { '_id': _id, 'trackId':int(request.form['trackId']), 'trackName':request.form['trackName'], 'bundleId':request.form['bundleId'], 'version':request.form['version'], 'primaryGenreId':int(request.form['primaryGenreId']), 'languageCodesISO2A':request.form.getlist('languageCodesISO2A'), 'description':request.form['description'], 'releaseNotes':request.form['releaseNotes'], 'review': int(request.form['review']) } DB.AppBase.update({'bundleId':request.form['bundleId']}, {'$set':data}, upsert=True) return redirect(create_url('.app.edit', {'_id':_id})) else: message = {'status':'error', 'message':'添加失败'} self._form.add_message(**message) return self._view.render('app_create', form=self._form) class AppDetailBaseView(View): ''' 应用详细信息基类 ''' def before_request(self, name): super(AppDetailBaseView, self).before_request(name)
def get(self): ha = request.args.get("ha", None) if ha: print(self.app_download.get_download_url(ha)) return redirect(self.app_download.get_download_url(ha), code=302)