コード例 #1
0
ファイル: views.py プロジェクト: gabrieldb/fairfrome
def createDuty():
    # define an error variable to be passed through if any errors that need to be prompted to the user occur
    error= None
    # create object instance of the duty form class
    duty_form = DutyForm()
    # add all of the volunteers from the volunteer table to the multiselection field for the duty form 
    duty_form.volunteer.choices = [(volunteer.id, volunteer.get_full_name().title()) for volunteer in Volunteer.query.filter_by(isActive = True)]
    # add all of the locations from the location table to the drop down selection field for the duty location 
    duty_form.location.choices = [(location.id, location.name) for location in Location.query.all()]
    # if the submit button is clicked
    if request.method == 'POST':
            # and the wtform fields validate
            if duty_form.validate_on_submit():
                # create an object instance of the class Duty
                new_duty = Duty(duty_form.location.data, duty_form.name.data, 
                duty_form.description.data, duty_form.date.data, duty_form.startTime.data, 
                duty_form.endTime.data)
                # add to the table and commit to the database
                db.session.add(new_duty)
                db.session.commit()
                # create the shifts for each volunteer
                # itterate through each volunteer selected from the multiselection form
                for volunteer in duty_form.volunteer.data:
                    # add the volunteer to the duty volunteers, creating a shift for each one with the given duty id
                    new_duty.volunteers.append(Volunteer.query.filter_by(id = volunteer).first())
                # commit to the database
                db.session.commit()
                # send the administrator back to the homepage
                return redirect(url_for('dashboard.home'))
    # load the duty creation page
    return render_template('schedule/create_duty.html', duty_form=duty_form, error=error)
コード例 #2
0
ファイル: views.py プロジェクト: bovine/flightloggin2
def realtime(request):
    from forms import DutyForm
    
    
    # get the current server time to seed the javascript timer
    gmt = datetime.datetime.now() + datetime.timedelta(hours=5)
    
    latest_open_duty = Duty.latest_open(user=request.display_user)
    
    if request.POST: #.get('submit') == "Go on Duty":
        form = DutyForm(request.POST, instance=latest_open_duty)
        if form.is_valid():
            form.save()
        
        print request.POST.get('submit')
        
        if request.POST.get('submit') == "Go On Duty":
            on_duty = True
        
        if request.POST.get('submit') == "Go Off Duty":
            on_duty = False
            form = DutyForm()
    else:

        if latest_open_duty.on_duty():
            form = DutyForm(instance=latest_open_duty)
            on_duty = True
            
        else:
            form = DutyForm()
            on_duty = False
            
    return locals()
コード例 #3
0
def realtime(request):
    from forms import DutyForm

    # get the current server time to seed the javascript timer
    gmt = datetime.datetime.now() + datetime.timedelta(hours=5)

    latest_open_duty = Duty.latest_open(user=request.display_user)

    if request.POST:  #.get('submit') == "Go on Duty":
        form = DutyForm(request.POST, instance=latest_open_duty)
        if form.is_valid():
            form.save()

        print request.POST.get('submit')

        if request.POST.get('submit') == "Go On Duty":
            on_duty = True

        if request.POST.get('submit') == "Go Off Duty":
            on_duty = False
            form = DutyForm()
    else:

        if latest_open_duty.on_duty():
            form = DutyForm(instance=latest_open_duty)
            on_duty = True

        else:
            form = DutyForm()
            on_duty = False

    return locals()