Ejemplo n.º 1
0
def list_qualified_applicants(request, download=True):
    submission_infos = (
        SubmissionInfo.get_qualified_submissions().select_related(
            depth=1).all())
    applicants = get_applicants_from_submission_infos(submission_infos)

    personal_infos = build_model_dict(PersonalInfo)
    # added more info to applicants
    for a in applicants:
        if a.id in personal_infos:
            a.national_id = personal_infos[a.id].national_id

    FIELD_LIST = [
        'ticket_number', 'first_name', 'last_name',
        'get_doc_submission_method_display', 'national_id'
    ]

    output_list = []
    for a in applicants:
        output_list.append(dump_fields(a, FIELD_LIST))
    output = u'\n'.join(output_list)

    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = 'attachment; filename=applicants.csv'
    response.write(output)

    return response
Ejemplo n.º 2
0
def list_applicant(request, reviewed=True, pagination=True):
    applicants = []
    display = {}
    submission_infos = SubmissionInfo.objects.filter(doc_received_at__isnull=False).filter(has_been_reviewed=reviewed).select_related(depth=1)
    if reviewed:
        submission_infos = submission_infos.order_by('-doc_reviewed_at')
    else:
        submission_infos = submission_infos.order_by('doc_received_at')

    applicant_count = submission_infos.count()

    if pagination:
        max_page = (applicant_count + APPLICANTS_PER_PAGE -1) / APPLICANTS_PER_PAGE
        page = 1
        if 'page' in request.GET:
            try:
                page = int(request.GET['page'])
            except:
                page = 1
        if page < 1 or page > max_page:
            page = 1
    else:
        max_page = 1
        page = 1

    display_start = APPLICANTS_PER_PAGE * (page - 1) + 1
    display_end = APPLICANTS_PER_PAGE * page
    submission_infos = submission_infos.all()[display_start-1:display_end]
    display_count = len(submission_infos)

    # add resubmitted applicants
    if not reviewed:
        resubmitted_submission_infos = list(SubmissionInfo.get_unreviewed_resubmitted_submissions().select_related(depth=1).all())
        applicant_count += len(resubmitted_submission_infos)
        submission_infos = list(resubmitted_submission_infos) + list(submission_infos)
        display_count = len(submission_infos)
        display_end += len(resubmitted_submission_infos)

    applicants = get_applicants_from_submission_infos(submission_infos)

    display['ticket_number']=True
    display['doc_received_at']=True
    if reviewed==True:
        display['doc_reviewed_at']=True
        display['doc_reviewed_complete']=True


    return render_to_response("review/search.html",
                              { 'form': None,
                                'applicant_count': applicant_count,
                                'applicants': applicants,
                                'force_review_link': True,
                                'pagination': pagination,
                                'display_start': display_start,
                                'display_end': display_end,
                                'display_count': display_count,
                                'page': page,
                                'max_page': max_page,
                                'display': display })
Ejemplo n.º 3
0
def list_incomplete_applicants(request, submission_method=None):
    submission_infos = (
        SubmissionInfo.get_incomplete_submissions().select_related(depth=1))

    applicants = get_applicants_from_submission_infos(submission_infos)

    submission_method_name = ''
    if submission_method == 'postal':
        submission_method_name = 'ที่สมัครออนไลน์แต่ส่งหลักฐานทางไปรษณีย์'
        applicants = [
            a for a in applicants
            if a.doc_submission_method == Applicant.SUBMITTED_BY_MAIL
        ]
    elif submission_method == 'offline':
        submission_method_name = 'ที่สมัครและส่งหลักฐานทางไปรษณีย์ (offline)'
        applicants = [
            a for a in applicants
            if a.doc_submission_method == Applicant.SUBMITTED_OFFLINE
        ]
    elif submission_method == 'online':
        submission_method_name = 'ที่สมัครและส่งหลักฐานออนไลน์ทั้งหมด'
        applicants = [
            a for a in applicants
            if a.doc_submission_method == Applicant.SUBMITTED_ONLINE
        ]

    applicant_count = len(applicants)

    notice = ''

    can_send_reminder_emails = (request.user.is_superuser
                                and submission_method != 'offline')

    if (request.method == 'POST') and (can_send_reminder_emails):
        # form submission, now send e-mail
        for app in applicants:
            send_resubmission_reminder_by_email(app)
        notice = ("ส่งอีเมล์เตือน %d ฉบับแล้ว" % (applicant_count, ))

    return render_to_response(
        "review/list_incomplete_for_email.html", {
            'form': None,
            'notice': notice,
            'submission_method_name': submission_method_name,
            'can_send_reminder_emails': can_send_reminder_emails,
            'applicant_count': applicant_count,
            'applicants': applicants,
            'force_review_link': True,
            'display': {
                'ticket_number': True,
                'doc_reviewed_at': True,
                'doc_reviewed_complete': True
            }
        })
