Exemplo n.º 1
0
def auction_update(request, item_id, template_name="auction/updateauction.html"):
    '''
        This is used to update new items(Auctions). The currently updated items are automatically displayed on the latest item and can be searchable. Email is sent to the person who updated the item once the item is created. The item can only be updated by the creator of the item. The other users won't even see the link to update an item that they have not created.
    '''
    itemid = item_id
    item = get_object_or_404(Item,  pk=itemid )
    page_title='Auction Update form'
    if request.method == 'POST' and request.user.is_authenticated():
        postdata = request.POST.copy()
        form = AuctionForm(postdata, request.FILES)
        user_profile = get_object_or_404(CustomUser, pk=request.user.id)
        if form.is_valid() and item.owner == user_profile:
            human = True
            name = postdata.get('name','')
            description = postdata.get('description','')
            minimum_price = postdata.get('minimum_price',0.01)
            image = request.FILES['image']

            my_list = []
            if item:
				#update
                if name <> '':
                    item.name = name
                    my_list.append("name")

                if description <> '':
                    item.description = description
                    my_list.append("description")

                if minimum_price <> 0.01:
                    item.minimum_price = minimum_price
                    my_list.append("minimum price")

                if image:
                    file_content = ContentFile(request.FILES['image'].read())
                    item.image.save(request.FILES['image'].name, file_content, save=False)
                    item.save()
                    my_list.append("image")

            item.save()

            t = loader.get_template('registration/updateAuction.txt')
            c = Context({
				'firstname': 		user_profile.first_name,
				'lastname': 		user_profile.last_name,
				'site_name': 		'YAAS Auction Site',
				'admin': 			'Kenneth Odoh',
				'my_list':		    my_list,
			})

            email_subject = 'Your have updated your auction'
            send_mail(email_subject, t.render(c), '*****@*****.**', [item.owner.email], fail_silently=False) 
            return HttpResponseRedirect(reverse('showCurrentUpdatedItem', args=(item.id,)))
    else:
        form = AuctionForm()			
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
Exemplo n.º 2
0
def auction_create(request, template_name="auction/createauction.html"):
    '''
        This is used to create new items(Auctions). The created items are automatically displayed on the latest item and can be searchable. Email is sent to the person who created the item once the item is created.
    '''
    if request.method == 'POST' and request.user.is_authenticated():
        page_title='Auction Creation form'
        postdata = request.POST.copy()
        form = AuctionForm(postdata, request.FILES)
        if form.is_valid():
            human = True
            name = postdata.get('name','')
            description = postdata.get('description','')
            minimum_price = postdata.get('minimum_price',0.01)
            ownerid = request.user.id
            user_profile = get_object_or_404(CustomUser, pk=ownerid)


            item = Item(name=name, description=description, minimum_price=minimum_price, owner=user_profile, highestbid=minimum_price)
            item.save()

            file_content = ContentFile(request.FILES['image'].read())
            item.image.save(request.FILES['image'].name, file_content, save=False)
            item.save()

            t = loader.get_template('registration/createAuction.txt')
            c = Context({
				'firstname': 		user_profile.first_name,
				'lastname': 		user_profile.last_name,
				'site_name': 		'YAAS Auction Site',
				'admin': 			'Kenneth Odoh',
			})

            email_subject = 'Your have created a new auction'
            send_mail(email_subject, t.render(c), '*****@*****.**', [user_profile.email], fail_silently=False) 
            return HttpResponseRedirect(reverse('showCurrentItem', args=(item.id,)))
    else:
        form = AuctionForm()			
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))