def __init__(self, request, course=None, course_instance=None, **dict): RequestContext.__init__(self, request, dict) # Initially the user is neither an assistant nor a teacher is_assistant = False is_teacher = False # If the course is not given, but an instance is, get the instance's course if course == None and course_instance != None: course = course_instance.course if request.user.is_authenticated(): # If the user is authenticated, populate is_assistant and is_teacher fields profile = request.user.get_profile() if course != None and course.is_teacher(profile): # Teachers are also allowed to act as assistants is_teacher = True is_assistant = True elif course_instance != None and course_instance.is_assistant(profile): is_assistant = True course_info = {"is_teacher": is_teacher, "is_assistant": is_assistant, "instance": course_instance, "course": course, } self.update(course_info)
def __init__(self, request, course=None, course_instance=None, **dict): RequestContext.__init__(self, request, dict) # Initially the user is neither an assistant nor a teacher is_assistant = False is_teacher = False # If the course is not given, but an instance is, get the instance's course if course == None and course_instance != None: course = course_instance.course if request.user.is_authenticated(): # If the user is authenticated, populate is_assistant and is_teacher fields profile = request.user.get_profile() if course != None and course.is_teacher(profile): # Teachers are also allowed to act as assistants is_teacher = True is_assistant = True elif course_instance != None and course_instance.is_assistant( profile): is_assistant = True course_info = { "is_teacher": is_teacher, "is_assistant": is_assistant, "instance": course_instance, "course": course, } self.update(course_info)
def __init__(self, request, dictionary = None, current_project = None, current_story = None): self.request = request if request.user.is_authenticated(): project_list = request.user.project_set.all() if project_list is None or project_list.count() == 0: raise UserHasNoProjectException else: raise UserHasNoProjectException if current_project is None: current_project = project_list[0] else: current_project = Project.objects.get(pk = current_project) if current_story is not None: try: current_story = UserStory.objects.get(id = current_story) except UserStory.DoesNotExist: current_story = None if dictionary is None: self.dictionary = { 'project_list' : project_list, 'current_project' : current_project, 'current_story': current_story, 'last_page': request.path, } else: self.dictionary = dictionary self.dictionary['project_list'] = project_list self.dictionary['current_project'] = current_project self.dictionary['current_story'] = current_story self.dictionary['last_page'] = request.path RequestContext.__init__(self, self.request, self.dictionary)
def __init__(self, request, dict=None, processors=None, current_app=None, use_l10n=None): # 此处继承沿袭了RequestContext 的深度继承方式 self.processors = [] if not processors else processors self.processors.extend(self.get_processors()) RequestContext.__init__(self, request, dict, self.processors, current_app, use_l10n)
def __init__(self, request, course=None, course_instance=None, **dict): RequestContext.__init__(self, request, dict) # Initially the user is neither an assistant nor a teacher is_assistant = False is_teacher = False # If the course is not given, but an instance is, get the instance's course if course == None and course_instance != None: course = course_instance.course if request.user.is_authenticated(): # If the user is authenticated, populate is_assistant and is_teacher fields profile = request.user.get_profile() if course != None and course.is_teacher(profile): # Teachers are also allowed to act as assistants is_teacher = True is_assistant = True elif course_instance != None and course_instance.is_assistant(profile): is_assistant = True course_info = {"is_teacher": is_teacher, "is_assistant": is_assistant, "instance": course_instance, "course": course, } self.update(course_info) # TODO: # For some reason, request is not available in this context even though # it should be. Thus temporarily adding it manually. self.update({"request": request})
def __init__(self, request, dict=None, processors=None, current_app=None, use_l10n=None): dict['menu_list'] = getMenuItems(request) RequestContext.__init__(self, request, dict, processors, current_app=current_app, use_l10n=use_l10n)