本文整理汇总了Python中userena.utils.get_user_profile函数的典型用法代码示例。如果您正苦于以下问题:Python get_user_profile函数的具体用法?Python get_user_profile怎么用?Python get_user_profile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user_profile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: check_permissions
def check_permissions(self):
"""
Checks that all permissions are set correctly for the users.
:return: A set of users whose permissions was wrong.
"""
# Variable to supply some feedback
changed_permissions = []
changed_users = []
warnings = []
# Check that all the permissions are available.
for model, perms in ASSIGNED_PERMISSIONS.items():
if model == 'profile':
model_obj = get_profile_model()
else:
model_obj = get_user_model()
model_content_type = ContentType.objects.get_for_model(model_obj)
for perm in perms:
try:
Permission.objects.get(codename=perm[0],
content_type=model_content_type)
except Permission.DoesNotExist:
changed_permissions.append(perm[1])
Permission.objects.create(name=perm[1],
codename=perm[0],
content_type=model_content_type)
# it is safe to rely on settings.ANONYMOUS_USER_ID since it is a
# requirement of django-guardian
for user in get_user_model().objects.exclude(id=settings.ANONYMOUS_USER_ID):
try:
user_profile = get_user_profile(user=user)
except ObjectDoesNotExist:
warnings.append(_("No profile found for %(username)s") \
% {'username': user.username})
else:
all_permissions = get_perms(user, user_profile) + get_perms(user, user)
for model, perms in ASSIGNED_PERMISSIONS.items():
if model == 'profile':
perm_object = get_user_profile(user=user)
else:
perm_object = user
for perm in perms:
if perm[0] not in all_permissions:
assign_perm(perm[0], user, perm_object)
changed_users.append(user)
return (changed_permissions, changed_users, warnings)
开发者ID:openslack,项目名称:openslack-web,代码行数:54,代码来源:managers.py
示例2: test_activation_valid
def test_activation_valid(self):
"""
Valid activation of an user.
Activation of an user with a valid ``activation_key`` should activate
the user and set a new invalid ``activation_key`` that is defined in
the setting ``USERENA_ACTIVATED``.
"""
user = UserenaSignup.objects.create_user(**self.user_info)
active_user = UserenaSignup.objects.activate_user(user.userena_signup.activation_key)
profile = get_user_profile(user=active_user)
# The returned user should be the same as the one just created.
self.failUnlessEqual(user, active_user)
# The user should now be active.
self.failUnless(active_user.is_active)
# The user should have permission to view and change its profile
self.failUnless('view_profile' in get_perms(active_user, profile))
self.failUnless('change_profile' in get_perms(active_user, profile))
# The activation key should be the same as in the settings
self.assertEqual(active_user.userena_signup.activation_key,
userena_settings.USERENA_ACTIVATED)
开发者ID:DjangoBD,项目名称:django-userena,代码行数:26,代码来源:tests_managers.py
示例3: test_create_inactive_user
def test_create_inactive_user(self):
"""
Test the creation of a new user.
``UserenaSignup.create_inactive_user`` should create a new user that is
not active. The user should get an ``activation_key`` that is used to
set the user as active.
Every user also has a profile, so this method should create an empty
profile.
"""
# Check that the fields are set.
new_user = UserenaSignup.objects.create_user(**self.user_info)
self.assertEqual(new_user.username, self.user_info['username'])
self.assertEqual(new_user.email, self.user_info['email'])
self.failUnless(new_user.check_password(self.user_info['password']))
# User should be inactive
self.failIf(new_user.is_active)
# User has a valid SHA1 activation key
self.failUnless(re.match('^[a-f0-9]{40}$', new_user.userena_signup.activation_key))
# User now has an profile.
self.failUnless(get_user_profile(user=new_user))
# User should be saved
self.failUnlessEqual(User.objects.filter(email=self.user_info['email']).count(), 1)
开发者ID:DjangoBD,项目名称:django-userena,代码行数:29,代码来源:tests_managers.py
示例4: profile_detail
def profile_detail(request, username):
user = get_object_or_404(User, username=username)
profile = get_user_profile(user)
context = {
'profile': profile,
}
return render(request, 'accounts/detail.html', context)
开发者ID:bjzt1016,项目名称:thirtylol,代码行数:7,代码来源:views.py
示例5: profile_detail
def profile_detail(request, username,
template_name=userena_settings.USERENA_PROFILE_DETAIL_TEMPLATE,
extra_context=None, **kwargs):
"""
Detailed view of an user.
:param username:
String of the username of which the profile should be viewed.
:param template_name:
String representing the template name that should be used to display
the profile.
:param extra_context:
Dictionary of variables which should be supplied to the template. The
``profile`` key is always the current profile.
**Context**
``profile``
Instance of the currently viewed ``Profile``.
"""
user = get_object_or_404(get_user_model(), username__iexact=username)
profile = get_user_profile(user=user)
if not profile.can_view_profile(request.user):
raise PermissionDenied
if not extra_context: extra_context = dict()
extra_context['profile'] = profile
extra_context['hide_email'] = userena_settings.USERENA_HIDE_EMAIL
return ExtraContextTemplateView.as_view(template_name=template_name,
extra_context=extra_context)(request)
开发者ID:Rsgm,项目名称:django-userena,代码行数:32,代码来源:views.py
示例6: profile_detail_extended
def profile_detail_extended(request, username, edit_profile_form=EditProfileForm, template_name='userena/profile_detail_extended.html', success_url=None,extra_context=None, **kwargs):
user = get_object_or_404(get_user_model(), username__iexact=username)
profile = get_user_profile(user=user)
if not extra_context: extra_context = dict()
extra_context['profile'] = profile
extra_context['profExpData'] = Profile_Experience.objects.filter(profile = profile)
extra_context['projExpData'] = Project_Experience.objects.filter(profile = profile)
extra_context['awardsData'] = Awards.objects.filter(profile = profile)
return ExtraContextTemplateView.as_view(template_name=template_name, extra_context=extra_context)(request)
开发者ID:aramais,项目名称:phoenixcs,代码行数:9,代码来源:views.py
示例7: favourite
def favourite(request, username):
user = get_object_or_404(User, username=username)
profile = get_user_profile(user)
presenter_list = user.my_profile.follows.order_by('-presenterdetail__showing', '-presenterdetail__audience_count');
context = {
'profile': profile,
'presenter_list': presenter_list,
}
return render(request, 'accounts/favourite.html', context)
开发者ID:bjzt1016,项目名称:thirtylol,代码行数:10,代码来源:views.py
示例8: get_queryset
def get_queryset(self):
logging.error(get_user_profile(self.request.user).__dict__)
profile_model = get_profile_model()
logging.error(profile_model.__dict__)
logging.error(profile_model.objects.all())
logging.error(profile_model.__doc__)
## logging.error(self.__dict__)
## logging.error(self.request.__dict__)
queryset = profile_model.objects.get_visible_profiles(self.request.user).select_related()
return queryset
开发者ID:behappyyoung,项目名称:pythonprojectm,代码行数:11,代码来源:views.py
示例9: process_request
def process_request(self, request):
lang_cookie = request.COOKIES.get(settings.LANGUAGE_COOKIE_NAME)
if not lang_cookie:
if request.user.is_authenticated():
try:
profile = get_user_profile(user=request.user)
except (ObjectDoesNotExist, SiteProfileNotAvailable):
profile = False
if profile:
try:
lang = getattr(profile, userena_settings.USERENA_LANGUAGE_FIELD)
translation.activate(lang)
request.LANGUAGE_CODE = translation.get_language()
except AttributeError: pass
开发者ID:itmation,项目名称:django-userena,代码行数:15,代码来源:middleware.py
示例10: test_preference_user
def test_preference_user(self):
""" Test the language preference of two users """
users = ((1, 'nl'),
(2, 'en'))
for pk, lang in users:
user = User.objects.get(pk=pk)
profile = get_user_profile(user=user)
req = self._get_request_with_user(user)
# Check that the user has this preference
self.assertEqual(profile.language, lang)
# Request should have a ``LANGUAGE_CODE`` with dutch
UserenaLocaleMiddleware().process_request(req)
self.assertEqual(req.LANGUAGE_CODE, lang)
开发者ID:AmmsA,项目名称:django-userena,代码行数:17,代码来源:tests_middleware.py
示例11: create_user
def create_user(self, username, email, password, active=False,
send_email=True):
"""
A simple wrapper that creates a new :class:`User`.
:param username:
String containing the username of the new user.
:param email:
String containing the email address of the new user.
:param password:
String containing the password for the new user.
:param active:
Boolean that defines if the user requires activation by clicking
on a link in an e-mail. Defaults to ``False``.
:param send_email:
Boolean that defines if the user should be sent an email. You could
set this to ``False`` when you want to create a user in your own
code, but don't want the user to activate through email.
:return: :class:`User` instance representing the new user.
"""
new_user = get_user_model().objects.create_user(
username, email, password)
new_user.is_active = active
new_user.save()
# Give permissions to view and change profile
for perm in ASSIGNED_PERMISSIONS['profile']:
assign_perm(perm[0], new_user, get_user_profile(user=new_user))
# Give permissions to view and change itself
for perm in ASSIGNED_PERMISSIONS['user']:
assign_perm(perm[0], new_user, new_user)
userena_profile = self.create_userena_profile(new_user)
if send_email:
userena_profile.send_activation_email()
return new_user
开发者ID:DjangoBD,项目名称:django-userena,代码行数:46,代码来源:managers.py
示例12: test_profile_edit_view_success
def test_profile_edit_view_success(self):
""" A ``POST`` to the edit view """
self.client.login(username='john', password='blowfish')
new_about_me = 'I hate it when people use my name for testing.'
response = self.client.post(reverse('userena_profile_edit',
kwargs={'username': 'john'}),
data={'about_me': new_about_me,
'privacy': 'open',
'language': 'en'})
# A valid post should redirect to the detail page.
self.assertRedirects(response, reverse('userena_profile_detail',
kwargs={'username': 'john'}))
# Users hould be changed now.
profile = get_user_profile(user=User.objects.get(username='john'))
self.assertEqual(profile.about_me, new_about_me)
开发者ID:bioinformatics-ua,项目名称:django-userena,代码行数:17,代码来源:tests_views.py
示例13: test_upload_mugshot
def test_upload_mugshot(self):
"""
Test the uploaded path of mugshots
TODO: What if a image get's uploaded with no extension?
"""
user = User.objects.get(pk=1)
filename = 'my_avatar.png'
path = upload_to_mugshot(get_user_profile(user=user), filename)
# Path should be changed from the original
self.failIfEqual(filename, path)
# Check if the correct path is returned
MUGSHOT_RE = re.compile('^%(mugshot_path)s[a-f0-9]{10}.png$' %
{'mugshot_path': userena_settings.USERENA_MUGSHOT_PATH})
self.failUnless(MUGSHOT_RE.search(path))
开发者ID:chuan137,项目名称:yunda,代码行数:19,代码来源:tests_models.py
示例14: profile_edit
def profile_edit(request, username):
user = get_object_or_404(User, username=username)
profile = get_user_profile(user)
if request.method == 'POST':
print request.POST
form = EditProfileForm(request.POST, request.FILES)
if form.is_valid():
mugshot = form.cleaned_data['mugshot']
if mugshot:
profile.mugshot = form.cleaned_data['mugshot']
profile.save()
else:
form = EditProfileForm()
context = {
'profile': profile,
'form': form,
}
return render(request, 'accounts/edit.html', context)
开发者ID:bjzt1016,项目名称:thirtylol,代码行数:20,代码来源:views.py
示例15: direct_to_user_template
def direct_to_user_template(request, username, template_name,
extra_context=None):
"""
Simple wrapper for Django's :func:`direct_to_template` view.
This view is used when you want to show a template to a specific user. A
wrapper for :func:`direct_to_template` where the template also has access to
the user that is found with ``username``. For ex. used after signup,
activation and confirmation of a new e-mail.
:param username:
String defining the username of the user that made the action.
:param template_name:
String defining the name of the template to use. Defaults to
``userena/signup_complete.html``.
**Keyword arguments**
``extra_context``
A dictionary containing extra variables that should be passed to the
rendered template. The ``account`` key is always the ``User``
that completed the action.
**Extra context**
``viewed_user``
The currently :class:`User` that is viewed.
"""
user = get_object_or_404(get_user_model(), username__iexact=username)
if not extra_context: extra_context = dict()
extra_context['viewed_user'] = user
extra_context['request'] = request
extra_context['profile'] = get_user_profile(user=user)
return ExtraContextTemplateView.as_view(template_name=template_name,
extra_context=extra_context)(request)
开发者ID:bioinformatics-ua,项目名称:django-userena,代码行数:39,代码来源:views.py
示例16: oauth
def oauth(request):
try:
code = request.GET.get('code', '')
token_str = _access_token(request, code)
token_json = json.loads(token_str)
user = authenticate(token=token_json['access_token'], uid=token_json['uid'], expire_in=(60 * 60 * 24))
if user:
try:
user_str = _show_user(token_json['access_token'], token_json['uid'])
user_json = json.loads(user_str)
user.username = user_json['screen_name']
user.save()
except:
pass
auth_login(request, user)
profile = get_user_profile(user)
profile.source = UserSource.objects.get(flag=100)
profile.save()
return HttpResponseRedirect(signin_redirect(user=user))
except:
return HttpResponse("很抱歉,使用新浪微博认证登录失败,请尝试从网站注册!")
开发者ID:bjzt1016,项目名称:thirtylol,代码行数:22,代码来源:views.py
示例17: test_get_full_name_or_username
def test_get_full_name_or_username(self):
""" Test if the full name or username are returned correcly """
user = User.objects.get(pk=1)
profile = get_user_profile(user=user)
# Profile #1 has a first and last name
full_name = profile.get_full_name_or_username()
self.failUnlessEqual(full_name, "John Doe")
# Let's empty out his name, now we should get his username
user.first_name = ''
user.last_name = ''
user.save()
self.failUnlessEqual(profile.get_full_name_or_username(),
"john")
# Finally, userena doesn't use any usernames, so we should return the
# e-mail address.
userena_settings.USERENA_WITHOUT_USERNAMES = True
self.failUnlessEqual(profile.get_full_name_or_username(),
"[email protected]")
userena_settings.USERENA_WITHOUT_USERNAMES = False
开发者ID:chuan137,项目名称:yunda,代码行数:23,代码来源:tests_models.py
示例18: disabled_account
def disabled_account(request, username, template_name, extra_context=None):
"""
Checks if the account is disabled, if so, returns the disabled account template.
:param username:
String defining the username of the user that made the action.
:param template_name:
String defining the name of the template to use. Defaults to
``userena/signup_complete.html``.
**Keyword arguments**
``extra_context``
A dictionary containing extra variables that should be passed to the
rendered template. The ``account`` key is always the ``User``
that completed the action.
**Extra context**
``viewed_user``
The currently :class:`User` that is viewed.
``profile``
Profile of the viewed user.
"""
user = get_object_or_404(get_user_model(), username__iexact=username)
if user.is_active:
raise Http404
if not extra_context: extra_context = dict()
extra_context['viewed_user'] = user
extra_context['profile'] = get_user_profile(user=user)
return ExtraContextTemplateView.as_view(template_name=template_name,
extra_context=extra_context)(request)
开发者ID:Rsgm,项目名称:django-userena,代码行数:37,代码来源:views.py
示例19: profile_edit
def profile_edit(request, username, edit_profile_form=EditProfileForm,
template_name='userena/profile_form.html', success_url=None,
extra_context=None, **kwargs):
"""
Edit profile.
Edits a profile selected by the supplied username. First checks
permissions if the user is allowed to edit this profile, if denied will
show a 404. When the profile is successfully edited will redirect to
``success_url``.
:param username:
Username of the user which profile should be edited.
:param edit_profile_form:
Form that is used to edit the profile. The :func:`EditProfileForm.save`
method of this form will be called when the form
:func:`EditProfileForm.is_valid`. Defaults to :class:`EditProfileForm`
from userena.
:param template_name:
String of the template that is used to render this view. Defaults to
``userena/edit_profile_form.html``.
:param success_url:
Named URL which will be passed on to a django ``reverse`` function after
the form is successfully saved. Defaults to the ``userena_detail`` url.
:param extra_context:
Dictionary containing variables that are passed on to the
``template_name`` template. ``form`` key will always be the form used
to edit the profile, and the ``profile`` key is always the edited
profile.
**Context**
``form``
Form that is used to alter the profile.
``profile``
Instance of the ``Profile`` that is edited.
"""
user = get_object_or_404(get_user_model(), username__iexact=username)
profile = get_user_profile(user=user)
user_initial = {'first_name': user.first_name,
'last_name': user.last_name}
form = edit_profile_form(instance=profile, initial=user_initial)
if request.method == 'POST':
form = edit_profile_form(request.POST, request.FILES, instance=profile,
initial=user_initial)
if form.is_valid():
profile = form.save()
mail_subject = [user.username]
mail_body = 'Dear customer. Your order has been confirmed. Please come on time. If you could not make it Please ring 845-783-8866 for reschedule or cancelation'
mail_from = '[email protected]'
mail_to = [user.email,'[email protected]' ]
send_mail(mail_subject, mail_body, mail_from, mail_to)
if success_url: redirect_to = success_url
else: redirect_to = reverse('userena_order_complete',
kwargs={'username': user.username})
return redirect(redirect_to)
if not extra_context: extra_context = dict()
extra_context['form'] = form
extra_context['profile'] = get_user_profile(user=user)
return ExtraContextTemplateView.as_view(template_name=template_name,
extra_context=extra_context)(request)
开发者ID:kamiswin,项目名称:body,代码行数:78,代码来源:views.py
示例20: profile_edit_extended
def profile_edit_extended(request, username, edit_profile_form=EditProfileForm, template_name='userena/profile_form_extended.html', success_url=None,extra_context=None, **kwargs):
"""
Edit profile.
Edits a profile selected by the supplied username. First checks
permissions if the user is allowed to edit this profile, if denied will
show a 404. When the profile is successfully edited will redirect to
``success_url``.
:param username:
Username of the user which profile should be edited.
:param edit_profile_form:
Form that is used to edit the profile. The :func:`EditProfileForm.save`
method of this form will be called when the form
:func:`EditProfileForm.is_valid`. Defaults to :class:`EditProfileForm`
from userena.
:param template_name:
String of the template that is used to render this view. Defaults to
``userena/edit_profile_form.html``.
:param success_url:
Named URL which will be passed on to a django ``reverse`` function after
the form is successfully saved. Defaults to the ``userena_detail`` url.
:param extra_context:
Dictionary containing variables that are passed on to the
``template_name`` template. ``form`` key will always be the form used
to edit the profile, and the ``profile`` key is always the edited
profile.
**Context**
``form``
Form that is used to alter the profile.
``profile``
Instance of the ``Profile`` that is edited.
"""
user = get_object_or_404(get_user_model(), username__iexact=username)
profile = get_user_profile(user=user)
user_initial = {'first_name': user.first_name, 'last_name': user.last_name}
form = edit_profile_form(instance=profile, initial=user_initial)
#FormSetProfExp = formset_factory(ProfExpForm)
#FormSetProjExp = formset_factory(ProjExpForm)
#FormSetAwards = formset_factory(AwardsForm, can_delete = True)
FormSetProfExp = modelformset_factory(Profile_Experience, exclude=('profile',), can_delete = True, widgets = {'jobstart':SelectDateWidget(),'jobend':SelectDateWidget() })
FormSetProjExp = modelformset_factory(Project_Experience, exclude=('profile',), can_delete = True,widgets = {'projectstart':SelectDateWidget(),'projectend':SelectDateWidget() })
FormSetAwards = modelformset_factory(Awards, exclude=('profile',), can_delete = True)
if request.method == 'POST':
formSetProfExp = FormSetProfExp(request.POST)
formSetProjExp = FormSetProjExp(request.POST)
formSetAwards = FormSetAwards(request.POST)
'''
for form in formSetProfExp:
if form.is_valid():
profExp = form.save(commit = False)
profExp.profile = profile
try:
profExp.save()
except IntegrityError:
pass
for form in formSetProjExp:
if form.is_valid():
projExp = form.save(commit = False)
projExp.profile = profile
try:
projExp.save()
except IntegrityError:
pass
'''
if formSetProfExp.is_valid():
formSetProfExp.save(commit = False)
for anobject in formSetProfExp.new_objects:
anobject.profile = profile
formSetProfExp.save(commit = True)
if formSetProjExp.is_valid():
formSetProjExp.save(commit = False)
for anobject in formSetProjExp.new_objects:
anobject.profile = profile
formSetProjExp.save(commit = True)
if formSetAwards.is_valid():
formSetAwards.save(commit = False)
for anobject in formSetAwards.new_objects:
anobject.profile = profile
formSetAwards.save(commit = True)
form = edit_profile_form(request.POST, request.FILES, instance=profile, initial=user_initial)
if form.is_valid():
profile = form.save()
#.........这里部分代码省略.........
开发者ID:aramais,项目名称:phoenixcs,代码行数:101,代码来源:views.py
注:本文中的userena.utils.get_user_profile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论