Ejemplo n.º 1
0
def edit_schedule(request, *args, **kwargs):
    if request.method == 'POST':

        if request.user and request.user.is_active:
            user_id = request.user.id
        else:
            # @TODO trhow exception
            user_id = 0

        schobj = Schedule()
        dt_start_temp = request.POST.get('dt-start', None)
        dt_start = datetime.strptime(dt_start_temp,
                                     '%d/%m/%Y').strftime("%Y-%m-%d")
        dt_end_temp = request.POST.get('dt-end', None)
        dt_end = datetime.strptime(dt_end_temp,
                                   '%d/%m/%Y').strftime("%Y-%m-%d")

        schobj.price = float(request.POST.get('sch-price', 0))
        schobj.price_lower = float(request.POST.get('sch-price-lower', 0))
        schobj.price_highter = float(request.POST.get('sch-price-highter', 0))
        schobj.departure_date = dt_start
        schobj.landing_date = dt_end
        schobj.days_in_place = get_interval_from_diffdays(
            diffdays(dt_start_temp, dt_end_temp))

        schobj.user_id = user_id

        # departure_in_weekend_only = request.POST.get('departure_in_weekend_only', False)
        # if departure_in_weekend_only == 'on':
        #     departure_in_weekend_only = True
        # landing_in_weekend_only = request.POST.get('landing_in_weekend_only', False)
        # if landing_in_weekend_only == 'on':
        #     landing_in_weekend_only = True

        landing_in_weekend_only = True
        departure_in_weekend_only = True

        schobj.departure_in_weekend_only = departure_in_weekend_only
        schobj.landing_in_weekend_only = landing_in_weekend_only
        # schobj.exactly_days_check = request.POST.get('sch-', None)

        departure_id = request.POST.get('sch-place-departure', None)
        placeobj = Place.objects.get(pk=departure_id)
        schobj.departure = placeobj

        id = request.POST.get('sch-id', None)

        if id:
            Schedule.objects.filter(pk=id).update(logic_delete=True)
            remove_automatic_scheduled_jobs(id)

        schobj.save()
        landings = request.POST.getlist('sch-place-landing', None)
        places = Place.objects.filter(pk__in=landings)
        schobj.landing = places
        schobj.save()
        return HttpResponseRedirect(reverse('flyerapp:home'))
Ejemplo n.º 2
0
def edit_schedule(request, *args, **kwargs):
    if request.method == 'POST':

        if request.user and request.user.is_active:
            user_id = request.user.id
        else:
            # @TODO trhow exception
            user_id = 0

        schobj = Schedule()
        dt_start_temp = request.POST.get('dt-start', None)
        dt_start = datetime.strptime(dt_start_temp, '%d/%m/%Y').strftime("%Y-%m-%d")
        dt_end_temp = request.POST.get('dt-end', None)
        dt_end = datetime.strptime(dt_end_temp, '%d/%m/%Y').strftime("%Y-%m-%d")

        schobj.price = float(request.POST.get('sch-price', 0))
        schobj.price_lower = float(request.POST.get('sch-price-lower', 0))
        schobj.price_highter = float(request.POST.get('sch-price-highter', 0))
        schobj.departure_date = dt_start
        schobj.landing_date = dt_end
        schobj.days_in_place = get_interval_from_diffdays(diffdays(dt_start_temp, dt_end_temp))

        schobj.user_id = user_id

        # departure_in_weekend_only = request.POST.get('departure_in_weekend_only', False)
        # if departure_in_weekend_only == 'on':
        #     departure_in_weekend_only = True
        # landing_in_weekend_only = request.POST.get('landing_in_weekend_only', False)
        # if landing_in_weekend_only == 'on':
        #     landing_in_weekend_only = True

        landing_in_weekend_only = True
        departure_in_weekend_only = True

        schobj.departure_in_weekend_only = departure_in_weekend_only
        schobj.landing_in_weekend_only = landing_in_weekend_only
        # schobj.exactly_days_check = request.POST.get('sch-', None)

        departure_id = request.POST.get('sch-place-departure', None)
        placeobj = Place.objects.get(pk=departure_id)
        schobj.departure = placeobj

        id = request.POST.get('sch-id', None)

        if id:
            Schedule.objects.filter(pk=id).update(logic_delete=True)
            remove_automatic_scheduled_jobs(id)

        schobj.save()
        landings = request.POST.getlist('sch-place-landing', None)
        places = Place.objects.filter(pk__in=landings)
        schobj.landing = places
        schobj.save()
        return HttpResponseRedirect( reverse( 'flyerapp:home' ) )