Example #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
        })
Example #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})
Example #3
0
    def get(self, request, *args, **kwargs):
        if kwargs.get("public"):
            # make sure this user is active
            if not request.user.person.is_active:
                raise PermissionDenied
        else:
            # make sure this is a board member
            try:
                request.user.groups.get(name="Board Members")
            except Group.DoesNotExist:
                raise PermissionDenied

        now = utils.now()
        year = kwargs.get("year")
        month = kwargs.get("month")
        year, month = utils.parse_year_month(year, month)
        months_list = [(num, name) for num, name in enumerate(list(calendar.month_name)) if num != 0]
        date = datetime.date(year, month, 1)
        next_month = date + relativedelta(months=1)
        prev_month = date + relativedelta(months=-1)
        primary_tour_coordinator = get_person_by_position("Tour Coordinator (Primary)", "Tour Coordinator")

        is_open, date_closes = tours_utils.month_is_open(month=month, year=year, return_tuple=True)

        if is_open:
            public_url = request.build_absolute_uri(
                unicode(reverse("public:month", kwargs={"year": year, "month": month}))
            )
        else:
            public_url = None

        open_eligible = tours_utils.open_eligible(month=month, year=year)

        weeks_with_tours = tours_utils.weeks_with_tours(month=month, year=year)

        context = {
            "months_list": months_list,
            "weeks": weeks_with_tours,
            "now": now,
            "month": month,
            "year": year,
            "next_year": (year + 1),
            "prev_year": (year - 1),
            "next_month": next_month,
            "prev_month": prev_month,
            "month_initialized": tours_utils.is_initialized(month=month, year=year),
            "is_open": is_open,
            "date_closes": date_closes,
            "open_eligible": open_eligible,
            "public_url": public_url,
            "primary_tour_coordinator": primary_tour_coordinator,
        }

        if kwargs.get("public"):
            return render(request, "public/month.html", context)
        elif kwargs.get("print") is True:
            return render(request, "tours/month_print.html", context)
        else:
            return render(request, "tours/month.html", context)
Example #4
0
    def get(self, request, *args, **kwargs):
        if kwargs.get('public'):
            # make sure this user is active
            if not request.user.person.is_active:
                raise PermissionDenied
        else:
            # make sure this is a board member
            try:
                request.user.groups.get(name='Board Members')
            except Group.DoesNotExist:
                raise PermissionDenied

        now = utils.now()
        year = kwargs.get('year')
        month = kwargs.get('month')
        year, month = utils.parse_year_month(year, month)
        months_list = [(num, name)
                       for num, name in enumerate(list(calendar.month_name))
                       if num != 0]
        date = datetime.date(year, month, 1)
        next_month = date + relativedelta(months=1)
        prev_month = date + relativedelta(months=-1)
        primary_tour_coordinator = get_person_by_position(
            'Tour Coordinator (Primary)', 'Tour Coordinator')

        is_open, date_closes = tours_utils.month_is_open(month=month,
                                                         year=year,
                                                         return_tuple=True)

        if is_open:
            public_url = request.build_absolute_uri(
                unicode(
                    reverse('public:month',
                            kwargs={
                                'year': year,
                                'month': month
                            })))
        else:
            public_url = None

        open_eligible = tours_utils.open_eligible(month=month, year=year)

        weeks_with_tours = tours_utils.weeks_with_tours(month=month, year=year)

        context = {
            'months_list': months_list,
            'weeks': weeks_with_tours,
            'now': now,
            'month': month,
            'year': year,
            'next_year': (year + 1),
            'prev_year': (year - 1),
            'next_month': next_month,
            'prev_month': prev_month,
            'month_initialized': tours_utils.is_initialized(month=month,
                                                            year=year),
            'is_open': is_open,
            'date_closes': date_closes,
            'open_eligible': open_eligible,
            'public_url': public_url,
            'primary_tour_coordinator': primary_tour_coordinator,
        }

        if kwargs.get('public'):
            return render(request, 'public/month.html', context)
        elif kwargs.get('print') is True:
            return render(request, 'tours/month_print.html', context)
        else:
            return render(request, 'tours/month.html', context)
Example #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)
Example #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)