Ejemplo n.º 4
0
def import_results():
    print 'Importing results...'

    app_order = 1
    for a in applicants:
        q_app = QualifiedApplicant()
        q_app.order = app_order
        q_app.ticket_number = a['ticket_number']
        q_app.first_name = a['first_name']
        q_app.last_name = a['last_name']
        q_app.category = ReportCategory.get_category_by_app_first_name(
            result_set_id, a['first_name'])
        submission_info = SubmissionInfo.find_by_ticket_number(a['ticket_number'])
        if submission_info == None:
            print 'TICKET:', a['ticket_number']
        applicant = submission_info.applicant
        q_app.applicant = applicant
        q_app.save()
        app_order += 1

        print a['ticket_number']
Ejemplo n.º 5
0
def find_applicants(form):
    ticket = form.cleaned_data['ticket_number']
    verinum = form.cleaned_data['verification_number']
    full_name = form.cleaned_data['full_name']
    if ticket:
        submission_info = SubmissionInfo.find_by_ticket_number(str(ticket))
        if submission_info!=None:
            return [submission_info.applicant]
        else:
            return []
    elif full_name:
        # search by name
        applicants = []
        items = full_name.strip().split(' ')
        if items[0]!='':
            applicants = Applicant.objects.all()
            applicants = applicants.filter(first_name__contains=items[0])
            if len(items)>1 and items[1]!='':
                applicants = applicants.filter(last_name__contains=items[1])
        return applicants
    else:
        return []
Ejemplo n.º 6
0
def confirm(request, preview=False):
    """
    Obsoleted.
    """

    return HttpResponseForbidden()

    if request.method != 'POST':
        return HttpResponseForbidden()
    if not request.user.has_perm('confirmation.add_admissionconfirmation'):
        return HttpResponseForbidden('ขออภัยคุณไม่มีสิทธิ์ในการทำรายการดังกล่าว')

    if 'cancel' in request.POST:
        request.session['notice'] = u'ยกเลิกการทำรายการ'
        return HttpResponseRedirect(reverse('confirmation-index'))

    import re

    if (('application_id' not in request.POST) or
        (not re.match(r'53[123]\d{5}', request.POST['application_id']))):
        request.session['notice'] = u'เกิดข้อผิดพลาด หมายเลขประจำตัวผู้สมัครไม่ถูกต้อง'
        return HttpResponseRedirect(reverse('confirmation-index'))

    application_id = request.POST['application_id']
    submission_info = SubmissionInfo.find_by_ticket_number(application_id)
    if submission_info==None:
        request.session['notice'] = (u'เกิดข้อผิดพลาด ไม่พบผู้สมัครที่ใช้หมายเลข %s' % application_id)
        return HttpResponseRedirect(reverse('confirmation-index'))

    applicant = submission_info.applicant

    if (not applicant.has_admission_result() or
        not applicant.admission_result.is_final_admitted):
        request.session['notice'] = (u'เกิดข้อผิดพลาด ผู้สมัครที่ใช้หมายเลข %s (%s) '
                                     u'ไม่ผ่านการคัดเลือกเข้าศึกษาต่อ' % 
                                     (application_id, applicant.full_name()))
        return HttpResponseRedirect(reverse('confirmation-index'))


    try:
        if applicant.admission_confirmation!=None:
            request.session['notice'] = (u'เกิดข้อผิดพลาด ผู้สมัครที่ใช้หมายเลข %s (%s) '
                                         u'ได้ยืนยันสิทธิ์แล้ว ถ้าต้องการยกเลิกกรุณาแจ้งผู้ดูแล' % 
                                         (application_id, applicant.full_name()))
            return HttpResponseRedirect(reverse('confirmation-index'))            
    except:
        pass

    if preview:
        return render_to_response('confirmation/preview.html',
                                  { 'applicant': applicant })
    else:
        confirmation = AdmissionConfirmation(applicant=applicant,
                                             confirming_user=request.user)

        Log.create("admission confirmation - from: %s" %
                   (request.META['REMOTE_ADDR'],),
                   user=request.user.username,
                   applicant_id=applicant.id,
                   applicantion_id=application_id)

        try:
            confirmation.save()
        except:
            Log.create("ERROR: admission confirmation - from: %s" %
                       (request.META['REMOTE_ADDR'],),
                       user=request.user.username,
                       applicant_id=applicant.id,
                       applicantion_id=application_id)

            request.session['notice'] = u'เกิดข้อผิดพลาดในการยืนยันสิทธิ์ กรุณาแจ้งผู้ดูแลด่วน'
            return HttpResponseRedirect(reverse('confirmation-index'))            

        request.session['notice'] = u'บันทึกการยืนยันสิทธิ์เรียบร้อย ชื่อผู้ยืนยันควรปรากฏในตารางด้านล่าง'
        return HttpResponseRedirect(reverse('confirmation-index'))            
