def index(request): results = [] #Check if the first time they logged in student = get_student(request) if student == None: new = True else: new = False # Receive form data for first-time users if request.method == 'POST': sForm = ShortStudentForm(request.POST) pForm = ShortProfessorForm(request.POST) if 'student' in request.POST: if sForm.is_valid(): temp_post = sForm.save(commit=False) temp_post.netid = request.user.username temp_post.email = request.user.username + '@princeton.edu' temp_post.name = request.user.username temp_post.save() return HttpResponseRedirect('/') elif 'professor' in request.POST: if pForm.is_valid(): newprof = Professor(netid=request.user.username,research_areas=pForm.cleaned_data['research_areas'],department=pForm.cleaned_data['department'],email=request.user.username + '@princeton.edu', name=request.user.username) newprof.save() return HttpResponseRedirect('/') else: sForm = ShortStudentForm() pForm = ShortProfessorForm() # store department to change research areas displayed on search department = get_department(student) research_areas = get_research_areas(department) #if professor not yet approved, display moderation explanation form try: mod = Professor.unmoderated_objects.get(netid=request.user.username) context = {'results':results, 'research_areas':research_areas, 'new':new, 'sForm': sForm, 'pForm':pForm, 'student':student} return render_to_response('mod.html', context, context_instance=RequestContext(request)) except: context = {'results':results, 'research_areas':research_areas, 'new':new, 'sForm': sForm, 'pForm':pForm, 'student':student} return render_to_response('index.html', context, context_instance=RequestContext(request)) context = {'results':results, 'research_areas':research_areas, 'new':new, 'sForm': sForm, 'pForm':pForm, 'student':student} return render_to_response('index.html', context, context_instance=RequestContext(request))
# Full path to your django project directory your_djangoproject_home="/Users/Pallavi/COS_Archive/Classes/COS333/Project/" #your_djangoproject_home="C:/Users/Stephen/Documents/GitHub/purf/" import sys, os sys.path.append(your_djangoproject_home) os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' from purf_app.models import Professor, Project, Rating import csv profdataReader = csv.reader(open(csv_filepathname), dialect='excel-tab') projdataReader = csv.reader(open(csv_filepathname2), dialect='excel-tab') ratdataReader = csv.reader(open(csv_filepathname3), dialect='excel-tab') for i,row in enumerate(profdataReader): prof = Professor() prof.netid = row[0] prof.title = row[2] prof.office = row[6] prof.phone = row[7] prof.research_areas = row[9] prof.research_topics = row[10] prof.research_links = row[11] prof.description = row[13] prof.full = row[14] prof.name = row[1] prof.department = row[3] prof.email = row[5] prof.image = row[4]