def checkout(request): r = Reservation.objects.filter(user=request.user, checkedout=False).order_by('end', 'start') if request.method == 'POST': for i in r: i.checkedout = True i.save() t = datetime.timedelta(1) c = i.start while c <= i.end: Paydue.objects.create(user=request.user, reservation=i, date=c, cost=i.location.cost) c += t return render(request, 'ads/checkout.html') else: t = 0 for i in r: t += i.cost return render(request, 'ads/checkout.html', {'r': r, 't': t})
def s3(request): ads = Ad.objects.filter(status=STATUS_CHECKED) if request.method == 'POST': done = [] error = [] for a in ads: filename = settings.MEDIA_ROOT + 'uploads/ads/' + str(a.id) if not os.path.isfile(filename): continue try: a.status = STATUS_UPLOADING a.save() upload_s3(filename, a.mimetype) except: a.status = STATUS_CHECKED a.save() error.append([a, sys.exc_info()]) else: a.status = STATUS_DONE a.save() done.append(a) return render(request, 'mod/s3-upload.html', {'done': done, 'error': error}) else: return render(request, 'mod/s3-todo.html', {'ads': ads})
def password_change(request): if request.method == 'POST': form = PasswordForm(request.POST) if form.is_valid(): request.user.set_password(form.cleaned_data['new_password']) request.user.save() return render(request, 'account/password-change-done.html') else: form = PasswordForm() return render(request, 'account/password-change.html', {'form': form})
def index(request): ads = Ad.objects.filter(user=request.user) reservations = Reservation.objects.filter(user=request.user, checkedout=True) return render(request, 'account/index.html', { 'ads': ads, 'reservations': reservations })
def reservations(request): l = Location.objects.all() a = [] for i in l: a.append((i, get_list(i))) return render(request, 'mod/reservations.html', {'a': a})
def upload(request): if request.method == 'POST': form = UploadForm(request.POST, request.FILES) if form.is_valid(): f = request.FILES['image'] a = Ad(user=request.user, name=form.cleaned_data['name'], mimetype=f['content-type'], filesize=len(f['content'])) if len(form.cleaned_data['name']) == 0: a.name = f['filename'] a.save() a.save_image_file(str(a.id), f['content']) a.image = a.get_image_filename() a.save() result = make_tn(a.get_image_filename()) if result[0] != 0: a.delete() return render( request, 'ads/upload.html', { 'form': form, 'fail': 'There was a problem while processing your image. It probably wasn\'t an image.' }) else: a.save() return render(request, 'ads/upload.html', { 'form': UploadForm(), 'upload': a.name }) else: form = UploadForm() return render(request, 'ads/upload.html', {'form': form})
def checkads(request): done = 0 for k, v in request.POST.iteritems(): if v[0] == 'on': try: a = Ad.objects.get(id=int(k)) a.status = STATUS_CHECKED a.save() done += 1 except: pass ads = Ad.objects.filter(status=STATUS_NOTCHECKED) return render(request, 'mod/check.html', {'ads': ads, 'done': done})
def pay(request): paydues = Paydue.objects.filter( user=request.user, date__lt=datetime.date.today()).select_related().order_by( 'date', 'ads_location.id', 'ads_ad.id') payments = Payment.objects.filter(user=request.user).values('amount') paid = 0 for i in payments: paid += i['amount'] p = [] total = 0 owed = 0 d = None for i in paydues: total += i.cost if total <= paid: continue owed += i.cost if d != i.date: d = i.date p.append([i, 0, []]) p[-1][-2] += i.cost p[-1][-1].append(i) if paid < total: p[0][-2] -= owed - total + paid total -= paid else: total = 0 return render( request, 'account/pay.html', { 'p': p, 't': total, 'paypal': settings.PAYPAL_BUSINESS_ADDRESS, 'external': settings.EXTERNAL_ADDRESS, 'paypal_url': settings.PAYPAL_URL })
def paid(request): return render(request, 'account/paid.html')
def index(request): page_size = 3 ads = Ad.objects.filter(user=request.user.id) locations = Location.objects.all() num_ad_pages = int(round(math.ceil(len(ads) / float(page_size)))) num_location_pages = int( round(math.ceil(len(locations) / float(page_size)))) adpages = [] for i in range(num_ad_pages): page = [] if i != 0: page.append(i) else: page.append(num_ad_pages) if i != num_ad_pages - 1: page.append(i + 2) else: page.append(1) adpages.append(page) ads_paged = [] page = [] for i in range(len(ads)): if i % page_size == 0: if (len(page) > 0): ads_paged.append(page) page = [] page.append(ads[i]) if (len(page) > 0): ads_paged.append(page) locationpages = [] for i in range(num_location_pages): page = [] if i != 0: page.append(i) else: page.append(num_location_pages) if i != num_location_pages - 1: page.append(i + 2) else: page.append(1) locationpages.append(page) locations_paged = [] page = [] for i in range(len(locations)): if i % page_size == 0: if (len(page) > 0): locations_paged.append(page) page = [] page.append(locations[i]) if (len(page) > 0): locations_paged.append(page) # set the appropriate margin depending on how many pages (dots) if num_ad_pages == 1: ad_margin = 35 elif num_ad_pages == 2: ad_margin = 30 elif num_ad_pages == 3: ad_margin = 22 elif num_ad_pages == 4: ad_margin = 15 else: ad_margin = 12 if num_location_pages == 1: location_margin = 35 elif num_location_pages == 2: location_margin = 30 elif num_location_pages == 3: location_margin = 22 elif num_location_pages == 4: location_margin = 15 else: location_margin = 12 return render( request, 'ads/index.html', { 'ads': ads, 'adpages': adpages, 'ads_paged': ads_paged, 'locations': locations, 'locationpages': locationpages, 'locations_paged': locations_paged, 'ad_margin': ad_margin, 'location_margin': location_margin })
def index(request): return render( request, 'blog/index.html', {'entries': Blog.objects.all().select_related().order_by('-date')[:5]})
def entry(request, id): e = get_object_or_404(Blog, pk=id) return render(request, 'blog/entry.html', {'entry': e})
def index(request): return render(request, 'mod/index.html')
def user_detail(request, user_id): u = get_object_or_404(User, pk=user_id) ads = Ad.objects.filter(user=u) res = Reservation.objects.filter(user=u) return render(request, 'mod/user_detail.html', {'u': u, 'ads': ads, 'res': res})
def users(request): users = User.objects.all() return render(request, 'mod/users.html', {'users': users})
def categories(request): iads = Ad.objects.filter(category_iads=True) fun = Ad.objects.filter(category_fun=True) return render(request, 'mod/categories.html', {'iads': iads, 'fun': fun})