Exemple #1
0
def edit(request, trip_id=None, template_name="edit.html"):
    trip = None
    if trip_id:
        try:
            trip = Trip.objects.get(id=trip_id)
        except Trip.DoesNotExist:
            raise Http404

    if request.method == "GET":
        if trip:
            form = TripForm(instance=trip)
        else:
            form = TripForm(initial={'date': datetime.datetime.now().date()})

    if request.method == "POST":
        form = TripForm(request.POST, instance=trip)
        if form.is_valid():
            trip = form.save(commit=False)
            trip.user = request.user
            trip.save()
            messages.success(request, u"Saved!")
            return HttpResponseRedirect(reverse("log"))
        else:
            messages.error(request, u"Uh oh... Error!")

    ctx = dict(
        trip=trip,
        tab="edit",
        form=form,
        )

    return render_to_response(
        template_name, RequestContext(request, ctx))
Exemple #2
0
def add():
    form = TripForm()
    if form.validate_on_submit():
        url = form.url.data
        description = form.description.data
        destination = form.destination.data
        outbound_date = form.outbound_date.data
        outbound_time = form.outbound_time.data
        inbound_date = form.inbound_date.data
        inbound_time = form.inbound_time.data
        tags = form.tags.data
        bm = Trip(user=current_user,
                  url=url,
                  description=description,
                  destination=destination,
                  tags=tags,
                  outbound_date=outbound_date,
                  outbound_time=outbound_time,
                  inbound_date=inbound_date,
                  inbound_time=inbound_time)
        db.session.add(bm)
        db.session.commit()
        flash("Stored trip '{}'".format(description))
        return redirect(url_for('index'))
    return render_template('trip_form.html', form=form, title="Add a Trip")
Exemple #3
0
def edit(id=0):
    setExits()
    id = cleanRecordID(id)
    if id < 0:
        flash("That is not a valid ID")
        return redirect(g.listURL)
            
    rec = None
    if id > 0:
        rec = Trip.query.get(id)
        if not rec:
            flash(printException("Could not edit that "+g.title + " record. ID="+str(id)+")",'error'))
            return redirect(g.listURL)
    
    form = TripForm(request.form, rec)
    ## choices need to be assigned before rendering the form
    # AND before attempting to validate it
    form.countEvent_ID.choices = getCountEventChoices()
    form.location_ID.choices = getLocationChoices()
    form.traveler_ID.choices = getTravelerChoices()
    form.turnDirection.choices = getTurnDirectionChoices()
    
    if request.method == 'POST' and form.validate():
        if not rec:
            rec = Trip(form.tripCount.data,form.tripDate.data,form.turnDirection.data,form.seqNo.data,form.location_ID.data,form.traveler_ID.data,form.countEvent_ID.data)
            db.session.add(rec)
        form.populate_obj(rec)
        db.session.commit()
        return redirect(g.listURL)
        
    return render_template('genericEditForm.html', rec=rec, form=form)
Exemple #4
0
def addtrip():
    error = None
    tripForm = TripForm()
    tripForm.trip_country.choices = [(a.countryName, a.countryName)
                                     for a in Country.query.all()]
    tripForm.trip_city.choices = [(a.cityName, a.cityName)
                                  for a in City.query.all()]
    if request.method == 'POST':
        if tripForm.validate_on_submit():
            now_loc = img_folder + str(current_user.id)
            #if directory is not yet created this function will create it
            if os.path.isdir(now_loc) == False:
                os.makedirs(now_loc)

            if tripForm.file.data and allowed_file(
                    tripForm.file.data.filename):
                filename = secure_filename(tripForm.file.data.filename)
                tripForm.file.data.save(os.path.join(now_loc + '/', filename))
                uploadFolder = now_loc + '/'

                #the renaming process of the image
                nameNow = str(int(time.time())) + '.' + str(
                    os.path.splitext(filename)[1][1:])

                #saving the changes
                os.rename(uploadFolder + filename, uploadFolder + nameNow)

                #this is the compressor part, this will optimize the image
                #and will decrease its file size but not losing that much quality
                img = Image.open(open(str(uploadFolder + nameNow), 'rb'))
                img.save(str(uploadFolder + nameNow),
                         quality=90,
                         optimize=True)

            tripform = Trips(tripName=tripForm.trip_name.data,
                             tripDateFrom=tripForm.trip_date_from.data,
                             tripDateTo=tripForm.trip_date_to.data,
                             userID=current_user.id,
                             tripCountry=tripForm.trip_country.data,
                             tripCity=tripForm.trip_city.data,
                             status=1,
                             visibility=tripForm.trip_visibility.data,
                             img_thumbnail=nameNow,
                             featuredTrip=0)

            db.session.add(tripform)
            db.session.commit()
            return redirect(url_for('trip_blueprint.trips'))

    ph = Photos.query.filter_by(id=current_user.profile_pic).first()
    if ph is None:
        cas = 'default'
    else:
        cas = ph.photoName

    return render_template('addtrip.html',
                           form=tripForm,
                           error=error,
                           csID=str(current_user.id),
                           csPic=str(cas))
Exemple #5
0
def edit_trip(trip_id):
    trip = Trip.query.get_or_404(trip_id)
    if current_user != trip.user:
        abort(403)
    form = TripForm(obj=trip)
    if form.validate_on_submit():
        form.populate_obj(trip)
        db.session.commit()
        flash("Stored '{}'".format(trip.description))
        return redirect(url_for('user', username=current_user.username))
    return render_template('trip_form.html', form=form, title="Edit Trip")
