예제 #1
0
def editProfile(request):
    mlogger.debug("Editing the profile of a member")   
    user = request.user   
    whichform = None
    profile = user.get_profile()   
    if request.method == "GET" :       
        if profile.isFaculty  :
                    whichform = "faculty"
                    #intialize the form
                    f = Faculty.objects.get(profile__id = profile.id )
                    fi = FacultyInstitute.objects.get(faculty__id = f.id,institute__id = request.institute.id)
                    initial_data = {'institutename':request.institute.name,
                                   'name':profile.fullname,
                                   'email':user.email,                               
                                    'department':fi.department.id}                   
                    fform = FacultyForm(request.institute.id,request.user.id ,initial=initial_data,instance=f)
                    industries = Industry.objects.all()
                    return render_to_response("institution/editprofile.html",{'industries':industries,'fform':fform,'whichform':whichform},RequestContext(request))
        elif user.get_profile().isStudent :                    
                    whichform = "student"
                    s = Student.objects.get(profile__id = profile.id )
                    si = StudentInstitute.objects.get(student__id = s.id,institute__id=request.institute.id)
                    initial_data = {'institutename':request.institute.name,
                                   'name':profile.fullname,
                                   'email':user.email,
                                    'website':profile.personalsite,
                                    'fromyear':si.fromyear,
                                   'toyear':si.toyear,
                                   'course':si.course.id,
                                   'department':si.department.id,
                                   'degree':si.degree.id}                    
                    sform = StudentForm(request.institute.id,request.user.id,initial=initial_data,instance=s)
                    industries = Industry.objects.all()
                    return render_to_response("institution/editprofile.html",{'industries':industries,'sform':sform,'whichform':whichform},RequestContext(request))
    elif request.method == "POST":
        if profile.isFaculty  :
            whichform = "faculty"
            f = Faculty.objects.get(profile__id = profile.id )
            fi = FacultyInstitute.objects.get(faculty__id = f.id,institute__id = request.institute.id)
            
            #update the user data
            fform = FacultyForm(request.institute.id,request.user.id,request.POST)
            if fform.is_valid() :
                profile.user.email = fform.cleaned_data['email']
                profile.user.username =  fform.cleaned_data['email'].replace("@","_").replace(".","_")
                profile.user.save()
                profile.fullname = fform.cleaned_data['name']
                            
                profile.save()               
                fi.department = fform.cleaned_data['department']
                fi.save()
                #Create message
                create_message(request,"Successfully update your profile..............")
                #Redirect to institute home
                return HttpResponseRedirect(reverse('editprofileurl'))
            else :
                return render_to_response("institution/editprofile.html",{'fform':fform,'whichform':whichform},RequestContext(request)) 
        elif profile.isStudent :
            whichform = "student"
            s = Student.objects.get(profile__id = profile.id )
            si = StudentInstitute.objects.get(student__id = s.id,institute__id=request.institute.id)
            
            #update the student data
            sform = StudentForm(request.institute.id,request.user.id,request.POST)
            if sform.is_valid() :
                profile.user.email = sform.cleaned_data['email']
                profile.user.username =  sform.cleaned_data['email'].replace("@","_").replace(".","_")
                profile.user.save()
                profile.fullname = sform.cleaned_data['name']                 
                profile.save()               
                si.toyear = sform.cleaned_data['toyear']
                si.fromyear = sform.cleaned_data['fromyear']                
                si.department = sform.cleaned_data['department']
                si.course = sform.cleaned_data['course']
                si.degree = sform.cleaned_data['degree']
                si.save()               
                #Create message
                create_message(request,"Successfully update your profile..............")
                #Redirect to institute home
                return HttpResponseRedirect(reverse('editprofileurl'))                         
            else :
                return render_to_response("institution/editprofile.html",{'sform':sform,'whichform':whichform},RequestContext(request))
