Ejemplo n.º 1
0
 def test_get_year_season(self):
     year, season = utils.get_year_season()
     self.assertLess(abs(year - localtime(now()).date().year), 2)
     self.assertIn(
         season,
         [Semester.SPRING, Semester.SUMMER, Semester.FALL],
     )
Ejemplo n.º 2
0
def start_semester_view(request):
    """
    Initiates a semester's worth of workshift, with the option to copy workshift
    types from the previous semester.
    """
    page_name = "Start Semester"
    year, season = utils.get_year_season()
    start_date, end_date = utils.get_semester_start_end(year, season)

    semester_form = SemesterForm(
        request.POST or None,
        initial={
            "year": year,
            "season": season,
            "start_date": start_date.strftime(date_formats[0]),
            "end_date": end_date.strftime(date_formats[0]),
            })

    pool_forms = []
    try:
        prev_semester = Semester.objects.all()[0]
    except IndexError:
        pass
    else:
        for pool in WorkshiftPool.objects.filter(semester=prev_semester):
            form = StartPoolForm(
                request.POST or None,
                initial={
                    "title": pool.title,
                    "hours": pool.hours,
                    },
                prefix="pool-{0}".format(pool.pk),
                )
            pool_forms.append(form)

    if semester_form.is_valid() and all(i.is_valid() for i in pool_forms):
        # And save this semester
        semester = semester_form.save()
        semester.workshift_managers = \
          [i.incumbent.user for i in Manager.objects.filter(workshift_manager=True)]
        semester.save()
        for pool_form in pool_forms:
            pool_form.save(semester=semester)
        return HttpResponseRedirect(wurl("workshift:manage",
                                         sem_url=semester.sem_url))

    # TODO: Adding workshift pools? Should we do a separate page for that?

    return render_to_response("start_semester.html", {
        "page_name": page_name,
        "semester_form": semester_form,
        "pool_forms": pool_forms,
    }, context_instance=RequestContext(request))
Ejemplo n.º 3
0
 def test_starting_month(self):
     # Starting in Summer, Fall, and Spring
     self.assertEqual(
         (2015, Semester.SPRING),
         utils.get_year_season(day=date(2014, 12, 20)),
         )
     self.assertEqual(
         (2015, Semester.SPRING),
         utils.get_year_season(day=date(2015, 3, 20)),
         )
     self.assertEqual(
         (2014, Semester.SUMMER),
         utils.get_year_season(day=date(2014, 4, 1)),
         )
     self.assertEqual(
         (2014, Semester.SUMMER),
         utils.get_year_season(day=date(2014, 7, 20)),
         )
     self.assertEqual(
         (2014, Semester.FALL),
         utils.get_year_season(day=date(2014, 8, 1)),
         )
     self.assertEqual(
         (2014, Semester.FALL),
         utils.get_year_season(day=date(2014, 10, 20)),
         )
Ejemplo n.º 4
0
def start_semester_view(request):
    """
    Initiates a semester's worth of workshift, with the option to copy workshift
    types from the previous semester.
    """
    page_name = "Start Semester"
    year, season = utils.get_year_season()
    start_date, end_date = utils.get_semester_start_end(year, season)

    semester_form = SemesterForm(
        request.POST or None,
        initial={
            "year": year,
            "season": season,
            "start_date": start_date.strftime(date_formats[0]),
            "end_date": end_date.strftime(date_formats[0]),
            })

    pool_forms = []
    try:
        prev_semester = Semester.objects.all().order_by('end_date')[0]
    except IndexError:
        pass
    else:
        for pool in WorkshiftPool.objects.filter(semester=prev_semester):
            form = StartPoolForm(
                request.POST or None,
                initial={
                    "title": pool.title,
                    "hours": pool.hours,
                    },
                prefix="pool-{0}".format(pool.pk),
                )
            pool_forms.append(form)

    if semester_form.is_valid() and all(i.is_valid() for i in pool_forms):
        # And save this semester
        semester = semester_form.save()
        for pool_form in pool_forms:
            pool_form.save(semester=semester)
        return HttpResponseRedirect(wurl("workshift:manage",
                                         sem_url=semester.sem_url))

    return render_to_response("start_semester.html", {
        "page_name": page_name,
        "semester_form": semester_form,
        "pool_forms": pool_forms,
        }, context_instance=RequestContext(request))
Ejemplo n.º 5
0
def _get_semester():
    # Start the Workshift Semester
    year, season = get_year_season()
    start_date, end_date = get_semester_start_end(year, season)
    try:
        semester = Semester.objects.get(current=True)
    except Semester.DoesNotExist:
        semester, created = Semester.objects.get_or_create(
            year=year,
            season=season,
            defaults=dict(start_date=start_date, end_date=end_date),
            )
    else:
        created = False

    if created:
        logging.info("Started a new workshift semester")

    return semester
