Esempio n. 1
0
def register(request, type=""):
    user = request.user

    account_type = {"buyer": "Buyer Account", "publisher": "Publisher Account"}

    if request.method == "POST":
        form = UserForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data.get("username")
            password = form.cleaned_data.get("password1")
            email = form.cleaned_data.get("email")

            newuser = User.objects.create_user(username=username, email=email, password=password)
            newuser.save()

            if type == "publisher":
                g = Group.objects.get(name="publisher")
                newuser.groups.add(g)
            else:
                g = Group.objects.get(name="buyer")
                newuser.groups.add(g)

                # Create the profile
            profile = UserProfile(user=newuser, balance=0)
            profile.save()

            return HttpResponseRedirect("/" + type + "/")
    else:
        form = UserForm()

    return render_to_response("accounts/register.html", {"form": form, "account_type": account_type[type]})
Esempio n. 2
0
def edit_profile_publisher(request):
	user = request.user
	
	try:
		profile = user.get_profile()
	except UserProfile.DoesNotExist:
		profile = UserProfile(user=user,  balance=0)
		profile.save()
	
	if request.method == "POST":
		form = EditPublisherForm(data=request.POST, instance=profile)
		
		if form.is_valid():
			form.save()
			return HttpResponseRedirect('/publisher/edit/')
	else:
		form = EditPublisherForm(instance=profile)
		
	return render_to_response('profiles/seller/edit_profile.html', {'profile':form}, context_instance=RequestContext(request))
Esempio n. 3
0
def edit_profile_publisher(request):
    user = request.user

    try:
        profile = user.get_profile()
    except UserProfile.DoesNotExist:
        profile = UserProfile(user=user, balance=0)
        profile.save()

    if request.method == "POST":
        form = EditPublisherForm(data=request.POST, instance=profile)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/publisher/edit/")
    else:
        form = EditPublisherForm(instance=profile)

    return render_to_response(
        "profiles/seller/edit_profile.html", {"profile": form}, context_instance=RequestContext(request)
    )
Esempio n. 4
0
def register(request, type=''):
    user = request.user

    account_type = {'buyer': 'Buyer Account', 'publisher': 'Publisher Account'}

    if request.method == 'POST':
        form = UserForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            email = form.cleaned_data.get('email')

            newuser = User.objects.create_user(username=username,
                                               email=email,
                                               password=password)
            newuser.save()

            if type == 'publisher':
                g = Group.objects.get(name='publisher')
                newuser.groups.add(g)
            else:
                g = Group.objects.get(name='buyer')
                newuser.groups.add(g)

            # Create the profile
            profile = UserProfile(user=newuser, balance=0)
            profile.save()

            return HttpResponseRedirect('/' + type + '/')
    else:
        form = UserForm()

    return render_to_response('accounts/register.html', {
        'form': form,
        'account_type': account_type[type]
    })
Esempio n. 5
0
    def clean(self):
        q = self.cleaned_data.get('quantity')
        p = self.cleaned_data.get('price')

        if (q > 0 and p > 0):
            total = q * p
            try:
                buyer_profile = self.instance.user.get_profile()
            except UserProfile.DoesNotExist:
                buyer_profile = UserProfile(user=self.instance.user, balance=0)
                buyer_profile.save()

            if buyer_profile.balance < total:
                error = u'Not Enough Funds. Please add more funds to your account. You have %d dollars.' % buyer_profile.balance
                raise forms.ValidationError(error)
            else:
                buyer_profile.balance = buyer_profile.balance - total
                buyer_profile.save()

        return self.cleaned_data
Esempio n. 6
0
	def clean(self):
		q = self.cleaned_data.get('quantity')
		p = self.cleaned_data.get('price')
		
		if(q > 0 and p > 0):
			total = q  * p
			try:
				buyer_profile = self.instance.user.get_profile()
			except UserProfile.DoesNotExist:
				buyer_profile = UserProfile(user=self.instance.user,  balance=0)
				buyer_profile.save()
				
			if buyer_profile.balance < total:
				error = u'Not Enough Funds. Please add more funds to your account. You have %d dollars.' % buyer_profile.balance
				raise forms.ValidationError(error)
			else:
				buyer_profile.balance = buyer_profile.balance - total
				buyer_profile.save()

		return self.cleaned_data
