Exemplo n.º 1
0
def add_farm(request):

    if request.method == 'POST':
        form = FarmAddForm(request.POST)
        if form.is_valid():
            instances = form.save()
            return HttpResponseRedirect(reverse('farm', args=[instances.id]))
    else:
        form = FarmAddForm()
    
    return _render(request, 'add_farm.html', locals())
Exemplo n.º 2
0
def book(request):
    if request.method == 'POST':
        form = BookingForm(request.POST)
        if form.is_valid():
            # do something here
            
            return HttpResponseRedirect(reverse('booking_confirmed'))
        else:
            form = BookingForm(request.POST)
    else:
        form = BookingForm()
    return _render(request, 'website/book.html', locals())
Exemplo n.º 3
0
def gallery_image(request, slug, id):
    image = get_object_or_404(GalleryImage, pk=id)
    try:
        next = get_object_or_404(GalleryImage, pk=(image.id+1), tour=image.tour)
    except:
        next = None
    
    try:
        prev = get_object_or_404(GalleryImage, pk=(image.id-1), tour=image.tour)
    except:
        prev = None
    return _render(request, 'website/gallery_image.html', locals())
Exemplo n.º 4
0
def add_instance(request, id):

    tea = get_object_or_404(Tea, pk=id)
    if request.method == 'POST':
        form = TeaInstanceAddForm(request.POST)
        if form.is_valid():
            
            instances = form.save()

            return HttpResponseRedirect(reverse('tea', args=[tea.id]))
    else:
        form = TeaInstanceAddForm()

    return _render(request, 'add_tea_instance.html', locals())
Exemplo n.º 5
0
def add_photo(request, tea_instance_id):
    
    tea_instance = get_object_or_404(TeaInstance, id=tea_instance_id)
    
    if request.method == 'POST':
        form = PhotoAddForm(request.POST, request.FILES)
        if form.is_valid():
            
            # add the photo and then save the model
            photo = request.FILES['image']
            image_content = photo.read()
            image = Image.open(StringIO(image_content))
            format = image.format
            format = format.lower().replace('jpeg', 'jpg')
            filename = md5.new(image_content).hexdigest() + '.' + format
            # Save the image
            path = os.path.join(settings.MEDIA_ROOT, 'tea_photos', filename)
            # check that the dir of the path exists
            dirname = os.path.dirname(path)
            if not os.path.isdir(dirname):
                try:
                    os.mkdir(dirname)
                except IOError:
                    raise IOError, "Unable to create the directory %s" % dirname
            open(path, 'w').write(image_content)
            
            thing = Photo.objects.create(
                image = "".join(('tea_photos/', filename)),
                date_uploaded = datetime.now(),
                tea_instance = tea_instance,
            )   
            
            print thing.image         

            return HttpResponseRedirect(reverse('tea_instance', args=[tea_instance.tea.id, tea_instance.id]))
    else:
        form = PhotoAddForm()
    
    return _render(request, 'add_photo.html', locals())
Exemplo n.º 6
0
def galleries(request):
    tours = Tour.objects.filter()
    return _render(request, 'website/galleries.html', locals())
Exemplo n.º 7
0
def tour(request, slug):
    tour = get_object_or_404(Tour, slug=slug)
    return _render(request, 'website/tour.html', locals())
Exemplo n.º 8
0
def tours(request):
    tours = Tour.objects.filter().order_by('start_date')
    return _render(request, 'website/tours.html', locals())
Exemplo n.º 9
0
def booking_confirmed(request):
    return _render(request, 'website/booking_confirmed.html', locals())
Exemplo n.º 10
0
def home(request):
    tours = Tour.objects.filter().order_by('start_date')
    photos = GalleryImage.objects.all().order_by('?')[:4]
    return _render(request, "website/home.html", locals())
Exemplo n.º 11
0
def search(request):
    
    return _render(request, 'home.html', locals())
Exemplo n.º 12
0
def farm(request, id):
    farm = get_object_or_404(Farm, pk=id)
    return _render(request, 'farm.html', locals())
Exemplo n.º 13
0
def farms(request):
    farms = Farm.objects.all()    
    return _render(request, 'farms.html', locals())
Exemplo n.º 14
0
def tea_instance(request, tea_id, id):

    tea_instance = get_object_or_404(TeaInstance, pk=id)

    return _render(request, 'tea_instance.html', locals())
Exemplo n.º 15
0
def tea(request, id):
    tea = get_object_or_404(Tea, pk=id)
    tea_instances = TeaInstance.objects.filter(tea=tea)
    return _render(request, 'tea.html', locals())
Exemplo n.º 16
0
def teas(request):  
    teas = Tea.objects.all()  
    return _render(request, 'teas.html', locals())
Exemplo n.º 17
0
def page(request, slug):
    page = get_object_or_404(Page, slug=slug)
    
    return _render(request, 'website/page.html', locals())
Exemplo n.º 18
0
def index(request):    
    return _render(request, 'home.html', locals())