当前位置: 首页>>代码示例>>Python>>正文


Python UserProfile.get_for_user方法代码示例

本文整理汇总了Python中evap.evaluation.models.UserProfile.get_for_user方法的典型用法代码示例。如果您正苦于以下问题:Python UserProfile.get_for_user方法的具体用法?Python UserProfile.get_for_user怎么用?Python UserProfile.get_for_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在evap.evaluation.models.UserProfile的用法示例。


在下文中一共展示了UserProfile.get_for_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_courses

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
    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)
开发者ID:Bartzi,项目名称:EvaP,代码行数:34,代码来源:models.py

示例2: user_index

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
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))
开发者ID:sebastianoe,项目名称:EvaP,代码行数:14,代码来源:views.py

示例3: handle

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
 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)
开发者ID:02strich,项目名称:EvaP,代码行数:27,代码来源:create_user.py

示例4: save

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
    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)
开发者ID:Nef10,项目名称:EvaP,代码行数:11,代码来源:forms.py

示例5: user_edit

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
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))
开发者ID:Nef10,项目名称:EvaP,代码行数:12,代码来源:views.py

示例6: store_in_database

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
 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
开发者ID:cyroxx,项目名称:EvaP,代码行数:12,代码来源:importers.py

示例7: user_delete

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
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')
开发者ID:sebastianoe,项目名称:EvaP,代码行数:14,代码来源:views.py

示例8: test_login_key

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
    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)
开发者ID:Bartzi,项目名称:EvaP,代码行数:15,代码来源:tests.py

示例9: _post_clean

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
    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)
开发者ID:Bartzi,项目名称:EvaP,代码行数:15,代码来源:forms.py

示例10: create_contributor_questionnaires

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
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
开发者ID:Nef10,项目名称:EvaP,代码行数:16,代码来源:tools.py

示例11: clean_email

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
    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
开发者ID:02strich,项目名称:EvaP,代码行数:16,代码来源:forms.py

示例12: update

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
    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()
开发者ID:cyroxx,项目名称:EvaP,代码行数:18,代码来源:importers.py

示例13: __init__

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
    def __init__(self, *args, **kwargs):
        super(CourseForm, self).__init__(*args, **kwargs)

        self.fields['vote_start_date'].localize = True
        self.fields['vote_end_date'].localize = True
        self.fields['kind'].widget = forms.Select(choices=[(a, a) for a in Course.objects.values_list('kind', flat=True).order_by().distinct()])
        self.fields['degree'].widget = forms.Select(choices=[(a, a) for a in Course.objects.values_list('degree', flat=True).order_by().distinct()])
        self.fields['participants'].queryset = User.objects.order_by("last_name", "first_name", "username")
        self.fields['participants'].help_text = ""

        if self.instance.general_contribution:
            self.fields['general_questions'].initial = [q.pk for q in self.instance.general_contribution.questionnaires.all()]

        self.fields['last_modified_time_2'].initial = self.instance.last_modified_time
        self.fields['last_modified_time_2'].widget.attrs['readonly'] = True
        if self.instance.last_modified_user:
            self.fields['last_modified_user_2'].initial = UserProfile.get_for_user(self.instance.last_modified_user).full_name
        self.fields['last_modified_user_2'].widget.attrs['readonly'] = True

        if self.instance.state == "inEvaluation":
            self.fields['vote_start_date'].widget.attrs['readonly'] = True
            self.fields['vote_end_date'].widget.attrs['readonly'] = True
开发者ID:Bartzi,项目名称:EvaP,代码行数:24,代码来源:forms.py

示例14: get_contributors_with_questionnaires

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
 def get_contributors_with_questionnaires(self, course):
     for ccm in self.get('course_category_mapping', course_id=course.id):
         for ccm_to_staff in self.get('ccm_to_staff', ccm_id=ccm.id):
             # staff --> User
             staff = self.get_one('staff', id=ccm_to_staff.staff_id)
             user = self.user_from_db(staff.loginName)
             
             # import name
             profile = UserProfile.get_for_user(user)
             name_parts = unicode(staff.name).split()
             if name_parts[0].startswith("Dr"):
                 user.last_name = " ".join(name_parts[1:])
                 profile.title = name_parts[0]
             elif name_parts[0] == "Prof.":
                 user.last_name = " ".join(name_parts[2:])
                 profile.title = " ".join(name_parts[:2])
             elif name_parts[0].startswith("Prof"):
                 user.last_name = " ".join(name_parts[1:])
                 profile.title = name_parts[0]
             elif len(name_parts) == 2:
                 user.first_name = name_parts[0]
                 user.last_name = name_parts[1]
             user.save()
             profile.save()
                 
             # TODO: import name?
             self.staff_cache[int(staff.id)] = user
             try:
                 topic_template = self.get_one('topic_template',
                                               course_category_id=ccm.course_category_id,
                                               questionnaire_template_id=course.evaluation_id,
                                               per_person="1")
                 
                 questionnaire = self.questionnaire_cache[int(topic_template.id)]
                 
                 yield user, questionnaire
             except NotOneException:
                 logger.warn("Skipping questionnaire for contributor %r in course %r.", user, course.name)
开发者ID:02strich,项目名称:EvaP,代码行数:40,代码来源:import_evaj.py

示例15: check_user

# 需要导入模块: from evap.evaluation.models import UserProfile [as 别名]
# 或者: from evap.evaluation.models.UserProfile import get_for_user [as 别名]
 def check_user(user):
     if not user.is_authenticated():
         return False
     return UserProfile.get_for_user(user=user).is_editor
开发者ID:Bartzi,项目名称:EvaP,代码行数:6,代码来源:auth.py


注:本文中的evap.evaluation.models.UserProfile.get_for_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。