本文整理汇总了Python中evap.evaluation.models.UserProfile类的典型用法代码示例。如果您正苦于以下问题:Python UserProfile类的具体用法?Python UserProfile怎么用?Python UserProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserProfile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_courses
def send_courses(self, courses, send_to_editors=False, send_to_contributors=False, send_to_due_participants=False, send_to_all_participants=False):
from evap.evaluation.models import UserProfile
# pivot course-user relationship
user_course_map = {}
for course in courses:
for user in [user for user in self.recipient_list_for_course(course, send_to_editors, send_to_contributors, send_to_due_participants, send_to_all_participants) if user.email != ""]:
if user in user_course_map:
user_course_map[user].append(course)
else:
user_course_map[user] = [course]
# send emails on a per user basis
for user, courses in user_course_map.iteritems():
cc = []
for course in courses:
# if email will be sent to editors, also send to all their delegates in CC
if send_to_editors:
if course.contributions.filter(can_edit=True, contributor=user).exists():
cc.extend([p.email for p in UserProfile.get_for_user(user).delegates.all() if p.email])
break
# send email to all cc users of the current user
cc.extend([p.email for p in UserProfile.get_for_user(user).cc_users.all() if p.email])
mail = EmailMessage(
subject = self.render_string(self.subject, {'user': user, 'courses': courses}),
body = self.render_string(self.body, {'user': user, 'courses': courses}),
to = [user.email],
cc = cc,
bcc = [a[1] for a in settings.MANAGERS],
headers = {'Reply-To': settings.REPLY_TO_EMAIL})
mail.send(False)
示例2: user_index
def user_index(request):
users = User.objects.order_by("last_name", "first_name", "username")
filter = request.GET.get('filter')
if filter == "fsr":
users = users.filter(is_staff=True)
elif filter == "responsibles":
users = [user for user in users if UserProfile.get_for_user(user).is_responsible]
elif filter == "delegates":
users = [user for user in users if UserProfile.get_for_user(user).is_delegate]
return render_to_response("fsr_user_index.html", dict(users=users, filter=filter), context_instance=RequestContext(request))
示例3: clean_email
def clean_email(self):
email = self.cleaned_data.get('email')
if not UserProfile.email_needs_login_key(email):
raise forms.ValidationError(_(u"HPI users cannot request login keys. Please login using your domain credentials."))
try:
user = User.objects.get(email__iexact=email)
self.user_cache = user
self.profile_cache = UserProfile.get_for_user(user)
except User.DoesNotExist:
raise forms.ValidationError(_(u"No user with this email address was found. Please make sure to enter the email address already known to the university office."))
return email
示例4: validate
def validate(self):
user = UserProfile()
user.username = self.username
user.first_name = self.first_name
user.last_name = self.last_name
user.email = self.email
user.password = "asdf" # clean_fields needs that...
user.clean_fields()
示例5: handle
def handle(self, *args, **options):
try:
# Get a username
username = read_value('Username: ', is_valid_username)
# Get an email
email = read_value('Email address: ', is_valid_email)
# Get password if it should be set
password = read_value_hidden('Password: ', lambda x: True) if options["has_password"] else None
# get fsr flag
is_fsr = True if read_value("Is FSR member (yes/no): ", is_valid_bool_answer) in ['Yes', 'yes'] else False
# create user
user = User.objects.create(username=username, email=email, is_staff=is_fsr, is_superuser=is_fsr)
if not password is None:
user.set_password(password)
user.save()
profile = UserProfile.get_for_user(user)
profile.save()
except KeyboardInterrupt:
sys.stderr.write("\nOperation cancelled.\n")
sys.exit(1)
示例6: save
def save(self, *args, **kw):
# first save the user, so that the profile gets created for sure
self.instance.user.first_name = self.cleaned_data.get('first_name')
self.instance.user.last_name = self.cleaned_data.get('last_name')
self.instance.user.email = self.cleaned_data.get('email')
self.instance.user.save()
self.instance = UserProfile.get_for_user(self.instance.user)
super(UserForm, self).save(*args, **kw)
示例7: store_in_database
def store_in_database(self):
user = User(username=self.username,
first_name=self.first_name,
last_name=self.last_name,
email=self.email)
user.save()
profile = UserProfile.get_for_user(user=user)
profile.title = self.title
profile.save()
return user
示例8: user_edit
def user_edit(request, user_id):
user = get_object_or_404(User, id=user_id)
form = UserForm(request.POST or None, request.FILES or None, instance=UserProfile.get_for_user(user))
if form.is_valid():
form.save()
messages.success(request, _("Successfully updated user."))
return redirect('evap.fsr.views.user_index')
else:
return render_to_response("fsr_user_form.html", dict(form=form, object=user), context_instance=RequestContext(request))
示例9: user_delete
def user_delete(request, user_id):
user = get_object_or_404(User, id=user_id)
if UserProfile.get_for_user(user).can_fsr_delete:
if request.method == 'POST':
user.delete()
return redirect('evap.fsr.views.user_index')
else:
return render_to_response("fsr_user_delete.html", dict(user=user), context_instance=RequestContext(request))
else:
messages.add_message(request, messages.ERROR, _("The user '%s' cannot be deleted, because he lectures courses.") % UserProfile.get_for_user(user).full_name)
return redirect('evap.fsr.views.user_index')
示例10: test_login_key
def test_login_key(self):
environ = self.app.extra_environ
self.app.extra_environ = {}
self.assertRedirects(self.app.get(reverse("evap.results.views.index"), extra_environ={}), "/?next=/results/")
self.app.extra_environ = environ
user = User.objects.all()[0]
userprofile = UserProfile.get_for_user(user)
userprofile.generate_login_key()
userprofile.save()
url_with_key = reverse("evap.results.views.index") + "?userkey=%s" % userprofile.login_key
self.app.get(url_with_key)
示例11: _post_clean
def _post_clean(self, *args, **kw):
# first save the user, so that the profile gets created for sure
self.instance.user.username = self.cleaned_data.get('username')
self.instance.user.first_name = self.cleaned_data.get('first_name')
self.instance.user.last_name = self.cleaned_data.get('last_name')
self.instance.user.email = self.cleaned_data.get('email')
self.instance.user.is_staff = self.cleaned_data.get('is_staff')
self.instance.user.is_superuser = self.cleaned_data.get('is_superuser')
self.instance.user.save()
self.instance.user.represented_users = self.cleaned_data.get('represented_users')
self.instance = UserProfile.get_for_user(self.instance.user)
super(UserForm, self)._post_clean(*args, **kw)
示例12: get_user_profile_object
def get_user_profile_object(self):
user = UserProfile()
user.username = self.username
user.first_name = self.first_name
user.last_name = self.last_name
user.email = self.email
user.password = "asdf" # clean_fields needs that...
return user
示例13: create_contributor_questionnaires
def create_contributor_questionnaires(form_groups_items):
contributor_questionnaires = []
errors = []
for contribution, form_group in form_groups_items:
if contribution.is_general:
continue
contributor = contribution.contributor
user_profile = UserProfile.get_for_user(contributor)
contributor_questionnaires.append((user_profile, form_group.values()));
if any(form.errors for form in form_group.values()):
errors.append(contributor.id)
return contributor_questionnaires, errors
示例14: clean_email
def clean_email(self):
email = self.cleaned_data.get('email')
if not UserProfile.email_needs_login_key(email):
raise forms.ValidationError(_("HPI users cannot request login keys. Please login using your domain credentials."))
try:
user = UserProfile.objects.get(email__iexact=email)
self.user_cache = user
except UserProfile.DoesNotExist:
raise forms.ValidationError(_("No user with this email address was found. Please make sure to enter the email address used for course or event registration."))
if not user.is_active:
raise forms.ValidationError(_("Inactive users cannot request login keys."))
return email
示例15: update
def update(self, user):
profile = UserProfile.get_for_user(user=user)
if not user.first_name:
user.first_name = self.first_name
if not user.last_name:
user.last_name = self.last_name
if not user.email:
user.email = self.email
if not profile.title:
profile.title = self.title
if profile.needs_login_key:
profile.refresh_login_key()
user.save()
profile.save()