def release(request): """ release page and release handle """ #TODO handle the request from the client if request.user.is_authenticated(): if request.method == 'GET': return RTR("release.html", {}, context_instance = RequestContext(request)) else: product_params = { 'owner' : request.user, 'productname' : request.POST.get('productname', ''), 'broadtype' : request.POST.get('broadtype', ''), 'image' : request.FILES.get('image'), 'subtype' : request.POST.get('subtype', ''), 'belongcampus' : request.POST.get('belongcampus', ''), 'tradetype' : request.POST.get('tradetype', ''), 'purity' : request.POST.get('purity', ''), 'price' : request.POST.get('price', ''), 'tradetitle' : request.POST.get('productname', ''), 'tradedetail' : request.POST.get('tradedetail', ''), 'releasetime' : datetime.datetime.now(), } print product_params ProductToSell.create_product_to_sell(product_params) return HttpResponse("add_product_to_sell.html!!!") else: return RTR("login.html", {'error' : '璇峰厛鐧诲綍~'})
def home_release(request, nid): """ home page for user, user authentication needed """ if not request.user.is_authenticated: # need login return HttpResponseRedirect('/register') else: user = Account.by_nid(nid) is_self = True if nid == request.user.nid else False cdic = {'user' : user, 'is_self' : is_self} products = ProductToSell.latest_product_to_show() cdic['products'] = reversed(products) return RTR('user.html', cdic)
def market(request): """ market page """ #TODO user authentication #TODO get the products from db t = request.GET.get('t', 'a') p = request.GET.get('p', '1') cdic = {'t' : t} if request.user.is_authenticated(): cdic['is_self'] = True cdic['user'] = request.user else: cdic['is_self'] = False products, page = ProductToSell.by_type(t, int(p)) cdic['products'] = products cdic['bef_page'] = page - 1 if page > 0 else 1 cdic['t'] = t cdic['page'] = page cdic['nxt_page'] = page + 1 return RTR('market.html', cdic, context_instance = RequestContext(request))