def addtrip():
    error = None
    tripForm = TripForm()
    tripForm.trip_country.choices = [(a.countryName, a.countryName)
                                     for a in Country.query]
    tripForm.trip_city.choices = [(a.cityName, a.cityName) for a in City.query]
    if request.method == 'POST':
        if tripForm.validate_on_submit():
            tripform = Trips(tripName=tripForm.trip_name.data,
                             tripDateFrom=tripForm.trip_date_from.data,
                             tripDateTo=tripForm.trip_date_to.data,
                             userID=current_user.id,
                             tripCountry=tripForm.trip_country.data,
                             tripCity=tripForm.trip_city.data,
                             status=tripForm.trip_status.data,
                             visibility=tripForm.trip_visibility.data,
                             img_thumbnail=tripForm.file.data.filename)
            db.session.add(tripform)
            db.session.commit()

            if tripForm.file.data and allowed_file(
                    tripForm.file.data.filename):
                filename = secure_filename(tripForm.file.data.filename)
                tripForm.file.data.save(
                    os.path.join(img_folder + 'trips/', filename))
            #ex = os.path.splitext(filename)[1][1:]
            #st = img_folder+'trips/'+filename
            #img = Image.open(open(str(st), 'rb'))
            #img.save(str(st), format=None, quality=50)

            return redirect(url_for('trip_blueprint.addtrip'))

    ph = Photos.query.filter_by(id=current_user.profile_pic).first()
    if ph is None:
        cas = 'default'
    else:
        cas = ph.photoName

    return render_template('addtrip.html',
                           form=tripForm,
                           error=error,
                           csID=str(current_user.id),
                           csPic=str(cas))
Exemple #7
0
def edittrips(tripName):
    trips = Trips.query.filter_by(tripName=tripName).first()
    result = Trips.query.all()
    form = TripForm()
    if form.validate_on_submit():
        trips.tripName = form.tripName.data
        trips.tripDateFrom = form.tripDateFrom.data
        trips.tripDateTo = form.tripDateTo.data
        trips.id = form.id.data
        trips.viewsNumber = form.viewsNumber.data
        trips.img_thumbnail = form.img_thumbnail.data
        db.session.add(trips)
        db.session.commit()
        flash("Your changes have been saved.")
        return render_template('admin/trips.html', result=result)
    else:
        form.tripName.data = trips.tripName
        form.tripDateFrom.data = trips.tripDateFrom
        form.tripDateTo.data = trips.tripDateTo
        form.id.data = trips.id
        form.viewsNumber.data = trips.viewsNumber
        form.img_thumbnail.data = trips.img_thumbnail
        return render_template('admin/edittrips.html', trips=trips, form=form)
Exemple #8
0
def edit(id=0):
    setExits()
    id = cleanRecordID(id)
    if id < 0:
        flash("That is not a valid ID")
        return redirect(g.listURL)

    rec = None
    if id > 0:
        rec = Trip.query.get(id)
        if not rec:
            flash(
                printException(
                    "Could not edit that " + g.title + " record. ID=" +
                    str(id) + ")", 'error'))
            return redirect(g.listURL)

    form = TripForm(request.form, rec)
    ## choices need to be assigned before rendering the form
    # AND before attempting to validate it
    form.countEvent_ID.choices = getCountEventChoices()
    form.location_ID.choices = getLocationChoices()
    form.traveler_ID.choices = getTravelerChoices()
    form.turnDirection.choices = getTurnDirectionChoices()

    if request.method == 'POST' and form.validate():
        if not rec:
            rec = Trip(form.tripCount.data, form.tripDate.data,
                       form.turnDirection.data, form.seqNo.data,
                       form.location_ID.data, form.traveler_ID.data,
                       form.countEvent_ID.data)
            db.session.add(rec)
        form.populate_obj(rec)
        db.session.commit()
        return redirect(g.listURL)

    return render_template('genericEditForm.html', rec=rec, form=form)
Exemple #9
0
def addtrip():
    error = None
    tripForm = TripForm()
    if request.method == 'POST':
        if tripForm.validate_on_submit():
            tripform = Trips(tripName=tripForm.trip_name.data,
                             tripDateFrom=tripForm.trip_date_from.data,
                             tripDateTo=tripForm.trip_date_to.data,
                             userID=current_user.id,
                             img_thumbnail=tripForm.file.data.filename)
            db.session.add(tripform)
            db.session.commit()

            if tripForm.file.data and allowed_file(tripForm.file.data.filename):
                filename = secure_filename(tripForm.file.data.filename)
                tripForm.file.data.save(os.path.join(img_folder+'trips/', filename))
            ex = os.path.splitext(filename)[1][1:]
            st = img_folder+'trips/'+filename
            img = Image.open(open(str(st), 'rb'))
            img.save(str(st), format=None, quality=50)

            return redirect(url_for('trip_blueprint.addtrip'))

    return render_template('addtrip.html', form=tripForm, error=error)
Exemple #10
0
def addtrip():
    trips = Trips(tripName=request.form['tripName'],
                  tripDateFrom=request.form['tripDateFrom'],
                  tripDateTo=request.form['tripDateTo'],
                  id=request.form['id'],
                  img_thumbnail=request.form['img_thumbnail'])
    form = TripForm()
    trips.tripName = form.tripName.data
    trips.tripDateFrom = form.tripDateFrom.data
    trips.tripDateTo = form.tripDateTo.data
    trips.id = form.id.data
    trips.img_thumbnail = form.img_thumbnail.data
    db.session.add(trips)
    db.session.commit()
    flash("Your changes have been saved.")
    return render_template('admin/trips.html', result=result)
Exemple #11
0
def createtrip():
    form = TripForm()
    return render_template('admin/createtrip.html', form=form)