Ejemplo n.º 6
0
def _get_semester():
    # Start the Workshift Semester
    year, season = get_year_season()
    start_date, end_date = get_semester_start_end(year, season)
    try:
        semester = Semester.objects.get(current=True)
    except Semester.DoesNotExist:
        semester, created = Semester.objects.get_or_create(
            year=year,
            season=season,
            defaults=dict(start_date=start_date, end_date=end_date),
        )
    else:
        created = False

    if created:
        logging.info("Started a new workshift semester")

    return semester
Ejemplo n.º 7
0
def main(args):
    # Add Managers
    for title, compensation, hours, email, duties in MANAGERS:
        Manager.objects.create(
            title=title,
            compensation=compensation,
            semester_hours=str(hours),
            summer_hours=str(hours),
            duties=duties,
            email="{0}{1}@bsc.coop".format(settings.HOUSE_ABBREV, email) if email else "",
            president="president" in title.lower(),
            workshift_manager="workshift" in title.lower(),
            )

    # Add Requests
    for name, managers, glyphicon in REQUESTS:
        r = RequestType.objects.create(
            name=name,
            glyphicon=glyphicon,
            )
        r.managers = [Manager.objects.get(title=i) for i in managers]
        r.save()

    if "workshift" in settings.INSTALLED_APPS:
        # Start the Workshift Semester
        year, season = get_year_season()
        start_date, end_date = get_semester_start_end(year, season)
        semester = Semester.objects.create(
            year=year,
            season=season,
            start_date=start_date,
            end_date=end_date,
            )

        for uprofile in UserProfile.objects.filter(status=UserProfile.RESIDENT):
            profile = WorkshiftProfile.objects.create(
                user=uprofile.user,
                semester=semester,
                )

        # Regular Weekly Workshift Hours
        pool = WorkshiftPool.objects.create(
            semester=semester,
            is_primary=True,
            hours=5,
            any_blown=True,
            )
        pool.managers = Manager.objects.filter(workshift_manager=True)
        pool.save()

        # HI Hours
        hi_pool = WorkshiftPool.objects.create(
            title="Home Improvement",
            semester=semester,
            hours=str(4),
            weeks_per_period=0,
            )
        hi_pool.managers = Manager.objects.filter(title="Maintenance Manager")
        hi_pool.save()

        # Social Hours
        social_pool = WorkshiftPool.objects.create(
            title="Social",
            semester=semester,
            hours=str(1),
            weeks_per_period=6,
            )
        social_pool.managers = Manager.objects.filter(title="Social Manager")
        social_pool.save()

        # Humor Shift
        humor_pool = WorkshiftPool.objects.create(
            title="Humor Shift",
            semester=semester,
            any_blown=True,
            hours=str(2),
            weeks_per_period=6,
            )
        humor_pool.managers = Manager.objects.filter(workshift_manager=True)
        humor_pool.save()

        make_workshift_pool_hours(semester)

        # Workshift Types
        for title, description, quick_tips, hours, rateable in WORKSHIFT_TYPES:
            WorkshiftType.objects.create(
                title=title,
                description=description,
                quick_tips=quick_tips,
                hours=str(hours),
                rateable=rateable,
                )

        # Regular Workshifts
        for title, type_title, days, count, start, end in REGULAR_WORKSHIFTS:
            wtype = WorkshiftType.objects.get(title=type_title)
            shift = RegularWorkshift.objects.create(
                workshift_type=wtype,
                title=title,
                pool=pool,
                count=count,
                start_time=start,
                end_time=end,
                hours=wtype.hours,
                )
            shift.days = get_int_days(days)
            shift.save()

        for title, type_title, count in WEEK_LONG:
            wtype = WorkshiftType.objects.get(title=type_title)
            shift = RegularWorkshift.objects.create(
                workshift_type=wtype,
                title=title,
                pool=pool,
                count=count,
                week_long=True,
                start_time=None,
                end_time=None,
                hours=wtype.hours,
                )

        # Humor Workshifts
        for title, type_title, days, start, end in HUMOR_WORKSHIFTS:
            wtype = WorkshiftType.objects.get(title=type_title)
            shift = RegularWorkshift.objects.create(
                workshift_type=wtype,
                title=title,
                pool=humor_pool,
                start_time=start,
                end_time=end,
                hours=wtype.hours,
                )
            shift.days = get_int_days(days)
            shift.save()

        make_instances(semester=semester)
        make_manager_workshifts(semester)
