Example #1
0
def prof_add_out(request):
    error = False
    errorMessage = []
    context = {}

    context['prof_out'] = 'active'

    if request.method == 'POST':
        profID              = genProfID()                       # 1. profID
        firstName           = request.POST['firstName']         # 2. firstName
        lastName            = request.POST['lastName']          # 3. lastName
        shortName           = request.POST['shortName']         # 4. shortName
        tell                = request.POST['tell']              # 5. tell
        email               = request.POST['email']             # 6. email
        sahakornAccount     = request.POST['sahakornAccount']   # 7. sahakornAccount
        department          = request.POST['department']        # 8. department
        faculty             = request.POST['faculty']           # 9. faculty
        type                = '1'                               # 10. type 1 is อาจารย์นอกภาควิชา
        prefix_name         = request.POST['prefix_name']       # 11. prefix_name
        academic_position   = request.POST['academic_position'] # 12. academic_position

        # ปรับ shortName ให้เป็นตัวพิมพ์ใหญ่
        shortName = str(shortName).upper()

        # ตรวจสอบดูว่า profID ซ้ำหรือไม่
        try:
            test = Prof2Lang.objects.get(profID = profID)
            error = True
            errorMessage.append('รหัสอาจารย์นี้มีในฐานข้อมูลแล้ว')
        except:
            pass

        # ตรวจสอบดูว่า shortName ซ้ำหรือไม่
        try:
            test = Prof2Lang.objects.get(shortName = shortName)
            error = True
            errorMessage.append('ตัวย่อชื่อนี้มีในฐานข้อมูลแล้ว')
        except:
            pass

        if error:
            context['profID']           = profID            # 1. profID
            context['firstName']        = firstName         # 2. firstName
            context['lastName']         = lastName          # 3. lastName
            context['shortName']        = shortName         # 4. shortName
            context['tell']             = tell              # 5. tell
            context['email']            = email             # 6. email
            context['sahakornAccount']  = sahakornAccount   # 7. sahakornAccount
            context['department']       = department        # 8. department
            context['faculty']          = faculty           # 9. faculty

            context['prof_out_errorMessage']     = errorMessage
        else:
            # create new Prof2Lang object
            newProf = Prof2Lang(
                profID          = profID,           # 1. profID
                firstName       = firstName,        # 2. firstName
                lastName        = lastName,         # 3. lastName
                shortName       = shortName,        # 4. shortName
                tell            = tell,             # 5. tell
                email           = email,            # 6. email
                sahakornAccount = sahakornAccount,  # 7. sahakornAccount
                department      = department,       # 8. department
                faculty         = faculty,          # 9. faculty
                type            = type,             # 10. type
                prefix_name     = prefix_name,      # 11. prefix_name
                academic_position = academic_position # 12. academic_position
            )

            # save new Prof2Lang object into database
            newProf.save()
            context['prof_out_successMessage'] = "เพิ่มข้อมูลอาจารย์ผู้สอนนอกภาควิชาเรียบร้อยแล้ว"
    return prof_add(request, context)
Example #2
0
def prof2langAdd_special(request):
    error = False
    errorMessage = []
    context = {}

    context['prof_special'] = 'active'

    if request.method == 'POST':
        profID              = genProfID()                       # 1. profID
        firstName           = request.POST['firstName']         # 2. firstName
        lastName            = request.POST['lastName']          # 3. lastName
        shortName           = request.POST['shortName']         # 4. shortName
        tell                = request.POST['tell']              # 5. tell
        email               = request.POST['email']             # 6. email
        sahakornAccount     = request.POST['sahakornAccount']   # 7. sahakornAccount
        department          = ''                                # 8. department is empty
        faculty             = ''                                # 9. faculty is empty
        type                = '2'                               # 10. type 1 is อาจารย์พิเศษ
        prefix_name         = request.POST['prefix_name']       # 11. prefix_name
        academic_position   = request.POST['academic_position'] # 12. academic_position

        # ปรับ shortName ให้เป็นตัวพิมพ์ใหญ่
        shortName = str(shortName).upper()

        # ตรวจสอบดูว่า profID ซ้ำหรือไม่
        try:
            test = Prof2Lang.objects.get(profID = profID)
            error = True
            errorMessage.append('รหัสอาจารย์นี้มีในฐานข้อมูลแล้ว')
        except:
            pass

        # ตรวจสอบดูว่า shortName ซ้ำหรือไม่
        try:
            test = Prof2Lang.objects.get(shortName = shortName)
            error = True
            errorMessage.append('ตัวย่อชื่อนี้มีในฐานข้อมูลแล้ว')
        except:
            pass

        if error:
            context['profID']           = profID            # 1. profID
            context['firstName']        = firstName         # 2. firstName
            context['lastName']         = lastName          # 3. lastName
            context['shortName']        = shortName         # 4. shortName
            context['tell']             = tell              # 5. tell
            context['email']            = email             # 6. email
            context['sahakornAccount']  = sahakornAccount   # 7. sahakornAccount

            context['prof_special_errorMessage']     = errorMessage
        else:
            # create new Prof2Lang object
            newProf = Prof2Lang(
                profID          = profID,           # 1. profID
                firstName       = firstName,        # 2. firstName
                lastName        = lastName,         # 3. lastName
                shortName       = shortName,        # 4. shortName
                tell            = tell,             # 5. tell
                email           = email,            # 6. email
                sahakornAccount = sahakornAccount,  # 7. sahakornAccount
                department      = department,       # 8. department
                faculty         = faculty,          # 9. faculty
                type            = type,             # 10. type
                prefix_name     = prefix_name,      # 11. prefix_name
                academic_position = academic_position # 12. academic_position
            )

            # save new Prof2Lang object into database
            newProf.save()
            return HttpResponseRedirect(reverse('group3:prof2lang_add', args=['0']))

    return prof2langAdd(request, context)