def bio_edit_user_program(request, founduser, foundprogram, external=False): """ Edits a teacher bio, given user and program """ if founduser is None: if external: raise ESPError(), 'No user given.' else: raise Http404 if not founduser.isTeacher(): raise ESPError(False), '%s is not a teacher of ESP.' % \ (founduser.name()) if request.user.id != founduser.id and request.user.is_staff != True: raise ESPError(False), 'You are not authorized to edit this biography.' lastbio = TeacherBio.getLastBio(founduser) # if we submitted a newly edited bio... from esp.web.forms.bioedit_form import BioEditForm if request.method == 'POST' and request.POST.has_key('bio_submitted'): form = BioEditForm(request.POST, request.FILES) if form.is_valid(): if foundprogram is not None: # get the last bio for this program. progbio = TeacherBio.getLastForProgram(founduser, foundprogram) else: progbio = lastbio # the slug bio and bio progbio.slugbio = form.cleaned_data['slugbio'] progbio.bio = form.cleaned_data['bio'] progbio.save() # save the image if form.cleaned_data['picture'] is not None: progbio.picture = form.cleaned_data['picture'] else: progbio.picture = lastbio.picture progbio.save() if external: return True return HttpResponseRedirect(progbio.url()) else: formdata = { 'slugbio': lastbio.slugbio, 'bio': lastbio.bio, 'picture': lastbio.picture } form = BioEditForm(formdata) return render_to_response( 'users/teacherbioedit.html', request, GetNode('Q/Web/myesp'), { 'form': form, 'institution': settings.INSTITUTION_NAME, 'user': founduser, 'picture_file': lastbio.picture })
def bio_edit_user_program(request, founduser, foundprogram, external=False, old_url=False): """ Edits a teacher bio, given user and program """ if founduser is None or not founduser.isTeacher(): return bio_not_found(request) if request.user.id != founduser.id and not request.user.isAdministrator(): # To prevent querying whether a username exists, just return not found # here as well. return bio_not_found(request) lastbio = TeacherBio.getLastBio(founduser) if old_url: # TODO(benkraft): after these URLs have been redirecting for a while, # remove them. return HttpResponsePermanentRedirect(lastbio.edit_url()) # if we submitted a newly edited bio... from esp.web.forms.bioedit_form import BioEditForm if request.method == 'POST' and 'bio_submitted' in request.POST: form = BioEditForm(request.POST, request.FILES) if form.is_valid(): if foundprogram is not None: # get the last bio for this program. progbio = TeacherBio.getLastForProgram(founduser, foundprogram) else: progbio = lastbio progbio.hidden = form.cleaned_data['hidden'] # the slug bio and bio progbio.slugbio = form.cleaned_data['slugbio'] progbio.bio = form.cleaned_data['bio'] progbio.save() # save the image if form.cleaned_data['picture'] is not None: progbio.picture = form.cleaned_data['picture'] else: progbio.picture = lastbio.picture progbio.save() if external: return True return HttpResponseRedirect(progbio.url()) else: formdata = {'hidden': lastbio.hidden, 'slugbio': lastbio.slugbio, 'bio': lastbio.bio, 'picture': lastbio.picture} form = BioEditForm(formdata) return render_to_response('users/teacherbioedit.html', request, {'form': form, 'institution': settings.INSTITUTION_NAME, 'user': founduser, 'picture_file': lastbio.picture})
def userview(request): """ Render a template displaying all the information about the specified user """ try: user = ESPUser.objects.get(username=request.GET['username']) except: raise ESPError(False), "Sorry, can't find anyone with that username." teacherbio = TeacherBio.getLastBio(user) if not teacherbio.picture: teacherbio.picture = 'images/not-available.jpg' from esp.users.forms.user_profile import StudentInfoForm if 'graduation_year' in request.GET: student_info = user.getLastProfile().student_info student_info.graduation_year = int(request.GET['graduation_year']) student_info.save() change_grade_form = StudentInfoForm(user=user) if 'disabled' in change_grade_form.fields['graduation_year'].widget.attrs: del change_grade_form.fields['graduation_year'].widget.attrs['disabled'] change_grade_form.fields['graduation_year'].initial = ESPUser.YOGFromGrade(user.getGrade()) change_grade_form.fields['graduation_year'].choices = filter(lambda choice: bool(choice[0]), change_grade_form.fields['graduation_year'].choices) context = { 'user': user, 'taught_classes' : user.getTaughtClasses().order_by('parent_program', 'id'), 'enrolled_classes' : user.getEnrolledSections().order_by('parent_class__parent_program', 'id'), 'taken_classes' : user.getSections().order_by('parent_class__parent_program', 'id'), 'teacherbio': teacherbio, 'domain': settings.SITE_INFO[1], 'change_grade_form': change_grade_form, } return render_to_response("users/userview.html", request, context )
def userview(request): """ Render a template displaying all the information about the specified user """ try: user = ESPUser.objects.get(username=request.GET['username']) except: raise ESPError("Sorry, can't find anyone with that username.", log=False) teacherbio = TeacherBio.getLastBio(user) if not teacherbio.picture: teacherbio.picture = 'images/not-available.jpg' from esp.users.forms.user_profile import StudentInfoForm if 'graduation_year' in request.GET: user.set_student_grad_year(request.GET['graduation_year']) change_grade_form = StudentInfoForm(user=user) if 'disabled' in change_grade_form.fields['graduation_year'].widget.attrs: del change_grade_form.fields['graduation_year'].widget.attrs['disabled'] change_grade_form.fields['graduation_year'].initial = user.getYOG() change_grade_form.fields['graduation_year'].choices = filter(lambda choice: bool(choice[0]), change_grade_form.fields['graduation_year'].choices) context = { 'user': user, 'taught_classes' : user.getTaughtClasses().order_by('parent_program', 'id'), 'enrolled_classes' : user.getEnrolledSections().order_by('parent_class__parent_program', 'id'), 'taken_classes' : user.getSections().order_by('parent_class__parent_program', 'id'), 'teacherbio': teacherbio, 'domain': settings.SITE_INFO[1], 'change_grade_form': change_grade_form, 'printers': StudentRegCore.printer_names(), } return render_to_response("users/userview.html", request, context )
def userview(request): """ Render a template displaying all the information about the specified user """ try: user = ESPUser.objects.get(username=request.GET['username']) except ESPUser.DoesNotExist: raise ESPError("Sorry, can't find anyone with that username.", log=False) if 'program' in request.GET: try: program = Program.objects.get(id=request.GET['program']) except Program.DoesNotExist: raise ESPError("Sorry, can't find that program.", log=False) else: program = user.get_last_program_with_profile() teacherbio = TeacherBio.getLastBio(user) if not teacherbio.picture: teacherbio.picture = 'images/not-available.jpg' from esp.users.forms.user_profile import StudentInfoForm if 'graduation_year' in request.GET: user.set_student_grad_year(request.GET['graduation_year']) change_grade_form = StudentInfoForm(user=user) if 'disabled' in change_grade_form.fields['graduation_year'].widget.attrs: del change_grade_form.fields['graduation_year'].widget.attrs[ 'disabled'] change_grade_form.fields['graduation_year'].initial = user.getYOG() change_grade_form.fields['graduation_year'].choices = filter( lambda choice: bool(choice[0]), change_grade_form.fields['graduation_year'].choices) context = { 'user': user, 'taught_classes': user.getTaughtClasses().order_by('parent_program', 'id'), 'enrolled_classes': user.getEnrolledSections().order_by('parent_class__parent_program', 'id'), 'taken_classes': user.getSections().order_by('parent_class__parent_program', 'id'), 'teacherbio': teacherbio, 'domain': settings.SITE_INFO[1], 'change_grade_form': change_grade_form, 'printers': StudentRegCore.printer_names(), 'all_programs': Program.objects.all().order_by('-id'), 'program': program, } return render_to_response("users/userview.html", request, context)
def bio_user(request, founduser): """ Display a teacher bio for a given user """ if founduser is None: raise Http404 if founduser.is_active == False: raise Http404 if not founduser.isTeacher(): raise ESPError(False), '%s is not a teacher of ESP.' % \ (founduser.name()) teacherbio = TeacherBio.getLastBio(founduser) if not teacherbio.picture: teacherbio.picture = 'images/not-available.jpg' if teacherbio.slugbio is None or len(teacherbio.slugbio.strip()) == 0: teacherbio.slugbio = 'ESP Teacher' if teacherbio.bio is None or len(teacherbio.bio.strip()) == 0: teacherbio.bio = 'Not Available.' now = datetime.now() # Only show classes that were approved and that have already run # If we show classes that are yet to run, it's possible that # the corresponding course catalog isn't up yet, in which case # the teacher-bio pages leak information. # Also, sort by the order of the corresponding program's DataTree node. # This should roughly order by program date; at the least, it will # cluster listed classes by program. recent_classes = founduser.getTaughtClassesAll( ).filter(status__gte=10).exclude(meeting_times__end__gte=now).exclude( sections__meeting_times__end__gte=datetime.now()).filter( sections__resourceassignment__resource__res_type__name="Classroom" ).order_by('-anchor__parent__parent__id') # Ignore archived classes where we still have a log of the original class # Archives lose information; so, display the original form if we still have it cls_ids = [x.id for x in recent_classes] classes = ArchiveClass.getForUser(founduser).exclude( original_id__in=cls_ids) return render_to_response( 'users/teacherbio.html', request, GetNode('Q/Web/Bio'), { 'biouser': founduser, 'bio': teacherbio, 'classes': classes, 'recent_classes': recent_classes, 'institution': settings.INSTITUTION_NAME })
def bio_user(request, founduser, old_url=False): """ Display a teacher bio for a given user """ if (not founduser or not founduser.is_active or not founduser.isTeacher()): return bio_not_found(request) teacherbio = TeacherBio.getLastBio(founduser) if teacherbio.hidden: return bio_not_found(request, founduser, teacherbio.edit_url()) if old_url: # TODO(benkraft): after these URLs have been redirecting for a while, # remove them. return HttpResponsePermanentRedirect(teacherbio.url()) if not teacherbio.picture: teacherbio.picture = 'images/not-available.jpg' if teacherbio.slugbio is None or len(teacherbio.slugbio.strip()) == 0: teacherbio.slugbio = 'ESP Teacher' if teacherbio.bio is None or len(teacherbio.bio.strip()) == 0: teacherbio.bio = 'Not Available.' now = datetime.now() # Only show classes that were approved and that have already run # If we show classes that are yet to run, it's possible that # the corresponding course catalog isn't up yet, in which case # the teacher-bio pages leak information. # Also, sort by the order of the corresponding program's id. # This should roughly order by program date; at the least, it will # cluster listed classes by program. recent_classes = founduser.getTaughtClassesAll().filter(status__gte=10).exclude(meeting_times__end__gte=now).exclude(sections__meeting_times__end__gte=now).filter(sections__resourceassignment__resource__res_type__name="Classroom").distinct().order_by('-parent_program__id') # Ignore archived classes where we still have a log of the original class # Archives lose information; so, display the original form if we still have it cls_ids = [x.id for x in recent_classes] classes = ArchiveClass.getForUser(founduser).exclude(original_id__in=cls_ids) return render_to_response('users/teacherbio.html', request, {'biouser': founduser, 'bio': teacherbio, 'classes': classes, 'recent_classes': recent_classes, 'institution': settings.INSTITUTION_NAME})
def isCompleted(self): # TeacherBio.getLastForProgram() returns a new bio if one already exists. # So, mark this step completed if there is an existing (i.e. non-empty) bio. lastBio = TeacherBio.getLastForProgram(get_current_request().user, self.program) return ((lastBio.id is not None) and lastBio.bio and lastBio.slugbio)