示例#1
0
    def get(self, request, *args, **kwargs):
        month = kwargs.get('month')
        year = kwargs.get('year')
        year, month = utils.parse_year_month(year, month, default=None)
        now = utils.now()

        if not month or not year:
            # show choose form
            choose_month_form = ChooseMonthForm()
            return render(request, 'tours/initialize_choose_month.html',
                          {'form': choose_month_form})

        try:
            month = int(month)
            year = int(year)
        except:
            raise Http404

        # make sure this month isn't initialized or out of allowed range
        date_obj = datetime.datetime(year, month, 1)
        current = datetime.datetime(now.year, now.month, 1)
        last_allowed = utils.add_months(current, 12, True)

        # make sure this month isn't initialized or out of allowed range
        if tours_utils.is_initialized(
                month=month,
                year=year) or date_obj < current or date_obj > last_allowed:
            raise PermissionDenied

        weeks = calendar.Calendar().monthdays2calendar(year, month)
        return render(request, 'tours/initialize_month.html', {
            'weeks': weeks,
            'month': month,
            'year': year
        })
示例#2
0
    def get(self, request, *args, **kwargs):
        month = kwargs.get("month")
        year = kwargs.get("year")
        year, month = utils.parse_year_month(year, month, default=None)
        now = utils.now()

        if not month or not year:
            # show choose form
            choose_month_form = ChooseMonthForm()
            return render(request, "tours/initialize_choose_month.html", {"form": choose_month_form})

        try:
            month = int(month)
            year = int(year)
        except:
            raise Http404

        # make sure this month isn't initialized or out of allowed range
        date_obj = datetime.datetime(year, month, 1)
        current = datetime.datetime(now.year, now.month, 1)
        last_allowed = utils.add_months(current, 12, True)

        # make sure this month isn't initialized or out of allowed range
        if tours_utils.is_initialized(month=month, year=year) or date_obj < current or date_obj > last_allowed:
            raise PermissionDenied

        weeks = calendar.Calendar().monthdays2calendar(year, month)
        return render(request, "tours/initialize_month.html", {"weeks": weeks, "month": month, "year": year})
示例#3
0
def get_initialize_month_choices():
    now = core_utils.now()
    months = [core_utils.add_months(now, i) for i in range(0, 13)]
    months_choices = []
    for month in months:
        if not is_initialized(month=month.month, year=month.year):
            months_choices.append((u'{}/{}'.format(month.year, month.month), month.strftime('%B %Y')))
    return months_choices
示例#4
0
 def __init__(self, *args, **kwargs):
     super(QuoteRequestForm, self).__init__(*args, **kwargs)
     self.fields['date_trip'].initial = add_months(datetime.datetime.now(),
                                                   1)
示例#5
0
    def post(self, request, *args, **kwargs):
        month = kwargs.get('month')
        year = kwargs.get('year')
        year, month = utils.parse_year_month(year, month)
        now = utils.now()

        try:
            month = int(month)
            year = int(year)
        except:
            raise Http404

        # make sure this month isn't initialized or out of allowed range
        date_obj = datetime.datetime(year, month, 1)
        current = datetime.datetime(now.year, now.month, 1)
        last_allowed = utils.add_months(current, 12, True)

        # make sure this month isn't initialized or out of allowed range
        if tours_utils.is_initialized(
                month=month,
                year=year) or date_obj < current or date_obj > last_allowed:
            raise PermissionDenied

        # process form
        selected_days = request.POST.get('selected_days', None)
        if selected_days is None:
            return HttpResponseBadRequest

        # make a counter of all selected days (i.e., days on which to have tours)
        if selected_days != '':
            selected_days_counter = Counter(
                [int(i) for i in selected_days.split(',')])
        else:
            selected_days_counter = Counter()

        # make a counter of all days in the month
        month_dates_counter = Counter([
            i for i in calendar.Calendar().itermonthdays(year, month) if i != 0
        ])
        canceled_days_counter = month_dates_counter - selected_days_counter

        for num, times in canceled_days_counter.items():
            date = datetime.date(year, month, num)
            canceled_day = CanceledDay(date=date)
            canceled_day.save()

        # add default tours on non-blacked out days
        default_tours = DefaultTour.objects.all()
        weeks = calendar.Calendar().monthdatescalendar(year, month)
        for week in weeks:
            for date in week:
                if date.month == month and not CanceledDay.objects.filter(
                        date=date):
                    for default_tour in default_tours.filter(
                            day_num=date.weekday):
                        add_tour = Tour.objects.create(
                            source=default_tour.source,
                            time=datetime.datetime(date.year, date.month,
                                                   date.day, default_tour.hour,
                                                   default_tour.minute),
                            notes=default_tour.notes,
                            length=default_tour.length,
                            default_tour=True)

        # mark month as initialized
        initialized_month = InitializedMonth.objects.create(month=month,
                                                            year=year)
        return redirect('tours:month', month=month, year=year)
示例#6
0
    def post(self, request, *args, **kwargs):
        month = kwargs.get("month")
        year = kwargs.get("year")
        year, month = utils.parse_year_month(year, month)
        now = utils.now()

        try:
            month = int(month)
            year = int(year)
        except:
            raise Http404

        # make sure this month isn't initialized or out of allowed range
        date_obj = datetime.datetime(year, month, 1)
        current = datetime.datetime(now.year, now.month, 1)
        last_allowed = utils.add_months(current, 12, True)

        # make sure this month isn't initialized or out of allowed range
        if tours_utils.is_initialized(month=month, year=year) or date_obj < current or date_obj > last_allowed:
            raise PermissionDenied

        # process form
        selected_days = request.POST.get("selected_days", None)
        if selected_days is None:
            return HttpResponseBadRequest

        # make a counter of all selected days (i.e., days on which to have tours)
        if selected_days != "":
            selected_days_counter = Counter([int(i) for i in selected_days.split(",")])
        else:
            selected_days_counter = Counter()

        # make a counter of all days in the month
        month_dates_counter = Counter([i for i in calendar.Calendar().itermonthdays(year, month) if i != 0])
        canceled_days_counter = month_dates_counter - selected_days_counter

        for num, times in canceled_days_counter.items():
            date = datetime.date(year, month, num)
            canceled_day = CanceledDay(date=date)
            canceled_day.save()

        # add default tours on non-blacked out days
        default_tours = DefaultTour.objects.all()
        weeks = calendar.Calendar().monthdatescalendar(year, month)
        for week in weeks:
            for date in week:
                if date.month == month and not CanceledDay.objects.filter(date=date):
                    for default_tour in default_tours.filter(day_num=date.weekday):
                        add_tour = Tour.objects.create(
                            source=default_tour.source,
                            time=datetime.datetime(
                                date.year, date.month, date.day, default_tour.hour, default_tour.minute
                            ),
                            notes=default_tour.notes,
                            length=default_tour.length,
                            default_tour=True,
                        )

        # mark month as initialized
        initialized_month = InitializedMonth.objects.create(month=month, year=year)
        return redirect("tours:month", month=month, year=year)