Ejemplo n.º 7
0
def build_row(applicant, registration, personal_info, major_number):
    if registration == None:
        registration = StudentRegistration()

    if applicant.title == u'นาย':
        gender = 'M'
        eng_title = 'Mr.'
    else:
        gender = 'F'
        eng_title = 'Miss'

    bd_year = personal_info.birth_date.year + 543
    birth_date_str = personal_info.birth_date.strftime("%d/%m") + "/" + str(
        bd_year)
    try:
        address = applicant.address.home_address
    except:
        address = Address()

    try:
        education = applicant.education
    except:
        education = Education()

    major_number_str = '0' * (3 - len(str(major_number))) + str(major_number)
    try:
        major = Major.objects.get(number=major_number_str)
    except:
        major = Major.objects.get(number='001')

    if major_number < 100:
        status = u'ปกติ'
    elif major_number < 200:
        status = u'พิเศษ'
    else:
        status = u'นานาชาติ'

    try:
        submission_info = applicant.submission_info
    except:
        applicant.submission_info = SubmissionInfo()
        applicant.submission_info.submitted_at = datetime.datetime.now()

    vnum = ''
    if address.village_number != 0 and address.village_number != None:
        vnum = address.village_number

    ticket_number = ''
    try:
        ticket_number = unicode(applicant.ticket_number())
    except:
        pass

    return u','.join([
        u'"%s"' % s for s in [
            ticket_number,
            applicant.national_id,
            registration.passport_number,
            gender,
            applicant.title,
            applicant.first_name,
            applicant.last_name,
            eng_title,
            registration.english_first_name,
            registration.english_last_name.capitalize(),
            personal_info.nationality,
            personal_info.ethnicity,
            registration.religion,
            registration.birth_place,
            birth_date_str,
            address.number,
            vnum,
            registration.address_avenue,
            address.road,
            address.district,
            address.city,
            address.province,
            address.postal_code,
            registration.home_phone_number,
            registration.cell_phone_number,
            applicant.email,
            find_school_code(education.school_name, education.school_province),
            education.school_name,
            education.school_province,
            registration.school_type,
            u'%1.2f' % (registration.GPA),
            u'บางเขน',
            'E',
            u'วิศวกรรมศาสตร์',
            MAJOR_CODE[int(major.number)],
            major.name,
            u'รับตรง คณะวิศวกรรมศาสตร์',
            status,
            unicode(
                applicant.submission_info.submitted_at.strftime('%d/%m/2555')),
            unicode(applicant.submission_info.submitted_at.strftime(
                '%H/%M/%S')),
            u'0002',
            u'เกษตรศาสตร์',
            applicant.clearing_house_result.password,
            registration.father_title,
            registration.father_first_name,
            registration.father_last_name,
            registration.father_national_id,
            registration.mother_title,
            registration.mother_first_name,
            registration.mother_last_name,
            registration.mother_national_id,
        ]
    ])
Ejemplo n.º 8
0
pref_file_name = sys.argv[2]
out_file_name = sys.argv[3]

from django.conf import settings
from django_bootstrap import bootstrap
bootstrap(__file__)

from application.models import Applicant, SubmissionInfo

