def pathway(request, pathway_id): result = urlfetch.fetch("http://www.kegg.com/kegg/pathway/map/map" + pathway_id + ".html") pathway_re = re.compile(r'KEGG PATHWAY:.+') pathway_name = pathway_re.findall(result.content)[0].split(": ")[1].replace(" - Reference pathway", "") org_re = re.compile(r'<option\s{1}value="\w{3}">.+') organisms = [] organism_name_for = {} orgs = org_re.findall(result.content) for org in orgs: org_code = org.split('"')[1] org_name = org.split('>')[1] organisms.append(Organism(org_code, org_name)) organism_name_for[org_code] = org_name # sort by organism name alphabetical_organism = sorted(organism_name_for.iteritems(), key = itemgetter(1)) if request.method == "POST": selected_organism_code = request.form['organism'] selected_organism_name = organism_name_for[selected_organism_code] json_layout = urlfetch.fetch("http://cg06.naist.jp/metadav/layout/" + selected_organism_code + pathway_id + "layout.json").content json_data = urlfetch.fetch("http://cg06.naist.jp/metadav/data/" + selected_organism_code + pathway_id + "data.json").content #json_layout = urlfetch.fetch("http://dl.dropbox.com/u/157897/bsu00020layout.json").content #json_data = urlfetch.fetch("http://dl.dropbox.com/u/157897/bsu00020data.json").content return render_to_response('myapp/cytoscape.html', {'pathway_id': pathway_id, 'pathway_name': pathway_name, 'alphabetical_organism': alphabetical_organism, 'selected_organism_code': selected_organism_code, 'selected_organism_name': selected_organism_name, 'json_layout': json_layout, 'json_data': json_data}) else: return render_to_response('myapp/pathway.html', {'pathway_id': pathway_id, 'pathway_name': pathway_name, 'alphabetical_organism': alphabetical_organism})
def add_image_task(request, task_id): data = memcache.get(task_id) memcache.delete(task_id) if not data or not data.get('gift_id') or not data.get('img_url'): return render_to_response('empty.html') img = urlfetch.fetch(data['img_url']) if img.status_code == 200: thumb = img.content gift = Gift.get_by_id(data['gift_id']) if gift: title = gift.name.replace('"', '"') content_type = 'image/jpeg' thumb_img = ThumbImage() thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700, ), title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ), title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ), title=title, content_type=content_type) thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ), title=title, content_type=content_type) thumb_img.put() gift.thumbs.append(str(thumb_img.key())) if not gift.main_thumb: gift.main_thumb = str(thumb_img.key()) gift.put() return render_to_response('empty.html')
def get(self): tel = self.request.args.get("tel") devId = self.request.args.get("devid") simSerial = self.request.args.get("simserial") if tel is None or devId is None or simSerial is None: req_param = "tel:" + str(tel) + "/devId:" + str(devId) + "/simSerial:" + str(simSerial) raise BadRequest("param error.") query = AndroidUser.all() query.filter("tel =", tel) query.filter("devId =", devId) query.filter("simSerial =", simSerial) android = query.get() # まずは電話番号で検索 android = AndroidUser.get_by_key_name("AU" + tel) if android is None: # 未登録 req_param = "tel:" + str(tel) + "/devId:" + str(devId) + "/simSerial:" + str(simSerial) raise NotFound("not found Android user. " + req_param) else: if devId == android.dev_id and simSerial == android.sim_serial: # 最終アクセス日時更新 android.put() return render_to_response('backend/result.xml', {'state': "OK", 'message': 'The user was Registed.'}, mimetype="text/xml") else: return render_to_response('backend/result.xml', {'state': "CHANGED", 'message': 'The user was Registed. but detail was changed.'}, mimetype="text/xml")
def my_list(request, ordering='popularne'): if ordering not in ORDERINGS.keys(): return NotFound() prev, recipes, next = PagerQuery(models.Recipe) \ .ancestor(request.user) \ .filter('disabled =', False) \ .order(ORDERINGS[ordering]) \ .fetch(settings.PAGE_SIZE, request.args.get('b', None)) if request.is_xhr: return render_to_response('przepisy/includes/my_list.html', { 'recipes': recipes, 'prev': prev, 'ordering': ordering, 'next': next, }) else: return render_to_response('przepisy/my_list.html', { 'recipes': recipes, 'prev': prev, 'next': next, 'ordering': ordering, 'fav_recipes': models.Favs.get_list(request.user.key()), })
def admin_edit(request, uid): news = News.get_by_id(uid) if not news: return redirect(url_for('news/admin')) form = NewsForm(initial={ 'title':news.title, 'is_display':news.is_display, 'short_text':news.short_text, 'text':news.text }) if request.method == 'POST': if form.validate(request.form): news.title = form['title'] news.is_display = form['is_display'] news.short_text = form['short_text'] news.text = form['text'] news.put() return redirect(url_for('news/admin')) else: return render_to_response( 'news/admin/edit.html', { 'form': form.as_widget(), 'news': news }) return render_to_response( 'news/admin/edit.html', { 'form': form.as_widget(), 'news': news })
def show(request): gifts = [] order_items = request.session.get('order', {}) if not order_items: return render_to_response('cart/show.html', {'gifts':gifts}) total_price = 0 for k, val in order_items.iteritems(): gift = Gift.get_by_id(k) if gift: gift.count = val gifts.append(gift) total_price += gift.price * val form = OrderForm() if request.method == 'POST' and form.validate(request.form): order = form.save(commit=False) order.email = request.form.get('email', None) order.address = request.form.get('address', None) order.put() for k, v in request.session.get('order', {}).items(): gift = Gift.get_by_id(k) if gift: oi = OrderItem(gift_id=gift, count=v) oi.in_order = order oi.put() clear_cart(request) return render_to_response('cart/confirm_complete.html') return render_to_response('cart/show.html', {'gifts':gifts, 'total_price':total_price, 'form':form.as_widget()})
def r_info_edit(request, uid): r_info = RetailInfo.get_by_id(uid) if not r_info: return redirect(url_for('page/admins/r_info/index')) form = NewsForm(initial={ 'title':r_info.title, 'is_display':r_info.is_display, 'short_text':r_info.short_text, 'text':r_info.text }) if request.method == 'POST': if form.validate(request.form): r_info.title = form['title'] r_info.is_display = form['is_display'] r_info.short_text = form['short_text'] r_info.text = form['text'] r_info.put() return redirect(url_for('page/admins/r_info/index')) else: return render_to_response( 'page/admins/r_info/edit.html', { 'form': form.as_widget(), 'r_info': r_info }) return render_to_response( 'page/admins/r_info/edit.html', { 'form': form.as_widget(), 'r_info': r_info })
def trash_ajax(request): if request.method == 'POST': last_gift = request.values.get('last_gift') if last_gift: last_gift = int(last_gift) gifts = gifts = Gift.all().filter('in_trash =', True) if gifts: gifts = gifts.fetch(50, last_gift) return render_to_response('gift/list.html', {'gifts': gifts}) return render_to_response("empty.html")
def pathway(request, pathway_id): result = urlfetch.fetch("http://www.kegg.com/kegg/pathway/map/map" + pathway_id + ".html") pathway_re = re.compile(r'KEGG PATHWAY:.+') pathway_name = pathway_re.findall( result.content)[0].split(": ")[1].replace(" - Reference pathway", "") org_re = re.compile(r'<option\s{1}value="\w{3}">.+') organisms = [] organism_name_for = {} orgs = org_re.findall(result.content) for org in orgs: org_code = org.split('"')[1] org_name = org.split('>')[1] organisms.append(Organism(org_code, org_name)) organism_name_for[org_code] = org_name # sort by organism name alphabetical_organism = sorted(organism_name_for.iteritems(), key=itemgetter(1)) if request.method == "POST": selected_organism_code = request.form['organism'] selected_organism_name = organism_name_for[selected_organism_code] json_layout = urlfetch.fetch("http://cg06.naist.jp/metadav/layout/" + selected_organism_code + pathway_id + "layout.json").content json_data = urlfetch.fetch("http://cg06.naist.jp/metadav/data/" + selected_organism_code + pathway_id + "data.json").content #json_layout = urlfetch.fetch("http://dl.dropbox.com/u/157897/bsu00020layout.json").content #json_data = urlfetch.fetch("http://dl.dropbox.com/u/157897/bsu00020data.json").content return render_to_response( 'myapp/cytoscape.html', { 'pathway_id': pathway_id, 'pathway_name': pathway_name, 'alphabetical_organism': alphabetical_organism, 'selected_organism_code': selected_organism_code, 'selected_organism_name': selected_organism_name, 'json_layout': json_layout, 'json_data': json_data }) else: return render_to_response( 'myapp/pathway.html', { 'pathway_id': pathway_id, 'pathway_name': pathway_name, 'alphabetical_organism': alphabetical_organism })
def admin_images(request, uid): showcase = Showcase.get_by_id(uid) if not showcase: return render_to_response('empty.html') images = showcase.images url = blobstore.create_upload_url(url_for('showcase/admin/images/add', uid=showcase.key().id())) return render_to_response('showcase/admin/images.html',{ 'images': images, 'showcase': showcase, 'url': url })
def r_info_images(request, uid): r_info_obj = RetailInfo.get_by_id(uid) if not r_info_obj: return render_to_response('empty.html') images = RetailInfoImage.query(RetailInfoImage.news_ref == r_info_obj.key) url = blobstore.create_upload_url(url_for('page/admins/r_info/images/add', uid=r_info_obj.key.id())) return render_to_response('page/admins/r_info/images.html',{ 'images': images, 'r_info': r_info_obj, 'url': url })
def images(request, uid): category = Category.get_by_id(uid) if not category: return render_to_response('empty.html') url = blobstore.create_upload_url(url_for('shop/admin/category/images/add', uid=category.key.id())) return render_to_response('shop/admin/category_images.html',{ 'images': category.images, 'category': category, 'url': url })
def admin_images(request, uid): news = News.get_by_id(uid) if not news: return render_to_response('empty.html') images = NewsImage.query(NewsImage.news_ref == news.key) url = blobstore.create_upload_url(url_for('news/admin/images/add', uid=news.key.id())) return render_to_response('news/admin/images.html',{ 'images': images, 'news': news, 'url': url })
def preview(request,entity_key): ''' preview page ''' browser_lang = request.lang entity = db.get(entity_key) model_name = entity.kind() key_name = entity.key().name() page = get_page_content(browser_lang,model_name,key_name,True) if page is None: return render_to_response('mainapp/404.html', {}) page.title = '('+_('Preview')+')'+page.title sidebar = {'sidebar_title':_('Link'),'sidebar_list':[{'title':_('About'),'url':'/about/'},{'title':_('Contact'),'url':'/contact/'}]} return render_to_response('mainapp/show_each_page.html', {'page': page,'model_name':model_name,'sidebar':sidebar})
def view(request, author, slug): recipe = get_or_404(models.Recipe, db.Key.from_path('PMMUser', author, 'Recipe', slug)) if recipe.disabled: return NotFound() similar = models.Recipe.search(recipe.title, limit=10, order='-created') if recipe.key() in similar: similar.remove(recipe.key()) similar = db.get(similar) is_author = False if request.user.is_authenticated() and request.user.is_admin: is_admin = True else: is_admin = False if request.user.is_authenticated() and author == request.user.key().name(): show = True is_author = True elif recipe.rec_vis == VISIBILITY[0] and (request.user.is_anonymous() or author != request.user.key().name()): show = False elif recipe.rec_vis == VISIBILITY[1] and (request.user.is_anonymous() or not is_my_friend(request.user.key().name(), author)): show = False else: show = True if show: ingredients = models.RecipeIngr.all().ancestor(recipe).order('__key__').fetch(20) if request.user.is_authenticated(): is_a_fave = models.Favs.is_a_fave(request.user.key(), recipe.key()) else: is_a_fave = False return render_to_response('przepisy/view.html', { 'recipe': recipe, 'ingredients': ingredients, 'similar': similar, 'is_a_fave': is_a_fave, 'is_author': is_author, 'is_admin': is_admin, }) else: return render_to_response('przepisy/view_private.html', { 'recipe': recipe, 'similar': similar, 'private': recipe.rec_vis == VISIBILITY[0], 'is_admin': is_admin, })
def load(request, offset): offset = int(offset) if offset <= 0: return render_to_response('empty.html') grams = GramPhoto.query().order(-GramPhoto.add_time) length = grams.count() if offset >= length: return render_to_response('empty.html') limit = 8 is_end = False if offset + limit >= length: limit = length - offset is_end = True grams = grams.fetch(limit, offset=offset-1) return render_to_response('gram/load.html', {'grams': grams, 'is_end': is_end})
def show_each_article(request,key_name): browser_lang = request.lang try: prior_lang = request.args['hl'] except: prior_lang = None if prior_lang and browser_lang != prior_lang: browser_lang = prior_lang model_name = 'Article' page = get_page_content(browser_lang,model_name,key_name) if page is None: return render_to_response('mainapp/404.html', {}) results_dic = get_article_list(browser_lang,1,10) sidebar = {'sidebar_title':_('Back number'),'sidebar_list':results_dic['articles']} return render_to_response('mainapp/show_each_page.html', {'page': page,'model_name':model_name,'sidebar':sidebar})
def confirm(request): if not request.session.get('order', {}): return redirect('/cart/show/') form = OrderForm() if request.method == 'POST' and form.validate(request.form): order = form.save() for k, v in request.session.get('order', {}).items(): gift = Gift.get_by_id(k) if gift: oi = OrderItem(gift_id=gift, count=v) oi.in_order = order oi.put() clear_cart(request) return render_to_response('cart/confirm_complete.html') return render_to_response('cart/confirm.html', {'form':form.as_widget()})
def index(request): form = RegFormForm() if request.method == 'POST': if request.form and form.validate(request.form): tmp = form.save(commit=False) if not tmp.address: tmp.put() return render_to_response('index/thanks.html') else: return render_to_response('index/index.html', {'form':form.as_widget()}) cache_page = memcache.get('index_page') if not cache_page: cache_page = render_to_string('index/index.html', {'form':form.as_widget()}) memcache.add('index_page', cache_page, 24 * 60 * 60) return Response(cache_page, content_type="text/html; charset=utf-8")
def get_menu(request): filters = request.session.get('filters', []) if request.user.is_admin: return render_to_response( 'categories_view.html', { 'subcategories': Gift.get_subcategories_list(filters, is_admin=True), 'brand_list': Gift.get_brand_list(filters, is_admin=True) }) return render_to_response( 'categories_view.html', { 'subcategories': Gift.get_subcategories_list(filters), 'brand_list': Gift.get_brand_list(filters) })
def result(request): """速度の測定値結果を表示するページ Args: request: リクエストオブジェクト Return: レンダリングされたテンプレートデータ まだ仕様未決の為適当実装 """ form = MeasuredResultForm() if request.method == "POST": if form.validate(request.form): # 仕様未決の為実装は適当 result = form.save() return redirect(url_for('kokodoya/index')) render_params = {} render_params['form'] = form.as_widget() current = datetime.datetime.now() render_params['measured_time'] = current.strftime("%Y/%m/%d %H:%M") # todo : ちゃんとした奴に直す import random render_params['speed'] = random.randrange(5, 50) / 10.0 render_params['address'] = u"福井県鯖江市新横江" return render_to_response('kokodoya/result.html', render_params)
def create_release(request): form = ReleaseForm() if form.validate(request.form): form.save() return redirect(url_for('vault/list_releases')) return render_to_response('vault/new_release.html', {'form': form.as_widget()})
def get(self): in_xls = self.request.session['in_grid'] base_sheet = in_xls.sheet_by_index(0) tenrows = [ base_sheet.row_values(i) for i in range(10) ] return render_to_response('client/gridbase_params.html', { 'in_grid': tenrows })
def preview_newsletter(request, key): newsletter = Newsletter.get(key) gifts = [] if newsletter.gifts: gifts_split = newsletter.gifts.split(",") for gift in gifts_split: try: gift = gift.strip() obj = Gift.all().filter("uid =", gift).get() if obj: gifts.append(obj) except Exception: pass managers = [] users = UserProfile.all().filter("is_send_newsletter =", True).filter("email !=", None) if newsletter.type != 999: users = users.filter("newsletter_type =", newsletter.type) files = [] for file_key in newsletter.n_price_list: file_ = File.get(file_key) if file_: files.append(file_) return render_to_response( "postman/admin/newsletters/preview.html", {"newsletter": newsletter, "gifts": gifts, "key": key, "files": files, "managers": managers, "users": users}, )
def post(self): logging.debug('XLSFileUpload.post') xls_upload_form = XLSFileUploadForm() if xls_upload_form.validate(self.request.form, self.request.files): logging.debug('process data here') in_data = [ ] for i in self.request.files: self.request.files[i].stream.seek(0) in_file = self.request.files[i].stream.getvalue() in_xls = open_workbook(file_contents=in_file) ## base_sheet = in_xls.sheet_by_index(0) ## tenrows = [ base_sheet.row_values(i) for i in range(10) ] request.session['in_xls'] = in_xls logging.debug('data processed') return redirect('/client/title_list_grid') ## return render_to_response('client/one_message.html', { 'message': "/thanks/" }) ## return redirect('client/process_spreadsheet.html', { 'message': 'I care', 'sheet': in_xls}) else: logging.debug('form did not validate') return render_to_response('client/one_message.html', { 'message': "oopsie!" })
def index(request): form = DocForm() return render_to_response('welcome/index.html', { 'form': form.as_widget(), })
def site_edit(request): form = SettingForm() if request.method == "POST" and (request.form.has_key('delete') and request.form['delete'] == 'on'): if request.form['edit']: site = Sites.get(request.form['site']) if site.user != request.user: redirect(url_for('admin/settings')) #FIXME error site.delete() return redirect(url_for('admin/settings')) if request.method == "POST" and form.validate(request.form): if form.data['edit']: site = Sites.get(form.data['site']) if site.user != request.user: redirect(url_for('admin/settings')) #FIXME error else: site = Sites(activate_code=_activate_code(), user=request.user) site.url = db.Link(form['url']) site.put() return redirect(url_for('admin/settings')) if request.method == "GET": if request.args.has_key('site') and request.args['site']: site = Sites.get(request.args['site']) if site.user == request.user: form.data['url'] = site.url form.data['edit'] = '1' form.data['site'] = request.args['site'] form.data['activate_code'] = site.activate_code form.delete.widget.value = u'False' return render_to_response('admin/site_edit.html', {'form': form.as_widget()})
def list(request, ordering='popularne'): if ordering not in ORDERINGS.keys(): return NotFound() prev, recipes, next = PagerQuery(models.Recipe) \ .filter('rec_vis =', VISIBILITY[2]) \ .filter('disabled =', False) \ .order(ORDERINGS[ordering]) \ .fetch(settings.PAGE_SIZE, request.args.get('b', None)) # Get authors, TODO: OPTIMIZE authors = PMMUser.get([recipe.parent_key() for recipe in recipes]) for i, recipe in enumerate(recipes): if recipe and authors[i]: recipe.author = authors[i] if request.is_xhr: template = 'przepisy/includes/list.html' else: template = 'przepisy/list.html' return render_to_response(template, { 'recipes': recipes, 'prev': prev, 'ordering': ordering, 'next': next, })
def mass_delete(request): import bulkupdate model_list = get_all_models() kinds = [model.kind() for model in model_list] result = None nuke_all_kinds = request.form.get('nuke_all_kinds') if not nuke_all_kinds: kind_string = request.form.get('kind') kind_class = None for model in model_list: if model.kind() == kind_string: kind_class = model if kind_class: job = bulkupdate.BulkDelete(kind_class.all(keys_only=True)) job.start() result = "Deleting all <b>" + kind_string + "</b> entities..." else: result = "Module does not have the class '%s'." % kind_string else: for kind_class in model_list: job = bulkupdate.BulkDelete(kind_class.all(keys_only=True)) job.start() result = "Deleting entities of all kinds!" return render_to_response('nuke/result.html', {'result': result})
def sync_gift_task(request, key): gift = Gift.get(key) if not gift: return render_to_response('empty.html') url = 'http://www.5studio.ru/api/v1/get/gift.json?&uid=%s' \ % gift.uid_5studio result = urlfetch.fetch(url) if result.status_code == 200: j = simplejson.loads(result.content) gift.leftovers = j.get('leftovers', 0) gift.category = get_category(j) gift.subcategory = get_subcategory(j, gift.category) gift.put() else: gift.delete() return render_to_response('empty.html')
def login_box(request): from kay.auth import login next = unquote_plus(request.values.get("next")) owned_domain_hack = request.values.get("owned_domain_hack") message = "" form = LoginBoxForm() if request.method == "POST": if form.validate(request.form): result = login(request, user_name=form.data['user_name'], password=form.data['password']) if result: if owned_domain_hack == 'True': original_host_url = unquote_plus( request.values.get("original_host_url")) url = original_host_url[:-1] + url_for("auth/post_session") url += '?' + url_encode({ 'session_id': result.key().name(), 'next': next }) return redirect(url) else: return redirect(next) else: message = _("Failed to login.") return render_to_response("auth/loginform.html", { "form": form.as_widget(), "message": message })
def skill_edit(request): u"""スキルを登録・編集する管理画面 """ # skill = Skill.all().filter('key =', request.form['key']).fetch(1) logging.debug(inspect.currentframe().f_lineno) logging.debug(request.form) form = SkillForm() if request.method == "POST": logging.debug(inspect.currentframe().f_lineno) logging.debug(request.form) if request.form['name']: logging.debug(inspect.currentframe().f_lineno) logging.debug(request.form) skill = Skill.get_skill(request.form['name']) if not skill: skill = Skill.add_skill( request.form['name'], int(request.form['timing']), int(request.form['typ']), request.form['param'], int(request.form['value'])) logging.debug(inspect.currentframe().f_lineno) logging.debug(request.form['timing']) skill.timing = int(request.form['timing']) skill.typ = int(request.form['typ']) skill.param = request.form['param'] skill.value = int(request.form['value']) # skill.job = request.form['job'] skill.put() return redirect(url_for('htbrpg2kay/index')) return render_to_response('htbrpg2kay/skill_edit.html', {'form': form.as_widget()})
def refused(request): requests = RegistrationRequest.query(RegistrationRequest.status == REQUEST_STATUS['refused']) return render_to_response('reguest/admins/index.html', { 'requests': requests, 'status': REQUEST_STATUS['refused'], 'statuses': REQUEST_STATUS })
def request_reset_password(request): form = ResetPasswordRequestForm() message = "" if request.method == "POST" and form.validate(request.form): try: auth_model_class = import_string(settings.AUTH_USER_MODEL) except (ImportError, AttributeError), e: raise ImproperlyConfigured, 'Failed to import %s: "%s".' % (settings.AUTH_USER_MODEL, e) user = auth_model_class.get_by_user_name(form["user_name"]) if user is None: return render_to_response("auth/no_such_user.html", {"user_name": form["user_name"]}) else: temporary_session = TemporarySession.get_new_session( user, additional_tq_url="_internal/send_reset_password_instruction", tq_kwargs={"user_key": user.key()} ) return render_to_response("auth/reset_password_finish.html")
def get(self, activation_key): account = RegistrationProfile.activate_user(activation_key) context = { 'account': account, 'expiration_duration': settings.ACCOUNT_ACTIVATION_DURATION } for key, value in self.extra_context.items(): context[key] = callable(value) and value() or value return render_to_response(self.template_name, context)
def site_view(request): if _invalid_configuration(request): return _redirect_configuration(request) url = request.args['url'] if request.args.has_key('url') else None if not url: return redirect(url_for('admin/')) from xml.sax.saxutils import * html = urllib2.urlopen(url).read() html = unicode(html, 'utf8', 'ignore') return render_to_response('admin/site_view.html', {"html": html})
def group_detail(request): if request.method == "GET": key_name = request.values.get("key_name", None) group = Group.get_by_key_name(key_name) if not group.is_owned_by(request.user): raise Forbidden() return render_to_response("groupy/group_detail.html", { "message": _("The details of the group"), "group": group })
def index(request): groups = Group.all().filter("owner =", request.user).fetch(100) if len(groups) == 0: message = _("You don't own any group yet.") else: message = _("The groups you own.") return render_to_response('groupy/index.html', { 'message': message, 'groups': groups })
def request_reset_password(request): form = ResetPasswordRequestForm() message = "" if request.method == 'POST' and form.validate(request.form): try: auth_model_class = import_string(settings.AUTH_USER_MODEL) except (ImportError, AttributeError), e: raise ImproperlyConfigured, \ 'Failed to import %s: "%s".' % (settings.AUTH_USER_MODEL, e) user = auth_model_class.get_by_user_name(form['user_name']) if user is None: return render_to_response("auth/no_such_user.html", {"user_name": form["user_name"]}) else: temporary_session = TemporarySession.get_new_session( user, additional_tq_url='_internal/send_reset_password_instruction', tq_kwargs={"user_key": user.key()}) return render_to_response("auth/reset_password_finish.html")
def select_service(request, targets): targets = targets.split('|') next_url = unquote_plus(request.args.get('next_url')) urls = [] for target in targets: verbose_name = 'Sign in with %s' % get_service_verbose_name(target) url = create_gaema_login_url(target, next_url) urls.append((target, verbose_name, url)) if len(targets) == 1: return redirect(url) return render_to_response('gaema/select_service.html', {'urls': urls})
def main_handler(request): model_list = get_all_models() all_kinds = get_schema_kinds() present_kinds = [] for kind_class in model_list: first_entity = kind_class.all(keys_only=True).get() if first_entity: present_kinds.append(kind_class.kind()) return render_to_response('nuke/main.html', { 'kinds': all_kinds, 'present_kinds': present_kinds })
def reset_password(request, session_key): form = ResetPasswordForm() if request.method == 'GET': try: temporary_session = TemporarySession.get(session_key) except Exception: # BadKeyError ... etc temporary_session = None if temporary_session is None: return Forbidden("Temporary Session might be expired.") # TODO: acquire new temporary session new_session = TemporarySession.get_new_session(temporary_session.user) temporary_session.delete() form.data['temp_session'] = str(new_session.key()) elif request.method == 'POST' and form.validate(request.form): new_session = TemporarySession.get(form['temp_session']) user = new_session.user user.set_password(form['new_password']) new_session.delete() return render_to_response("auth/reset_password_success.html") return render_to_response("auth/reset_password.html", {"form": form.as_widget()})
def thermographies(request): if _invalid_configuration(request): return _redirect_configuration(request) site = None _thermographies = None if request.args.has_key('site'): site = Sites.get(request.args['site']) if site.user != request.user: return _redirect_configuration(request) from thermography.models import ThermographyPointDaily _thermographies = ThermographyPointDaily.all().filter( 'site =', site).order('-date').fetch(1000) return render_to_response('admin/thermographies.html', { "site": site, "thermographies": _thermographies })
def edit_group(request): error_message = None if request.method == "GET": key_name = request.values.get("key_name", None) group = Group.get_by_key_name(key_name) if not group.is_owned_by(request.user): raise Forbidden() form = get_edit_form(group) elif request.method == "POST": key_name = request.form.get("hidden_key_name", None) group = Group.get_by_key_name(key_name) if not group.is_owned_by(request.user): raise Forbidden() form = get_edit_form(group) if form.validate(request.form): if str(group.updated) == form["hidden_updated"]: group.language = form["language"] group.description = form["description"] group.members = form["members"] group.applications = form["applications"] group.banned_addresses = form["banned_addresses"] group.put() return redirect( url_for('groupy/group_detail', key_name=group.key().name())) else: # re-init because of race condition form = get_edit_form(group) error_message = _("Sorry, It can not be saved because " "a race condition happened. " "Please try again from the start.") else: pass return render_to_response( "groupy/edit_group.html", { "message": _("Editing a group"), "form": form.as_widget(), "error_message": error_message, "group": group })
def report_admin(request): from kay.utils import render_to_response from kay.utils.paginator import Paginator version_filter = request.args.get('versions', 'all') report_date = request.args.get('date', None) if report_date: yesterday = datetime.date(*[int(x) for x in report_date.split('-')]) else: yesterday = None app_id = os.environ['APPLICATION_ID'] version = os.environ['CURRENT_VERSION_ID'] major_version, minor_version = version.rsplit('.', 1) minor_version = int(minor_version) query_args = { 'major_version': major_version, } if yesterday: query_args['query_date'] = yesterday try: exceptions = GetQuery(order='-date', **query_args) paginator = Paginator(exceptions, 10) page = paginator.page(request.args.get('page', 1)) except db.NeedIndexError: exceptions = GetQuery(**query_args) paginator = Paginator(exceptions, 10) page = paginator.page(request.args.get('page', 1)) return render_to_response("ereporter/admin.html", { 'version_filter': version_filter, 'app_id': app_id, 'major_version': major_version, 'exceptions': page.object_list, 'paginator': paginator, 'page': page, })
def create_or_update(self, request, key=None): from google.appengine.api.datastore_errors import BadKeyError self._import_model_if_not() if key: try: entity = db.get(key) except BadKeyError: entity = None if entity is None: raise NotFound("Specified %s not found." % self.model_name) form_class = self.get_form(request, OP_UPDATE) form = form_class(instance=entity) title = self.messages['title_update'] % self.model_name self.check_authority(request, OP_UPDATE, entity) else: form_class = self.get_form(request, OP_CREATE) form = form_class() title = self.messages['title_create'] % self.model_name self.check_authority(request, OP_CREATE) if request.method == 'POST': if form.validate(request.form, request.files): if key: additional_context = self.get_additional_context_on_update( request, form) message = self.messages['result_update'] else: additional_context = self.get_additional_context_on_create( request, form) message = self.messages['result_create'] new_entity = form.save(**additional_context) set_flash(message) return redirect(self.get_list_url()) return render_to_response(self.get_template(request, OP_UPDATE), { 'form': form.as_widget(), 'title': title }, processors=(self.url_processor, ))
def thermography(request): if _invalid_configuration(request): return _redirect_configuration(request) if not request.args.has_key('url') or not request.args.has_key('date'): #FIXME error pass _thermography = _get_thermography(request.args['url'], request.args['date']) logging.info(_thermography) if not _thermography or _thermography.site.user != request.user: return _redirect_configuration(request) points_json = _thermography.data max_point = _thermography.max_point import time return render_to_response( 'admin/thermography.html', { "time": time.time(), "url": _thermography.url, "points": points_json, "max_point": max_point })
def list(self, request, cursor=None): # TODO: bi-directional pagination instead of one way ticket forward self._import_model_if_not() self.check_authority(request, OP_LIST) q = self.get_query(request) if cursor: q.with_cursor(cursor) entities = q.fetch(self.entities_per_page) if entities: next_cursor = q.cursor() q2 = self.get_query(request) q2.with_cursor(next_cursor) if q2.get() is None: next_cursor = None else: next_cursor = None return render_to_response(self.get_template(request, OP_LIST), { 'model': self.model_name, 'entities': entities, 'cursor': next_cursor, 'message': get_flash(), }, processors=(self.url_processor, ))
def process_request(self, request): """Determines the subdomain of the request.""" # The 'subdomain' query parameter always overrides the hostname. try: if request.form['subdomain']: request.subdomain = request.form['subdomain'] return None if request.args['subdomain']: request.subdomain = request.args['subdomain'] return None except KeyError: pass levels = request.headers['Host'].split('.') if levels[-2:] == ['appspot', 'com'] and len(levels) >= 4: # foo.person-finder.appspot.com -> subdomain 'foo' # bar.kpy.latest.person-finder.appspot.com -> subdomain 'bar' logging.info(levels[0]) request.subdomain = levels[0] return None return render_to_response('sammy/basecamp.html', {'subdomains': Subdomain.all()})
def add_group(request): form = AddGroupForm() if request.method == "POST": if form.validate(request.form): form['name'] group = Group.get_or_insert( key_name=Group.get_key_name(form['name']), name=form['name'], language=form['language'], description=unicode(form['description']), owner=request.user, members=form['members']) if group.owner.key() != request.user.key(): form.errors.append("Group creation failed.") else: return redirect( url_for('groupy/group_detail', key_name=group.key().name())) else: pass return render_to_response('groupy/edit_group.html', { 'form': form.as_widget(), 'message': _("Adding a new group") })
def game(request, game_id): game = get_by_key_name_or_404(Game, game_id) return render_to_response('webigo/game.html', {'game':game})
def index(request): games = Game.all().order('-created_at') return render_to_response('webigo/index.html', {'games':games})
def crossdomain(request): return render_to_response('study/crossdomain.xml')
def get(self): c = {'form': self.form.as_widget()} c.update(self.extra_context) return render_to_response(self.template_name, c)
def index(request): return render_to_response('study/index.html')
def registration_complete(request): return render_to_response('registration/registration_complete.html')
def index(request): if _invalid_configuration(request): return _redirect_configuration(request) return render_to_response('admin/index.html', {'message': 'Hello'})
def settings(request): return render_to_response('admin/settings.html')
def index(request): return render_to_response('main/index.html', {'message': 'Hello'})
app_id = os.environ['APPLICATION_ID'] version = os.environ['CURRENT_VERSION_ID'] major_version, minor_version = version.rsplit('.', 1) minor_version = int(minor_version) query_args = { 'major_version': major_version, } if yesterday: query_args['query_date'] = yesterday try: exceptions = GetQuery(order='-date', **query_args) paginator = Paginator(exceptions, 10) page = paginator.page(request.args.get('page', 1)) except db.NeedIndexError, e: logging.warn(e) exceptions = GetQuery(**query_args) paginator = Paginator(exceptions, 10) page = paginator.page(request.args.get('page', 1)) return render_to_response( "ereporter/admin.html", { 'version_filter': version_filter, 'app_id': app_id, 'major_version': major_version, 'exceptions': page.object_list, 'paginator': paginator, 'page': page, })