コード例 #1
0
ファイル: views.py プロジェクト: nims11/Foo-Barketplace
def seal(request, item_id, curr_user):
	"""
	When buyer seals the deal
	status = 0 -> 1
	"""
	try:
		item = items.objects.get(id=item_id, is_expired=False, is_sold=False)
	except items.DoesNotExist:
		return render(request, 'error.html', {'error': 'Item Not Found'})

	if request.method == 'POST':
		form = DealForm(request.POST)
		if form.is_valid() and form.cleaned_data.get('deal', False):
			# If sealed by buyer
			if item.user != curr_user.user_obj:
				try:
					comm = Comm.objects.get(buyer=curr_user.user_obj, item=item)
				except Comm.DoesNotExist:
					comm = Comm(buyer=curr_user.user_obj, item=item)
					comm.save()
				if comm.status == 0:
					comm.status = 1
					comm.save()
				else:
					return render(request, 'error.html', {'error': 'You can\'t seal the deal now!'})
				return HttpResponseRedirect(item.get_comm_url())
			else:
				# Current user is the seller
				return render(request, 'error.html', {'error': 'You can\'t purchase your own item!!'})
	return HttpResponseRedirect(item.get_comm_url())
コード例 #2
0
ファイル: views.py プロジェクト: nims11/Foo-Barketplace
def seller_seal(request, item_id, buyer_nick, curr_user):
	try:
		item = items.objects.get(id=item_id, is_expired=False, is_sold=False)
	except items.DoesNotExist:
		return render(request, 'error.html', {'error': 'Item Not Found'})

	try:
		tar_user = user_profile.objects.get(nick=buyer_nick)
	except user_profile.DoesNotExist:
		return render(request, 'error.html', {'error': 'User Not Found'})

	if request.method == 'POST':
		form = DealForm(request.POST)
		if form.is_valid() and form.cleaned_data.get('deal', False):
			# If sealed by buyer
			if item.user != curr_user.user_obj:
				return render(request, 'error.html', {'error': 'Not your item!'})
			else:
				# Current user is the seller
				try:
					comm = Comm.objects.get(buyer=tar_user, item=item)
				except Comm.DoesNotExist:
					return render(request, 'error.html', {'error': 'Invalid Action!!'})
				if comm.status == 1:
					item.is_sold = True
					item.buyer = tar_user
					item.save()
					comm.status = 2
					comm.save()
				else:
					return render(request, 'error.html', {'error': 'Invalid Action!!'})

	return HttpResponseRedirect(item.get_comm_url())
コード例 #3
0
ファイル: server.py プロジェクト: ShaolinZhang/creo
def new_deal():
    context['page_name'] = 'New Deal'
    form = DealForm()
    if form.validate_on_submit():
        try:
            g.conn.execute(
                'INSERT INTO deal(addedBy, projectName, \
                projectScore, teamScore, projectStatus, industry, memo) \
                VALUES (%s, %s, %s, %s, %s, %s, %s)', session['user'],
                form.projectName.data, form.projectScore.data,
                form.teamScore.data, form.projectStatus.data,
                form.industry.data, form.memo.data)
            return redirect('/success')
        except Exception:
            return render_template('new_deal.html', form=form, **context)
    return render_template('new_deal.html', form=form, **context)
コード例 #4
0
  def get(self, request, *args, **kwargs):
      chapter = None
      if 'deal' in request.GET:
          if request.GET['deal'] == 'new':
              form = DealForm()
              deal = None
          else: 
              deal = Deal.objects.get(pk = request.GET['deal'])
              form = DealForm( instance = deal )
          return self.render_to_response( {'form': form, 'deal':deal} )
      
      if 'chapter' in request.GET:
          chapter = Chapter.objects.get(pk = request.GET['chapter'])
          deals = chapter.deals()
 
      elif 'leadbuyer' in request.GET:
          leadbuyer = LeadBuyer.objects.get(pk = request.GET['leadbuyer'])
          deals = leadbuyer.deals()
                
      return self.render_to_response( {'deals':deals, 'chapter':chapter} )
コード例 #5
0
ファイル: views.py プロジェクト: meriloi/dealy
def create_deal(request, venue_id):
    v = Venue.objects.get(id=venue_id)

    if request.POST:
        f = DealForm(request.POST)
        if f.is_valid():
            d = f.save(commit=False)
            d.venue = v
            d.save()

            return HttpResponseRedirect('/')
    else:
        f = DealForm()

    args = {}
    args.update(csrf(request))

    args['venue'] = v
    args['form'] = f

    return render_to_response('create_deal.html', args)
コード例 #6
0
def my_account():
    if "auth_field" in session:
        dbcursor.execute(
            "SELECT amount FROM stock_tracker WHERE user_id = %s AND symbol = %s",
            (session['_id'], 'money'))
        dbres = dbcursor.fetchone()
        form = DealForm(user_id=session['_id'])
        if form.validate_on_submit():
            place_deal(request.form, session["_id"])
            dbcursor.execute(
                "UPDATE stock_tracker SET amount = amount - %s WHERE symbol = %s AND user_id = %s",
                (request.form['number'], request.form['symbol'],
                 session['_id']))
            db.commit()
            flash('Deal placed successfully', 'success')
            return render_template('my.account.html',
                                   auth_name=session["auth_field"],
                                   funds=dbres[0],
                                   form=form)
        else:
            return render_template('my.account.html',
                                   auth_name=session["auth_field"],
                                   funds=dbres[0],
                                   form=form)