def read_as_dict(file_name, key_field, header_row=False):
    f = codecs.open(file_name, encoding='utf-8')
    d = {}
    if header_row:
        f.readline()
    for line in f:
        items = line.strip().split(',')
        d[items[key_field]] = items
    return d

pref_dict = read_as_dict(pref_file_name,1)
assignment_dict = read_as_dict(assignment_file_name, 0, header_row=True)

f = codecs.open(out_file_name, encoding='utf-8', mode='w')

for nat_id, data in assignment_dict.iteritems():
    pref = pref_dict[nat_id]
    submission_info = SubmissionInfo.find_by_ticket_number(pref[0])
    applicant = submission_info.applicant
    print >> f, pref[0] + ',' + applicant.title +','+ applicant.first_name +','+applicant.last_name + ',' + ','.join(data) + ',"' + ','.join(pref[3:]) + '"'

Ejemplo n.º 9
0
def confirm(request, preview=False):
    """
    Obsoleted.
    """

    return HttpResponseForbidden()

    if request.method != 'POST':
        return HttpResponseForbidden()
    if not request.user.has_perm('confirmation.add_admissionconfirmation'):
        return HttpResponseForbidden(
            'ขออภัยคุณไม่มีสิทธิ์ในการทำรายการดังกล่าว')

    if 'cancel' in request.POST:
        request.session['notice'] = u'ยกเลิกการทำรายการ'
        return HttpResponseRedirect(reverse('confirmation-index'))

    import re

    if (('application_id' not in request.POST) or
        (not re.match(r'53[123]\d{5}', request.POST['application_id']))):
        request.session[
            'notice'] = u'เกิดข้อผิดพลาด หมายเลขประจำตัวผู้สมัครไม่ถูกต้อง'
        return HttpResponseRedirect(reverse('confirmation-index'))

    application_id = request.POST['application_id']
    submission_info = SubmissionInfo.find_by_ticket_number(application_id)
    if submission_info == None:
        request.session['notice'] = (
            u'เกิดข้อผิดพลาด ไม่พบผู้สมัครที่ใช้หมายเลข %s' % application_id)
        return HttpResponseRedirect(reverse('confirmation-index'))

    applicant = submission_info.applicant

    if (not applicant.has_admission_result()
            or not applicant.admission_result.is_final_admitted):
        request.session['notice'] = (
            u'เกิดข้อผิดพลาด ผู้สมัครที่ใช้หมายเลข %s (%s) '
            u'ไม่ผ่านการคัดเลือกเข้าศึกษาต่อ' %
            (application_id, applicant.full_name()))
        return HttpResponseRedirect(reverse('confirmation-index'))

    try:
        if applicant.admission_confirmation != None:
            request.session['notice'] = (
                u'เกิดข้อผิดพลาด ผู้สมัครที่ใช้หมายเลข %s (%s) '
                u'ได้ยืนยันสิทธิ์แล้ว ถ้าต้องการยกเลิกกรุณาแจ้งผู้ดูแล' %
                (application_id, applicant.full_name()))
            return HttpResponseRedirect(reverse('confirmation-index'))
    except:
        pass

    if preview:
        return render_to_response('confirmation/preview.html',
                                  {'applicant': applicant})
    else:
        confirmation = AdmissionConfirmation(applicant=applicant,
                                             confirming_user=request.user)

        Log.create("admission confirmation - from: %s" %
                   (request.META['REMOTE_ADDR'], ),
                   user=request.user.username,
                   applicant_id=applicant.id,
                   applicantion_id=application_id)

        try:
            confirmation.save()
        except:
            Log.create("ERROR: admission confirmation - from: %s" %
                       (request.META['REMOTE_ADDR'], ),
                       user=request.user.username,
                       applicant_id=applicant.id,
                       applicantion_id=application_id)

            request.session[
                'notice'] = u'เกิดข้อผิดพลาดในการยืนยันสิทธิ์ กรุณาแจ้งผู้ดูแลด่วน'
            return HttpResponseRedirect(reverse('confirmation-index'))

        request.session[
            'notice'] = u'บันทึกการยืนยันสิทธิ์เรียบร้อย ชื่อผู้ยืนยันควรปรากฏในตารางด้านล่าง'
        return HttpResponseRedirect(reverse('confirmation-index'))