本文整理汇总了Python中evap.evaluation.models.Semester.active_semester方法的典型用法代码示例。如果您正苦于以下问题:Python Semester.active_semester方法的具体用法?Python Semester.active_semester怎么用?Python Semester.active_semester使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类evap.evaluation.models.Semester
的用法示例。
在下文中一共展示了Semester.active_semester方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def index(request):
"""Main entry page into EvaP providing all the login options available. The username/password
login is thought to be used for internal users, e.g. by connecting to a LDAP directory.
The login key mechanism is meant to be used to include external participants, e.g. visiting
students or visiting contributors.
"""
# parse the form data into the respective form
submit_type = request.POST.get("submit_type", "no_submit")
new_key_form = NewKeyForm(request.POST if submit_type == "new_key" else None)
login_username_form = LoginUsernameForm(request, request.POST if submit_type == "login_username" else None)
# process form data
if request.method == 'POST':
if new_key_form.is_valid():
# user wants a new login key
profile = new_key_form.get_user()
profile.ensure_valid_login_key()
profile.save()
EmailTemplate.send_login_url_to_user(new_key_form.get_user())
messages.success(request, _("We sent you an email with a one-time login URL. Please check your inbox."))
return redirect('evaluation:index')
elif login_username_form.is_valid():
# user would like to login with username and password and passed password test
auth.login(request, login_username_form.get_user())
# clean up our test cookie
if request.session.test_cookie_worked():
request.session.delete_test_cookie()
# if not logged in by now, render form
if not request.user.is_authenticated:
# set test cookie to verify whether they work in the next step
request.session.set_test_cookie()
template_data = dict(new_key_form=new_key_form, login_username_form=login_username_form)
return render(request, "index.html", template_data)
else:
user, __ = UserProfile.objects.get_or_create(username=request.user.username)
# check for redirect variable
redirect_to = request.GET.get("next", None)
if redirect_to is not None:
return redirect(redirect_to)
# redirect user to appropriate start page
if request.user.is_reviewer:
return redirect('staff:semester_view', Semester.active_semester().id)
if request.user.is_manager:
return redirect('staff:index')
elif request.user.is_grade_publisher:
return redirect('grades:semester_view', Semester.active_semester().id)
elif user.is_student:
return redirect('student:index')
elif user.is_contributor_or_delegate:
return redirect('contributor:index')
else:
return redirect('results:index')
示例2: __init__
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
courses_of_current_semester = Course.objects.filter(semester=Semester.active_semester())
excludes = [x.id for x in courses_of_current_semester if x.is_single_result()]
courses_of_current_semester = courses_of_current_semester.exclude(id__in=excludes)
self.fields['courses_participating_in'].queryset = courses_of_current_semester
self.fields['courses_participating_in'].initial = courses_of_current_semester.filter(participants=self.instance) if self.instance.pk else ()
self.fields['courses_participating_in'].label = _("Courses participating in (active semester)")
self.fields['courses_participating_in'].required = False
示例3: __init__
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
courses_in_active_semester = Course.objects.filter(semester=Semester.active_semester())
excludes = [x.id for x in courses_in_active_semester if x.is_single_result()]
courses_in_active_semester = courses_in_active_semester.exclude(id__in=excludes)
self.fields['courses_participating_in'].queryset = courses_in_active_semester
if self.instance.pk:
self.fields['courses_participating_in'].initial = courses_in_active_semester.filter(participants=self.instance)
self.fields['is_staff'].initial = self.instance.is_staff
self.fields['is_grade_user'].initial = self.instance.is_grade_publisher
示例4: clean_courses_participating_in
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def clean_courses_participating_in(self):
courses_participating_in = self.cleaned_data.get('courses_participating_in')
if self.instance.pk:
courses_voted_for = self.instance.courses_voted_for.filter(semester=Semester.active_semester())
removed_courses_voted_for = set(courses_voted_for) - set(courses_participating_in)
if removed_courses_voted_for:
names = [str(course) for course in removed_courses_voted_for]
self.add_error("courses_participating_in", _("Courses for which the user already voted can't be removed: %s") % ", ".join(names))
return courses_participating_in
示例5: user_edit
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def user_edit(request, user_id):
user = get_object_or_404(UserProfile, id=user_id)
form = UserForm(request.POST or None, request.FILES or None, instance=user)
courses_contributing_to = Course.objects.filter(semester=Semester.active_semester(), contributions__contributor=user)
if form.is_valid():
form.save()
messages.success(request, _("Successfully updated user."))
return redirect('staff:user_index')
else:
return render(request, "staff_user_form.html", dict(form=form, object=user, courses_contributing_to=courses_contributing_to))
示例6: __init__
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
evaluations_in_active_semester = Evaluation.objects.filter(course__semester=Semester.active_semester())
excludes = [x.id for x in evaluations_in_active_semester if x.is_single_result]
evaluations_in_active_semester = evaluations_in_active_semester.exclude(id__in=excludes)
self.fields['evaluations_participating_in'].queryset = evaluations_in_active_semester
if self.instance.pk:
self.fields['evaluations_participating_in'].initial = evaluations_in_active_semester.filter(participants=self.instance)
self.fields['is_manager'].initial = self.instance.is_manager
self.fields['is_grade_publisher'].initial = self.instance.is_grade_publisher
self.fields['is_reviewer'].initial = self.instance.is_reviewer
self.fields['is_inactive'].initial = not self.instance.is_active
示例7: __init__
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
all_users = UserProfile.objects.all()
# fix generated form
self.fields['delegates'].required = False
self.fields['delegates'].queryset = all_users
self.fields['cc_users'].required = False
self.fields['cc_users'].queryset = all_users
courses_of_current_semester = Course.objects.filter(semester=Semester.active_semester())
self.fields['courses_participating_in'].queryset = courses_of_current_semester
self.fields['courses_participating_in'].initial = courses_of_current_semester.filter(participants=self.instance) if self.instance.pk else ()
self.fields['courses_participating_in'].label = _("Courses participating in (active semester)")
self.fields['courses_participating_in'].required = False
示例8: save
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def save(self, *args, **kw):
super().save(*args, **kw)
self.instance.course_set = list(self.instance.course_set.exclude(semester=Semester.active_semester())) + list(self.cleaned_data.get('courses_participating_in'))
staff_group = Group.objects.get(name="Staff")
grade_user_group = Group.objects.get(name="Grade publisher")
if self.cleaned_data.get('is_staff'):
self.instance.groups.add(staff_group)
else:
self.instance.groups.remove(staff_group)
if self.cleaned_data.get('is_grade_user'):
self.instance.groups.add(grade_user_group)
else:
self.instance.groups.remove(grade_user_group)
示例9: __init__
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def __init__(self, *args, **kwargs):
super(UserForm, self).__init__(*args, **kwargs)
all_users = UserProfile.objects.order_by('username')
# fix generated form
self.fields['delegates'].required = False
self.fields['delegates'].queryset = all_users
self.fields['delegates'].help_text = ""
self.fields['cc_users'].required = False
self.fields['cc_users'].queryset = all_users
self.fields['cc_users'].help_text = ""
courses_of_current_semester = Course.objects.filter(semester=Semester.active_semester())
self.fields['courses_participating_in'] = forms.ModelMultipleChoiceField(courses_of_current_semester,
initial=courses_of_current_semester.filter(participants=self.instance) if self.instance.pk else (),
label=_("Courses participating in (active semester)"),
help_text="",
required=False)
self.fields['courses_participating_in'].help_text = ""
示例10: save
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def save(self, *args, **kw):
super().save(*args, **kw)
self.instance.course_set = list(self.instance.course_set.exclude(semester=Semester.active_semester())) + list(self.cleaned_data.get('courses_participating_in'))
示例11: save
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def save(self, *args, **kw):
super().save(*args, **kw)
new_course_list = list(self.instance.courses_participating_in.exclude(semester=Semester.active_semester())) + list(self.cleaned_data.get('courses_participating_in'))
self.instance.courses_participating_in.set(new_course_list)
staff_group = Group.objects.get(name="Staff")
grade_publisher_group = Group.objects.get(name="Grade publisher")
reviewer_group = Group.objects.get(name="Reviewer")
if self.cleaned_data.get('is_staff'):
self.instance.groups.add(staff_group)
else:
self.instance.groups.remove(staff_group)
if self.cleaned_data.get('is_grade_publisher'):
self.instance.groups.add(grade_publisher_group)
else:
self.instance.groups.remove(grade_publisher_group)
if self.cleaned_data.get('is_reviewer') and not self.cleaned_data.get('is_staff'):
self.instance.groups.add(reviewer_group)
else:
self.instance.groups.remove(reviewer_group)
self.instance.is_active = not self.cleaned_data.get('is_inactive')
self.instance.save()
示例12: clean_evaluations_participating_in
# 需要导入模块: from evap.evaluation.models import Semester [as 别名]
# 或者: from evap.evaluation.models.Semester import active_semester [as 别名]
def clean_evaluations_participating_in(self):
evaluations_participating_in = self.cleaned_data.get('evaluations_participating_in')
if self.instance.pk:
evaluations_voted_for = self.instance.evaluations_voted_for.filter(course__semester=Semester.active_semester())
removed_evaluations_voted_for = set(evaluations_voted_for) - set(evaluations_participating_in)
if removed_evaluations_voted_for:
names = [str(evaluation) for evaluation in removed_evaluations_voted_for]
self.add_error("evaluations_participating_in", _("Evaluations for which the user already voted can't be removed: %s") % ", ".join(names))
return evaluations_participating_in