예제 #2
0
def registerMember(request):
    ''' register new member it may be student or faculty'''
    mlogger.debug("Institution %s" %(str(request.institute)))
    mlogger.debug("Registering a new member it can either student or Faculty")
    
    if request.institute is not None :
        if request.method == "GET" :        
            fform = FacultyForm(request.institute.id,False)
            sform = StudentForm(request.institute.id,False)            
            states = State.objects.all().order_by("id")
            industries = Industry.objects.all()
            return render_to_response("institution/newmember.html",{'industries':industries,'fform':fform,'sform':sform,'states':states,'form_default':'student'},RequestContext(request))
        elif request.method == "POST":
            if request.POST['whichform'] == "student" :
                whichform = "student"
                sform = StudentForm(request.institute.id,0,request.POST)
                fform = FacultyForm(request.institute.id,0)
                if sform.is_valid() :                    
                    #give him the success message
                    student = sform.save(commit=False)
                    up = createMember(sform.cleaned_data['name'],sform.cleaned_data['email'],sform.cleaned_data['password'],whichform,sform,request.institute)
                    student.profile = up              
                    student.save()              
                    #Student Institute                    
                    si = StudentInstitute()
                    si.institute = request.institute
                    si.student = student
                    si.fromyear = sform.cleaned_data['fromyear']                  
                    if len(sform.cleaned_data['toyear'].strip()) > 0 :
                        si.toyear = sform.cleaned_data['toyear']                  
                    si.course = sform.cleaned_data['course']
                    si.department = sform.cleaned_data['department']
                    si.degree = sform.cleaned_data['degree']                    
                    si.save()                   
                    #Create message
                    
                    fullactivationurl = student.profile.get_full_activation_url(request.institute)                    
                    deliverEmail('newstudent_subject.html','newstudent_message.html',{'fullactivationurl':fullactivationurl,'institute':request.institute,'user':up.user,'password':sform.cleaned_data['password']},up.user.email)
                    
                    # TEll alumclub admin and institute admin about regitration
                    emails = getALumClubAdminUrls()
                    emails.append(request.institute.admin.email)
                    deliverEmail('tell_new_alumini_registration.html','tell_new_alumini_registration_message.html',{'fullactivationurl':fullactivationurl,'institute':request.institute,'user':up.user,'password':sform.cleaned_data['password']},emails)
                    #Tell institute admin about new registration                    
                    
                    create_message(request,"Successfully Registered.Your will be able to login once your account is  verified by the Insitute admin.")
                    return HttpResponseRedirect("/")                       
                else :
                    return render_to_response("institution/newmember.html",{'fform':fform,'sform':sform,'form_default':whichform},RequestContext(request))                        
            elif request.POST['whichform'] == "faculty" :
                whichform = "faculty"           
                sform = StudentForm(request.institute.id,0)
                fform = FacultyForm(request.institute.id,0,request.POST)
                if fform.is_valid() :
                    #give him the success message
                    faculty = fform.save(commit=False)
                    up = createMember(fform.cleaned_data['name'],fform.cleaned_data['email'],fform.cleaned_data['password'],whichform,fform,request.institute)
                    faculty.profile = up
                    faculty.save()                    
                    #save faculty institute relationship
                    fi = FacultyInstitute()
                    fi.institute = request.institute
                    fi.faculty = faculty                
                    fi.department = fform.cleaned_data['department']
                    fi.save()
                    #Create message
                    
                    fullactivationurl = faculty.profile.get_full_activation_url(request.institute)                    
                    deliverEmail('newfaculty_subject.html','newfaculty_message.html',{'fullactivationurl':fullactivationurl,'institute':request.institute,'user':up.user,'password':fform.cleaned_data['password']},up.user.email)
                    
                    # TEll alumclub admin and institute admin about regitration
                    emails = getALumClubAdminUrls()
                    emails.append(request.institute.admin.email)
                    deliverEmail('tell_new_alumini_registration.html','tell_new_alumini_registration_message.html',{'fullactivationurl':fullactivationurl,'institute':request.institute,'user':up.user,'password':fform.cleaned_data['password']},emails)
                    
                    create_message(request,"Successfully Registered.Your will be able to login once your account is  verified by the Insitute admin.")
                    
                    #Redirect to institute home
                    return HttpResponseRedirect("/")                          
                    
                else :
                    return render_to_response("institution/newmember.html",{'fform':fform,'sform':sform,'form_default':whichform},RequestContext(request))