Ejemplo n.º 8
0
def main(args, verbose=True):
    # Add Managers
    managers = 0
    for title, compensation, hours, email, duties in MANAGERS:
        created = Manager.objects.get_or_create(
            title=title,
            defaults=dict(
                compensation=compensation,
                semester_hours=hours,
                summer_hours=hours,
                duties=duties,
                email="{0}{1}@bsc.coop".format(settings.HOUSE_ABBREV, email) if email else "",
                president="president" in title.lower(),
                workshift_manager="workshift" in title.lower(),
                ),
            )[1]
        if created:
            managers += 1

    if verbose:
        print("Created {0} managers".format(managers))

    # Add Requests
    requests = 0
    for name, managers, glyphicon in REQUESTS:
        r, created = RequestType.objects.get_or_create(
            name=name,
            defaults=dict(
                glyphicon=glyphicon,
                ),
            )

        if created:
            r.managers = [Manager.objects.get(title=i) for i in managers]
            r.save()
            requests += 1

    if verbose:
        print("Created {0} request types".format(requests))

    if "workshift" in settings.INSTALLED_APPS:
        # Start the Workshift Semester
        year, season = get_year_season()
        start_date, end_date = get_semester_start_end(year, season)
        try:
            semester = Semester.objects.get(current=True)
        except Semester.DoesNotExist:
            semester, created = Semester.objects.get_or_create(
                year=year,
                season=season,
                defaults=dict(start_date=start_date, end_date=end_date),
                )
        else:
            created = False

        if created and verbose:
            print("Started a new workshift semester")

        # Regular Weekly Workshift Hours
        pool, created = WorkshiftPool.objects.get_or_create(
            semester=semester,
            is_primary=True,
            defaults=dict(hours=5, any_blown=True),
            )
        if created:
            pool.managers = Manager.objects.filter(workshift_manager=True)
            pool.save()

        # HI Hours
        hi_pool, created = WorkshiftPool.objects.get_or_create(
            title="Home Improvement",
            semester=semester,
            defaults=dict(hours=4, weeks_per_period=0),
            )
        if created:
            hi_pool.managers = Manager.objects.filter(title="Maintenance Manager")
            hi_pool.save()

        # Social Hours
        social_pool, created = WorkshiftPool.objects.get_or_create(
            title="Social",
            semester=semester,
            defaults=dict(hours=1, weeks_per_period=0),
            )
        if created:
            social_pool.managers = Manager.objects.filter(title="Social Manager")
            social_pool.save()

        # Humor Shift
        humor_pool, created = WorkshiftPool.objects.get_or_create(
            title="Humor Shift",
            semester=semester,
            defaults=dict(any_blown=True, hours=2, weeks_per_period=6),
            )
        if created:
            humor_pool.managers = Manager.objects.filter(workshift_manager=True)
            humor_pool.save()

        make_workshift_pool_hours(semester)

        # Workshift Types
        for title, description, quick_tips, rateable in WORKSHIFT_TYPES:
            WorkshiftType.objects.get_or_create(
                title=title,
                defaults=dict(
                    description=description,
                    quick_tips=quick_tips,
                    rateable=rateable,
                    ),
                )

        # Regular Workshifts
        for type_title, hours, days, count, start, end in REGULAR_WORKSHIFTS:
            wtype = WorkshiftType.objects.get(title=type_title)
            for day in days:
                RegularWorkshift.objects.get_or_create(
                    workshift_type=wtype,
                    pool=pool,
                    day=day,
                    start_time=start,
                    end_time=end,
                    defaults=dict(
                        count=count,
                        hours=hours,
                        ),
                    )

        for type_title, hours, count in WEEK_LONG:
            wtype = WorkshiftType.objects.get(title=type_title)
            RegularWorkshift.objects.get_or_create(
                workshift_type=wtype,
                pool=pool,
                count=count,
                week_long=True,
                defaults=dict(
                    start_time=None,
                    end_time=None,
                    hours=hours,
                    ),
                )

        # Humor Workshifts
        for type_title, hours, days, start, end in HUMOR_WORKSHIFTS:
            wtype = WorkshiftType.objects.get(title=type_title)
            for day in days:
                RegularWorkshift.objects.get_or_create(
                    workshift_type=wtype,
                    pool=humor_pool,
                    day=day,
                    defaults=dict(
                        start_time=start,
                        end_time=end,
                        hours=hours,
                        ),
                    )

        make_instances(semester=semester)
        make_manager_workshifts(semester)