Exemple #1
0
def prepare_invitation(owner, student_id, mode, addressing_parents, addressing_p, addressing_s, addressing_d):
    student = Student.get_by_id(int(student_id))
    if student is None:
        return
  

    logging.info('student: %s'%student)

    addressing=''
    iname = None
    isurname = None
    if mode=='parents':
        addressing=addressing_parents
        sex=student.get_sex()
        if not student.name is None:
            iname = inflector.do_inflect('name',sex,student.name)
        
        if not student.surname is None:
            isurname = inflector.do_inflect('surname',sex,student.surname)

    elif mode=='direct':
        if student.addressing =='p':
            addressing=addressing_p
        elif student.addressing =='s':
            addressing=addressing_s
        elif student.addressing =='d':
            addressing=addressing_d
       
    logging.info('addressing:%s'%addressing) 
 
    invitation = Invitation() 
    
    invitation.init(owner=owner,mode=mode, addressing=addressing, name=student.name, surname=student.surname, sex=student.get_sex(), street=student.street,
        street_no=student.street_no, city=student.city, post_code=student.post_code
                )

    if not iname is None:
        invitation.name_inflected = iname
    if not isurname is None:
        invitation.surname_inflected = isurname


    logging.info('pre save invitation=%s'%invitation)

    invitation.save()
    logging.info('invitation=%s'%invitation)
Exemple #2
0
def test(request):
    inflector.init_dicts()
    if request.method == 'POST':
        form = TestInflectForm(request.POST)
        if form.is_valid():
            pattern = form.cleaned_data['pattern']
            part = form.cleaned_data['part']
            gender = form.cleaned_data['gender']

            proposal = inflector.do_inflect(part,gender,pattern)
    
            form = TestInflectForm({'proposal':proposal,'pattern':pattern,'gender':gender,'part':part})
            
    else:
        form = TestInflectForm()

    return render_to_response('admin/inflects_test.html', RequestContext(request, {'form':form}))