本文整理汇总了Python中evap.evaluation.models.EmailTemplate类的典型用法代码示例。如果您正苦于以下问题:Python EmailTemplate类的具体用法?Python EmailTemplate怎么用?Python EmailTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EmailTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
def handle(self, *args, **options):
logger.info("send_reminders called.")
check_dates = []
# Collect end-dates of courses whose participants need to be reminded today.
for number_of_days in settings.REMIND_X_DAYS_AHEAD_OF_END_DATE:
check_dates.append(datetime.date.today() + datetime.timedelta(days=number_of_days))
recipients = set()
for course in Course.objects.filter(state="in_evaluation", vote_end_date__in=check_dates):
recipients.update(course.due_participants)
for recipient in recipients:
due_courses = dict()
for course in Course.objects.filter(participants=recipient, state="in_evaluation").exclude(
voters=recipient
):
due_courses[course] = (course.vote_end_date - datetime.date.today()).days
first_due_in_days = min(due_courses.values())
# Sort courses by number of days left for evaluation and bring them to following format:
# [(course, due_in_days), ...]
due_courses = sorted(due_courses.items(), key=operator.itemgetter(1))
EmailTemplate.send_reminder_to_user(recipient, first_due_in_days=first_due_in_days, due_courses=due_courses)
logger.info("send_reminders finished.")
logger.info("sent reminders to {} people.".format(len(recipients)))
示例2: send_publish_notifications
def send_publish_notifications(grade_document_courses=None, evaluation_results_courses=None):
grade_document_courses = grade_document_courses or []
evaluation_results_courses = evaluation_results_courses or []
publish_notifications = defaultdict(lambda: CourseLists(set(), set()))
for course in evaluation_results_courses:
# for published courses all contributors and participants get a notification
if course.can_publish_grades:
for participant in course.participants.all():
publish_notifications[participant].evaluation_results_courses.add(course)
for contribution in course.contributions.all():
if contribution.contributor:
publish_notifications[contribution.contributor].evaluation_results_courses.add(course)
# if a course was not published notifications are only sent for contributors who can see comments
elif len(course.textanswer_set) > 0:
for textanswer in course.textanswer_set:
if textanswer.contribution.contributor:
publish_notifications[textanswer.contribution.contributor].evaluation_results_courses.add(course)
publish_notifications[course.responsible_contributor].evaluation_results_courses.add(course)
for course in grade_document_courses:
# all participants who can download grades get a notification
for participant in course.participants.all():
if participant.can_download_grades:
publish_notifications[participant].grade_document_courses.add(course)
for user, course_lists in publish_notifications.items():
EmailTemplate.send_publish_notifications_to_user(
user,
grade_document_courses=list(course_lists.grade_document_courses),
evaluation_results_courses=list(course_lists.evaluation_results_courses)
)
示例3: index
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')
示例4: send
def send(self, request, courses):
recipient = self.cleaned_data.get('to')
self.template.subject = self.cleaned_data.get('subject')
self.template.body = self.cleaned_data.get('body')
subject_params = {}
body_params = {'user': recipient, 'courses': courses}
EmailTemplate.send_to_user(recipient, self.template, subject_params, body_params, use_cc=True, request=request)
示例5: send_publish_notifications
def send_publish_notifications(courses, template=None):
from evap.evaluation.models import EmailTemplate
publish_notifications = defaultdict(set)
if not template:
template = EmailTemplate.objects.get(name=EmailTemplate.PUBLISHING_NOTICE)
for course in courses:
# for published courses all contributors and participants get a notification
if course.can_publish_grades:
for participant in course.participants.all():
publish_notifications[participant].add(course)
for contribution in course.contributions.all():
if contribution.contributor:
publish_notifications[contribution.contributor].add(course)
# if a course was not published notifications are only sent for contributors who can see comments
elif len(course.textanswer_set) > 0:
for textanswer in course.textanswer_set:
if textanswer.contribution.contributor:
publish_notifications[textanswer.contribution.contributor].add(course)
for contributor in course.responsible_contributors:
publish_notifications[contributor].add(course)
for user, course_set in publish_notifications.items():
body_params = {'user': user, 'courses': list(course_set)}
EmailTemplate.send_to_user(user, template, {}, body_params, use_cc=True)
示例6: login_key_authentication
def login_key_authentication(request, key):
user = auth.authenticate(request, key=key)
if user and not user.is_active:
messages.error(request, _("Inactive users are not allowed to login."))
return redirect('evaluation:index')
# If we already have an authenticated user don't try to login a new user. Show an error message if another user
# tries to login with a URL in this situation.
if request.user.is_authenticated:
if user != request.user:
messages.error(request, _("Another user is currently logged in. Please logout first and then use the login URL again."))
return redirect('evaluation:index')
if user and user.login_key_valid_until >= date.today():
# User is valid. Set request.user and persist user in the session by logging the user in.
request.user = user
auth.login(request, user)
messages.success(request, _("Logged in as %s.") % user.full_name)
# Invalidate the login key, but keep it stored so we can later identify the user that is trying to login and send a new link
user.login_key_valid_until = date.today() - timedelta(1)
user.save()
elif user:
# A user exists, but the login key is not valid anymore. Send the user a new one.
user.ensure_valid_login_key()
EmailTemplate.send_login_url_to_user(user)
messages.warning(request, _("The login URL is not valid anymore. We sent you a new one to your email address."))
else:
messages.warning(request, _("Invalid login URL. Please request a new one below."))
return redirect('evaluation:index')
示例7: test_recipient_list_filtering
def test_recipient_list_filtering(self):
course = mommy.make(Course)
contributor1 = mommy.make(UserProfile)
contributor2 = mommy.make(UserProfile, delegates=[contributor1])
mommy.make(Contribution, course=course, contributor=contributor1)
mommy.make(Contribution, course=course, contributor=contributor2)
# no-one should get filtered.
recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.CONTRIBUTORS], filter_users_in_cc=False)
self.assertCountEqual(recipient_list, [contributor1, contributor2])
# contributor1 is in cc of contributor2 and gets filtered.
recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.CONTRIBUTORS], filter_users_in_cc=True)
self.assertCountEqual(recipient_list, [contributor2])
contributor3 = mommy.make(UserProfile, delegates=[contributor2])
mommy.make(Contribution, course=course, contributor=contributor3)
# again, no-one should get filtered.
recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.CONTRIBUTORS], filter_users_in_cc=False)
self.assertCountEqual(recipient_list, [contributor1, contributor2, contributor3])
# contributor1 is in cc of contributor2 and gets filtered.
# contributor2 is in cc of contributor3 but is not filtered since contributor1 wouldn't get an email at all then.
recipient_list = EmailTemplate.recipient_list_for_course(course, [EmailTemplate.CONTRIBUTORS], filter_users_in_cc=True)
self.assertCountEqual(recipient_list, [contributor2, contributor3])
示例8: semester_publish
def semester_publish(request, semester_id):
semester = get_object_or_404(Semester, id=semester_id)
courses = semester.course_set.filter(state="reviewed").all()
forms = helper_create_grouped_course_selection_forms(courses, None, request)
valid = helper_are_course_selection_forms_valid(forms)
for form in forms:
for course_id, field in form.fields.items():
course = Course.objects.get(pk=course_id)
field.label += " (graded)" if course.is_graded else " (not graded)"
if valid:
selected_courses = []
for form in forms:
for course in form.selected_courses:
course.publish()
course.save()
selected_courses.append(course)
messages.success(request, _("Successfully published %d courses.") % (len(selected_courses)))
for user, courses in user_publish_notifications(selected_courses).iteritems():
try:
EmailTemplate.get_publish_template().send_to_user(user, courses=list(courses))
except Exception:
messages.error(request, _("Could not send notification email to ") + user.username)
return redirect('evap.staff.views.semester_view', semester_id)
else:
return render(request, "staff_semester_publish.html", dict(semester=semester, forms=forms))
示例9: send_publish_notifications
def send_publish_notifications(courses, template=None):
from evap.evaluation.models import EmailTemplate
publish_notifications = defaultdict(set)
if not template:
template = EmailTemplate.objects.get(name=EmailTemplate.PUBLISHING_NOTICE)
for course in courses:
# for courses with published averaged grade, all contributors and participants get a notification
# we don't send a notification if the significance threshold isn't met
if course.can_publish_average_grade:
for participant in course.participants.all():
publish_notifications[participant].add(course)
for contribution in course.contributions.all():
if contribution.contributor:
publish_notifications[contribution.contributor].add(course)
# if the average grade was not published, notifications are only sent for contributors who can see text answers
elif course.textanswer_set:
for textanswer in course.textanswer_set:
if textanswer.contribution.contributor:
publish_notifications[textanswer.contribution.contributor].add(course)
for contributor in course.responsible_contributors:
publish_notifications[contributor].add(course)
for user, course_set in publish_notifications.items():
body_params = {'user': user, 'courses': list(course_set)}
EmailTemplate.send_to_user(user, template, {}, body_params, use_cc=True)
示例10: evaluation_direct_delegation
def evaluation_direct_delegation(request, evaluation_id):
delegate_user_id = request.POST.get("delegate_to")
evaluation = get_object_or_404(Evaluation, id=evaluation_id)
delegate_user = get_object_or_404(UserProfile, id=delegate_user_id)
contribution, created = Contribution.objects.update_or_create(evaluation=evaluation, contributor=delegate_user, defaults={'can_edit': True})
if created:
contribution.order = evaluation.contributions.all().aggregate(Max('order'))['order__max'] + 1
contribution.save()
template = EmailTemplate.objects.get(name=EmailTemplate.DIRECT_DELEGATION)
subject_params = {"evaluation": evaluation, "user": request.user, "delegate_user": delegate_user}
body_params = subject_params
# we don't provide the request here since send_to_user only uses it to display a warning message in case the user does not have
# an email address. In this special case, we don't want that warning. Instead, we want a mail to the admins.
EmailTemplate.send_to_user(delegate_user, template, subject_params, body_params, use_cc=True, additional_cc_user=request.user)
messages.add_message(
request,
messages.SUCCESS,
_('{} was added as a contributor for evaluation "{}" and was sent an email with further information.').format(str(delegate_user), str(evaluation))
)
return redirect('contributor:index')
示例11: CourseEmailForm
class CourseEmailForm(forms.Form, BootstrapMixin):
recipients = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), choices=EMAIL_RECIPIENTS, label=_("Send email to"))
subject = forms.CharField(label=_("Subject"))
body = forms.CharField(widget=forms.Textarea(), label=_("Message"))
def __init__(self, *args, **kwargs):
self.instance = kwargs.pop('instance')
self.template = EmailTemplate()
super(CourseEmailForm, self).__init__(*args, **kwargs)
def clean(self):
self.recipient_groups = self.cleaned_data.get('recipients')
if not self.recipient_groups:
raise forms.ValidationError(_(u"No recipient selected. Choose at least one group of recipients."))
return self.cleaned_data
# returns whether all recepients have an email address
def all_recepients_reachable(self):
return self.missing_email_addresses() == 0
# returns the number of recepients without an email address
def missing_email_addresses(self):
recipients = self.template.recipient_list_for_course(self.instance, self.recipient_groups)
return len([user for user in recipients if not user.email])
def send(self):
self.template.subject = self.cleaned_data.get('subject')
self.template.body = self.cleaned_data.get('body')
self.template.send_to_users_in_courses([self.instance], self.recipient_groups)
示例12: helper_semester_course_operation_prepare
def helper_semester_course_operation_prepare(request, courses, send_email):
for course in courses:
course.ready_for_editors()
course.save()
messages.success(request, ungettext("Successfully enabled %(courses)d course for editor review.",
"Successfully enabled %(courses)d courses for editor review.", len(courses)) % {'courses': len(courses)})
if send_email:
EmailTemplate.send_review_notifications(courses)
示例13: test_no_login_url_when_cc_users_in_cc
def test_no_login_url_when_cc_users_in_cc(self):
self.user.cc_users.add(self.other_user)
EmailTemplate.send_to_users_in_courses(self.template, [self.course], [EmailTemplate.CONTRIBUTORS], use_cc=True)
self.assertEqual(len(mail.outbox), 2)
self.assertFalse("loginkey" in mail.outbox[0].body) # message does not contain the login url
self.assertTrue("loginkey" in mail.outbox[1].body) # separate email with login url was sent
self.assertEqual(len(mail.outbox[1].cc), 0)
self.assertEqual(mail.outbox[1].to, [self.user.email])
示例14: test_missing_email_address
def test_missing_email_address(self):
"""
Tests that __send_to_user behaves when the user has no email address.
Regression test to https://github.com/fsr-itse/EvaP/issues/825
"""
user = mommy.make(UserProfile, email=None)
template = EmailTemplate.objects.get(name=EmailTemplate.STUDENT_REMINDER)
EmailTemplate._EmailTemplate__send_to_user(user, template, {}, {}, False, None)
示例15: helper_semester_course_operation_start
def helper_semester_course_operation_start(request, courses, send_email):
for course in courses:
course.vote_start_date = datetime.date.today()
course.evaluation_begin()
course.save()
messages.success(request, ungettext("Successfully started evaluation for %(courses)d course.",
"Successfully started evaluation for %(courses)d courses.", len(courses)) % {'courses': len(courses)})
if send_email:
EmailTemplate.send_evaluation_started_notifications(courses)