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 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 r_info_add_image(request, uid): if request.method == 'POST': news = RetailInfo.get_by_id(uid) if not news: return render_json_response({'api':{'success':False}}) upload_files = get_uploads(request, 'file') if len(upload_files): blob_info = upload_files[0] if blob_info.size: image = RetailInfoImage.create(blob_info.key()) news = RetailInfo.get_by_id(uid) images = RetailInfoImage.query(RetailInfoImage.news_ref == news.key) if not images.count: image.is_master = True image.news_ref = news.key image.cached_url = image.get_cached_url() image.put() else: blob_info.delete() return r_info_images(request, uid) return render_to_response('empty.html')
def r_info_show(request, key_id): r_info_obj = RetailInfo.get_by_id(key_id) if not r_info_obj: return redirect('page/r_info') return render_to_response('page/r_info_show.html', {'m_r_info': 'active', 'r_info': r_info_obj})
def r_info(request): r_info_objs = RetailInfo.query(RetailInfo.is_display == True) return render_to_response('page/r_info_index.html', {'m_r_info': 'active', 'r_info': r_info_objs})
def r_info_delete(request, uid): news = RetailInfo.get_by_id(uid) if news: news.key.delete() return redirect(url_for('page/admins/r_info/index'))
def r_info_add(request): r_info = RetailInfo() r_info.put() form = NewsForm(action=url_for('page/admins/r_info/edit', uid=r_info.key.id())) return render_to_response('page/admins/r_info/edit.html', {'form': form.as_widget(), 'r_info': r_info})
def r_info_index(request): r_info = RetailInfo.query().order(-RetailInfo.add_time) return render_to_response('page/admins/r_info/index.html', {'r_info': r_info})