Esempio n. 7
0
def homebiz_three(request):
	try:
		lead = BaseLead.objects.get(leadid=request.GET['leadid'])
	except BaseLead.DoesNotExist:
		return HttpResponse("Lead id does not exist.")
	
	lead.rent_own = request.GET['rentown']
	lead.reach_time = request.GET['reachtime']
	lead.address = request.GET['address']
	lead.city = request.GET['city']
	
	lead.save()
	
	tracker = lead.trackerlog.tracker
	campaign = tracker.campaign
	
	lead.trackerlog.leads_total = lead.trackerlog.leads_total + 1
	lead.trackerlog.save()
	
	campaign.leads_total = campaign.leads_total + 1
	campaign.save()
	
	try:
		buying = Buying.objects.all().filter(type__iexact='homebiz').filter(Q(filter_state__iexact=lead.state) | Q(filter_state__iexact='*') | Q(filter_zip__iexact=lead.zip)).order_by('-price')[0:1].get()
	except Buying.DoesNotExist:
		return HttpResponse("No buyers found.")
		
	if buying is not None:
		buying.quantity = buying.quantity-1
		buying.save()	
		
		try:
			buyer_profile = buying.user.get_profile()
		except UserProfile.DoesNotExist:
			buyer_profile = UserProfile(user=buying.user,  balance=0)
			buyer_profile.save()
			
		publisher_price = buying.price * decimal.Decimal(".8")
		our_price = buying.price * decimal.Decimal(".2")
		
		if buyer_profile.balance < buying.price:
			return HttpResponse("Could not commplete transaction. Not enough balance.")
		else:
			buyer_profile.balance -= buying.price
			buyer_profile.save()
			
			try:
				publisher_profile = campaign.user.get_profile()
			except UserProfile.DoesNotExist:
				publisher_profile = UserProfile(user=campaign.user, balance=0)
				publisher_profile.save()
				
			publisher_profile.balance += publisher_price
			publisher_profile.save()
			
			lead.trackerlog.leads_sold +=  1
			lead.trackerlog.sold_total += publisher_price
			lead.trackerlog.save()
		
			campaign.leads_sold += 1
			campaign.save()
			
			lead.sold_at = publisher_price
			lead.save()
			
			publisher_log = UserLog(user=campaign.user, amount=publisher_price)
			publisher_log.save()

			buyer_log = UserLog(user=buying.user, amount=-(publisher_price+our_price))
			buyer_log.save()
			
			buyer_lead_log = LeadLog(order=buying, lead=lead, date=datetime.today())
			buyer_lead_log.save()
			
			our_log = UserLog(user=User.objects.get(pk=1), amount=our_price)
			our_log.save()
			
			our_log.user.get_profile().balance += our_price
			our_log.user.get_profile().save()
			
	return_dict = {
					'location': buying.location,
					'leadid': request.GET['leadid'],
				}
	
	json = simplejson.dumps(return_dict)
	
	return HttpResponse(request.GET['callback']+'('+json+')')
Esempio n. 8
0
def designlead_final(request):
	try:
		tracker_log = TrackerLog.objects.get(date=datetime.today(), tracker__name=request.GET.get('tracker'))
	except TrackerLog.DoesNotExist:
		return HttpResponse("Invalid tracker.")
	
	phone = request.GET.get('phone')
	description = request.GET.get('description')
	budget = request.GET.get('budget')
	first_name = request.GET.get('first_name')
	last_name = request.GET.get('last_name')
	
	lead = DesignLead(leadid=md5.new(str(random.random())).hexdigest(), trackerlog=tracker_log, phone=phone,
				last_name=last_name, first_name=first_name, budget=budget, description=description, sold_at=0)
	lead.save()
	
	tracker = lead.trackerlog.tracker
	campaign = tracker.campaign
	
	lead.trackerlog.leads_total = lead.trackerlog.leads_total + 1
	lead.trackerlog.save()
	
	campaign.leads_total = campaign.leads_total + 1
	campaign.save()
	
	try:
		buying = Buying.objects.filter(type__id='1').order_by('-price')[0:1].get()
	except Buying.DoesNotExist:
		return HttpResponse("No Buyers")
		
	if buying is not None:
		buying.quantity = buying.quantity-1
		buying.save()	
		
		try:
			buyer_profile = buying.user.get_profile()
		except UserProfile.DoesNotExist:
			buyer_profile = UserProfile(user=buying.user,  balance=0)
			buyer_profile.save()
			
		publisher_price = buying.price * decimal.Decimal(".8")
		our_price = buying.price * decimal.Decimal(".2")
		
		if buyer_profile.balance < buying.price:
			return HttpResponse("Could not commplete transaction. Not enough balance.")
		else:
			buyer_profile.balance -= buying.price
			buyer_profile.save()
			
			try:
				publisher_profile = campaign.user.get_profile()
			except UserProfile.DoesNotExist:
				publisher_profile = UserProfile(user=campaign.user, balance=0)
				publisher_profile.save()
				
			publisher_profile.balance += publisher_price
			publisher_profile.save()
			
			lead.trackerlog.leads_sold +=  1
			lead.trackerlog.sold_total += publisher_price
			lead.trackerlog.save()
		
			campaign.leads_sold += 1
			campaign.save()
			
			lead.sold_at = publisher_price
			lead.save()
			
			publisher_log = UserLog(user=campaign.user, amount=publisher_price)
			publisher_log.save()

			buyer_log = UserLog(user=buying.user, amount=-(publisher_price+our_price))
			buyer_log.save()
			
			buyer_lead_log = LeadLog(order=buying, lead=lead, date=datetime.today())
			buyer_lead_log.save()
			
			our_log = UserLog(user=User.objects.get(pk=1), amount=our_price)
			our_log.save()
			
			our_log.user.get_profile().balance += our_price
			our_log.user.get_profile().save()
		
	return_dict = {
					'location': buying.location,
					'leadid': lead.leadid,
				}
	
	json = simplejson.dumps(return_dict)
	
	return HttpResponse(request.GET['callback']+'('+json+')', mimetype='application/json'))