Exemple #1
0
def create_sessionals():
    from sessionals.models import SessionalAccount, SessionalContract
    from coredata.models import AnyPerson, Person
    unit = Unit.objects.get(slug='cmpt')
    a = SessionalAccount(unit=unit,
                         title='SFUFA Account',
                         account_number='234',
                         position_number=123456,
                         slug='cmpt-234-sfufa-account')
    a.save()
    p = Person.objects.get(userid='0ggg1')
    ap = AnyPerson.get_or_create_for(person=p)
    ap.save()
    co = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
    c = SessionalContract(account=a,
                          sessional=ap,
                          offering=co,
                          appointment_start=co.semester.start,
                          appointment_end=co.semester.end,
                          pay_start=co.semester.start -
                          datetime.timedelta(days=2),
                          pay_end=co.semester.end - datetime.timedelta(days=2),
                          slug='a-test-sessionalcontract',
                          sin='000000000',
                          contact_hours=45.6,
                          total_salary=4657.95,
                          created_by='devtest',
                          unit=unit)
    c.save()
    return itertools.chain(
        SessionalAccount.objects.all(),
        AnyPerson.objects.all(),
        SessionalContract.objects.all(),
    )
Exemple #2
0
def edit_contract(request, contract_slug):
    contract = get_object_or_404(SessionalContract, slug=contract_slug, unit__in=request.units)
    if request.method == 'POST':
        form = SessionalContractForm(request, request.POST, instance=contract)
        if form.is_valid():
            contract = form.save(commit=False)
            # Let's convert the person in there to an AnyPerson
            person = form.cleaned_data['person']
            contract.sessional = AnyPerson.get_or_create_for(person=person)
            contract.save()
            messages.add_message(request,
                                 messages.SUCCESS,
                                 'Contract was edited.'
                                 )
            l = LogEntry(userid=request.user.username,
                         description="edited sessional contract for: %s" % contract.sessional,
                         related_object=contract
                         )
            l.save()

            return HttpResponseRedirect(reverse('sessionals:sessionals_index'))
    else:
        form = SessionalContractForm(request, instance=contract)
        form.fields['person'].initial = contract.sessional.get_person().emplid
    return render(request, 'sessionals/edit_contract.html', {'form': form, 'contract': contract})
Exemple #3
0
def new_contract(request):
    if request.method == 'POST':
        form = SessionalContractForm(request, request.POST)
        if form.is_valid():
            contract = form.save(commit=False)
            # Let's convert the person in there to an AnyPerson
            person = form.cleaned_data['person']
            contract.sessional = AnyPerson.get_or_create_for(person=person)
            contract.save()
            messages.add_message(request,
                                 messages.SUCCESS,
                                 'Contract was created.'
                                 )
            l = LogEntry(userid=request.user.username,
                         description="added sessional contract for: %s" % contract.sessional,
                         related_object=contract
                         )
            l.save()

            return HttpResponseRedirect(reverse('sessionals:sessionals_index'))
    else:
        form = SessionalContractForm(request)
        #  Everyone except a sysadmin most likely has only one unit they have admin roles for.  Let's try to
        #  find the config matching that unit, and if it exists, use it for default values.
        config = SessionalConfig.objects.filter(unit__in=request.units).first()
        if config:
            form.fields['appointment_start'].initial = config.appointment_start
            form.fields['appointment_end'].initial = config.appointment_end
            form.fields['pay_start'].initial = config.pay_start
            form.fields['pay_end'].initial = config.pay_end
            form.fields['course_hours_breakdown'].initial = config.course_hours_breakdown
    return render(request, 'sessionals/new_contract.html', {'form': form})
Exemple #4
0
def create_sessionals():
    from sessionals.models import SessionalAccount, SessionalContract
    from coredata.models import AnyPerson, Person
    unit = Unit.objects.get(slug='cmpt')
    a = SessionalAccount(unit=unit, title='SFUFA Account', account_number='234', position_number=123456,
                         slug='cmpt-234-sfufa-account')
    a.save()
    p = Person.objects.get(userid='0ggg1')
    ap = AnyPerson.get_or_create_for(person=p)
    ap.save()
    co = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
    c = SessionalContract(account=a, sessional=ap, offering=co, appointment_start=co.semester.start,
                          appointment_end=co.semester.end, pay_start=co.semester.start - datetime.timedelta(days=2),
                          pay_end=co.semester.end - datetime.timedelta(days=2), slug='a-test-sessionalcontract',
                          sin='000000000', contact_hours=45.6, total_salary=4657.95, created_by='devtest', unit=unit)
    c.save()
    return itertools.chain(
        SessionalAccount.objects.all(),
        AnyPerson.objects.all(),
        SessionalContract.objects.all(),
    )