def updateTrain(loaded):
    if session["adminLog"] == 1:
        global train
        form = UpdateTrain()
        try:
            global train
            train_no = request.form["train_no"]
            train = Train.query.filter_by(train_no=train_no).first()
            print(train_no)
        except:
            if form.validate_on_submit():
                db.session.delete(train)
                db.session.commit()
                train = Train(
                    train_no=form.trainID.data,
                    train_name=form.trainName.data,
                    source=form.starting.data,
                    destination=form.ending.data,
                    monday=form.monday.data,
                    tuesday=form.tuesday.data,
                    wednesday=form.wednesday.data,
                    thursday=form.thursday.data,
                    friday=form.friday.data,
                    saturday=form.saturday.data,
                    sunday=form.sunday.data,
                    ac_first_class_coaches=form.acFirstClassCoaches.data,
                    ac_two_tier_coaches=form.acTwoTierCoaches.data,
                    ac_three_tier_coaches=form.acThreeTierCoaches.data,
                    sleeper_class_coaches=form.sleeperClassCoaches.data,
                    ac_first_class_available_seats=24 *
                    int(form.acFirstClassCoaches.data),
                    ac_two_tier_available_seats=54 *
                    int(form.acTwoTierCoaches.data),
                    ac_three_tier_available_seats=64 *
                    int(form.acThreeTierCoaches.data),
                    sleeper_class_available_seats=72 *
                    int(form.sleeperClassCoaches.data),
                    ac_first_class_fare=form.acFirstClassFare.data,
                    ac_two_tier_fare=form.acTwoTierFare.data,
                    ac_three_tier_fare=form.acThreeTierFare.data,
                    sleeper_class_fare=form.sleeperClassFare.data,
                    arrival=str(form.arrival.data),
                    departure=str(form.departure.data),
                    total=str(form.total.data))
                db.session.add(train)
                db.session.commit()
                flash('Your train has been updated', 'success')
                return redirect(url_for('view'))
        return render_template('update_train.html',
                               title="Update Train",
                               loaded=loaded,
                               form=form,
                               train=train,
                               admin=session["adminLog"])
    else:
        if current_user.is_authenticated:
            return redirect(url_for('home'))
        else:
            flash('Please log in to access this page.', 'info')
            return redirect(url_for('adminLogin'))
Пример #2
0
def train_data():
    print("Checking whether data file exists and reading from it.")
    dataset = get_data_from_file("train")
    if not dataset:
        return "Error: Null dataset."

    print("Deleting Train Objects.")
    Train.objects.all().delete()

    print("Inserting new data.")

    for data in dataset:
        data = data.split(COLDIV)
        data[1] = int(data[1])
        t = Train()
        t.name, t.number = data
        t.save()
        print("Saved train " + str(t.number))

    print("Insertion done.\nQuiting...")
Пример #3
0
 def get(self, request):
     ticket_number = request.user.ticket_number
     train = Train.get_train_by_ticket_number(ticket_number)
     return JsonResponse({
         'id':
         train.id,
         'title':
         f'(Train {train.type} {ticket_number} from {train.departure_city} to {train.arrival_city})',
         'users': [{
             'name': request.user.username,
             'points': request.user.points
         }, {
             'name': 'Kasia',
             'points': 2
         }, {
             'name': 'Jan',
             'points': 0
         }]
     })
Пример #4
0
 def list(self, request, *args, **kwargs):
     ticket_number = request.user.ticket_number
     train = Train.get_train_by_ticket_number(ticket_number)
     return JsonResponse({
         'id':
         train.id,
         'title':
         f'Train {train.type} {ticket_number} from {train.departure_city} to {train.arrival_city}',
         'users': [{
             'name': request.user.username,
             'ready': request.user.ready
         }, {
             'name': 'Kasia',
             'ready': True
         }, {
             'name': 'Jan',
             'ready': True
         }]
     })
def addTrain():
    if session["adminLog"] == 1:
        form = AddTrain()
        if form.validate_on_submit():
            print("Yes")
            days = [
                'monday', 'tuesday', 'wednesday', 'thursday', 'friday',
                'saturday', 'sunday'
            ]
            for day in days:
                if form[day].data:
                    form[day].data = 1
                else:
                    form[day].data = 0
            train = Train(train_no=form.trainID.data,
                          train_name=form.trainName.data,
                          source=form.starting.data,
                          destination=form.ending.data,
                          monday=form.monday.data,
                          tuesday=form.tuesday.data,
                          wednesday=form.wednesday.data,
                          thursday=form.thursday.data,
                          friday=form.friday.data,
                          saturday=form.saturday.data,
                          sunday=form.sunday.data,
                          ac_first_class_coaches=form.acFirstClassCoaches.data,
                          ac_two_tier_coaches=form.acTwoTierCoaches.data,
                          ac_three_tier_coaches=form.acThreeTierCoaches.data,
                          sleeper_class_coaches=form.sleeperClassCoaches.data,
                          ac_first_class_available_seats=24 *
                          int(form.acFirstClassCoaches.data),
                          ac_two_tier_available_seats=54 *
                          int(form.acTwoTierCoaches.data),
                          ac_three_tier_available_seats=64 *
                          int(form.acThreeTierCoaches.data),
                          sleeper_class_available_seats=72 *
                          int(form.sleeperClassCoaches.data),
                          ac_first_class_fare=form.acFirstClassFare.data,
                          ac_two_tier_fare=form.acTwoTierFare.data,
                          ac_three_tier_fare=form.acThreeTierFare.data,
                          sleeper_class_fare=form.sleeperClassFare.data,
                          departure=str(form.departure.data),
                          arrival=str(form.arrival.data),
                          total=str(form.tot_time.data))
            db.session.add(train)
            print("Train read Success")
            ac1_seats = 24 * int(form.acFirstClassCoaches.data)
            for i in range(ac1_seats):
                print("Inside Loop")
                seat = SeatStatus(train_no=form.trainID.data,
                                  seat_no=1000 + i + 1,
                                  seat_type="1A")
                db.session.add(seat)

            ac2_seats = 54 * int(form.acTwoTierCoaches.data)
            for i in range(ac2_seats):
                seat = SeatStatus(train_no=form.trainID.data,
                                  seat_no=2000 + i + 1,
                                  seat_type="2A")
                db.session.add(seat)

            ac3_seats = 64 * int(form.acThreeTierCoaches.data)
            for i in range(ac3_seats):
                seat = SeatStatus(train_no=form.trainID.data,
                                  seat_no=3000 + i + 1,
                                  seat_type="3A")
                db.session.add(seat)

            sleep_seats = 72 * int(form.sleeperClassCoaches.data)
            for i in range(sleep_seats):
                seat = SeatStatus(train_no=form.trainID.data,
                                  seat_no=4000 + i + 1,
                                  seat_type="Sl")
                db.session.add(seat)

            db.session.commit()

            flash('Your train has been added', 'success')
            return redirect(url_for('view'))
        return render_template('add_train.html',
                               title="Add Train",
                               form=form,
                               admin=session["adminLog"])
    else:
        if current_user.is_authenticated:
            return redirect(url_for('home'))
        else:
            flash('Please log in to access this page.', 'info')
            return redirect(url_for('adminLogin'))
Пример #6
0
 def remaining_place(self, Train):
     return Train.get_remaining_place()