本文整理汇总了Python中django.contrib.sites.shortcuts.get_current_site方法的典型用法代码示例。如果您正苦于以下问题:Python shortcuts.get_current_site方法的具体用法?Python shortcuts.get_current_site怎么用?Python shortcuts.get_current_site使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.sites.shortcuts
的用法示例。
在下文中一共展示了shortcuts.get_current_site方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: team_listing
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def team_listing(request):
"""Return a listing of teams visible to the user."""
team_list = Team.objects.user_visible(request.user).order_by(Lower('name'))
desc = _('List of teams on {name} and summary information').format(name=get_current_site(request).name) # nopep8
user_teams = set()
user_invites = set()
user_pending = set()
user_owns = set()
if request.user.is_authenticated:
user_invites = set(TeamRequest.objects.filter(invitee=request.user, inviter__isnull=False).values_list('team', flat=True))
user_pending = set(TeamRequest.objects.filter(invitee=request.user, inviter__isnull=True).values_list('team', flat=True))
user_teams = set(request.user.team_set.values_list('id', flat=True))
user_owns = set(Team.objects.filter(owner=request.user).values_list('id', flat=True))
return render(request, 'teams/teams.html', {
'teams': make_paginator(request, team_list),
'meta_description': desc,
'user_teams': user_teams,
'user_invites': user_invites,
'user_pending': user_pending,
'user_owns': user_owns,
})
示例2: index
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def index(request, sitemaps,
template_name='sitemap_index.xml', content_type='application/xml',
sitemap_url_name='django.contrib.sitemaps.views.sitemap'):
req_protocol = request.scheme
req_site = get_current_site(request)
sites = []
for section, site in sitemaps.items():
if callable(site):
site = site()
protocol = req_protocol if site.protocol is None else site.protocol
sitemap_url = urlresolvers.reverse(
sitemap_url_name, kwargs={'section': section})
absolute_url = '%s://%s%s' % (protocol, req_site.domain, sitemap_url)
sites.append(absolute_url)
for page in range(2, site.paginator.num_pages + 1):
sites.append('%s?p=%s' % (absolute_url, page))
return TemplateResponse(request, template_name, {'sitemaps': sites},
content_type=content_type)
示例3: render
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def render(self, context):
if 'request' in context:
site_pk = get_current_site(context['request']).pk
else:
site_pk = settings.SITE_ID
flatpages = FlatPage.objects.filter(sites__id=site_pk)
# If a prefix was specified, add a filter
if self.starts_with:
flatpages = flatpages.filter(
url__startswith=self.starts_with.resolve(context))
# If the provided user is not authenticated, or no user
# was provided, filter the list to only public flatpages.
if self.user:
user = self.user.resolve(context)
if not user.is_authenticated():
flatpages = flatpages.filter(registration_required=False)
else:
flatpages = flatpages.filter(registration_required=False)
context[self.context_name] = flatpages
return ''
示例4: form_valid
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def form_valid(self, form):
"""仮登録と本登録用メールの発行."""
# 仮登録と本登録の切り替えは、is_active属性を使うと簡単です。
# 退会処理も、is_activeをFalseにするだけにしておくと捗ります。
user = form.save(commit=False)
user.is_active = False
user.save()
# アクティベーションURLの送付
current_site = get_current_site(self.request)
domain = current_site.domain
context = {
'protocol': 'https' if self.request.is_secure() else 'http',
'domain': domain,
'token': dumps(user.pk),
'user': user,
}
subject = render_to_string('register/mail_template/create/subject.txt', context)
message = render_to_string('register/mail_template/create/message.txt', context)
user.email_user(subject, message)
return redirect('register:user_create_done')
示例5: index
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def index(request, sitemaps,
template_name='sitemap_index.xml', content_type='application/xml',
sitemap_url_name='django.contrib.sitemaps.views.sitemap'):
req_protocol = request.scheme
req_site = get_current_site(request)
sites = [] # all sections' sitemap URLs
for section, site in sitemaps.items():
# For each section label, add links of all pages of its sitemap
# (usually generated by the `sitemap` view).
if callable(site):
site = site()
protocol = req_protocol if site.protocol is None else site.protocol
sitemap_url = reverse(sitemap_url_name, kwargs={'section': section})
absolute_url = '%s://%s%s' % (protocol, req_site.domain, sitemap_url)
sites.append(absolute_url)
# Add links to all pages of the sitemap.
for page in range(2, site.paginator.num_pages + 1):
sites.append('%s?p=%s' % (absolute_url, page))
return TemplateResponse(request, template_name, {'sitemaps': sites},
content_type=content_type)
示例6: flatpage
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def flatpage(request, url):
"""
Public interface to the flat page view.
Models: `flatpages.flatpages`
Templates: Uses the template defined by the ``template_name`` field,
or :template:`flatpages/default.html` if template_name is not defined.
Context:
flatpage
`flatpages.flatpages` object
"""
if not url.startswith('/'):
url = '/' + url
site_id = get_current_site(request).id
try:
f = get_object_or_404(FlatPage, url=url, sites=site_id)
except Http404:
if not url.endswith('/') and settings.APPEND_SLASH:
url += '/'
f = get_object_or_404(FlatPage, url=url, sites=site_id)
return HttpResponsePermanentRedirect('%s/' % request.path)
else:
raise
return render_flatpage(request, f)
示例7: render
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def render(self, context):
if 'request' in context:
site_pk = get_current_site(context['request']).pk
else:
site_pk = settings.SITE_ID
flatpages = FlatPage.objects.filter(sites__id=site_pk)
# If a prefix was specified, add a filter
if self.starts_with:
flatpages = flatpages.filter(
url__startswith=self.starts_with.resolve(context))
# If the provided user is not authenticated, or no user
# was provided, filter the list to only public flatpages.
if self.user:
user = self.user.resolve(context)
if not user.is_authenticated:
flatpages = flatpages.filter(registration_required=False)
else:
flatpages = flatpages.filter(registration_required=False)
context[self.context_name] = flatpages
return ''
示例8: domain
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def domain(context, url=''):
if 'request' in context:
protocol = 'https' if context['request'].is_secure() else 'http'
_domain = get_current_site(context['request']).domain
elif 'protocol' in context and 'domain' in context:
# Django emails
protocol, _domain = context['protocol'], context['domain']
elif 'site' in context:
# Postman emails
_domain = context['site'].domain
protocol = 'https' if 'pasportaservo.org' in _domain else 'http'
else:
# Fallback
if settings.DEBUG:
protocol, _domain = 'http', 'localhost:8000'
else:
protocol, _domain = 'https', settings.ALLOWED_HOSTS[0]
link = '{}://{}{}'.format(protocol, _domain, url)
return link
示例9: categories_show
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def categories_show(request, category_id, slug=None):
category = get_object_or_404(
Category,
pk=category_id,
site_id=get_current_site(request).id
)
if slug is None:
return HttpResponsePermanentRedirect(category.get_absolute_url())
jobs = Job.objects.filter(site_id=get_current_site(request).id) \
.filter(category_id=category_id) \
.filter(paid_at__isnull=False) \
.filter(expired_at__isnull=True) \
.order_by('-paid_at')
form = SubscribeForm()
meta_desc = 'Browse a list of all active %s jobs' % category.name
feed_url = reverse('categories_feed', args=(category.id, category.slug(),))
title = '%s Jobs' % category.name
context = {'meta_desc': meta_desc,
'link_rss': feed_url,
'title': title,
'form': form,
'jobs': jobs}
return render(request, 'job_board/jobs_index.html', context)
示例10: companies_index
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def companies_index(request):
companies_list = Company.objects \
.filter(site_id=get_current_site(request).id)
for c in companies_list:
if len(c.paid_jobs()) == 0:
companies_list = companies_list.exclude(id=c.id)
paginator = Paginator(companies_list, 25)
page = request.GET.get('page')
meta_desc = 'Browse an extensive list of companies with active and ' \
'expired jobs'
title = 'Companies'
try:
companies = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
companies = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
companies = paginator.page(paginator.num_pages)
context = {'meta_desc': meta_desc, 'title': title, 'companies': companies}
return render(request, 'job_board/companies_index.html', context)
示例11: jobs_mine
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def jobs_mine(request):
jobs_list = Job.objects.filter(site_id=get_current_site(request).id) \
.filter(user_id=request.user.id) \
.order_by('-created_at')
paginator = Paginator(jobs_list, 25)
page = request.GET.get('page')
title = 'My Jobs'
try:
jobs = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
jobs = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
jobs = paginator.page(paginator.num_pages)
context = {'jobs': jobs, 'title': title}
return render(request, 'job_board/jobs_mine.html', context)
示例12: jobs_search
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def jobs_search(request):
form = SearchForm(request.GET)
if form.is_valid():
cd = form.cleaned_data
jobs = Job.objects.filter(site_id=get_current_site(request).id) \
.filter(paid_at__isnull=False) \
.filter(expired_at__isnull=True) \
.filter(
Q(title__icontains=cd['query']) |
Q(description__icontains=cd['query'])
).order_by('-paid_at')
meta_desc = 'Search Results'
title = 'Search Results'
context = {'meta_desc': meta_desc,
'title': title,
'form': form,
'jobs': jobs}
return render(request, 'job_board/jobs_index.html', context)
示例13: form_valid
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def form_valid(self, form):
# add current site
form.instance.site = get_current_site(self.request)
# save the project
response = super(ProjectCreateView, self).form_valid(form)
# add all tasks to project
tasks = Task.objects.filter_current_site().filter_group(self.request.user)
for task in tasks:
form.instance.tasks.add(task)
# add all views to project
views = View.objects.filter_current_site().filter_catalog(self.object.catalog).filter_group(self.request.user)
for view in views:
form.instance.views.add(view)
# add current user as owner
membership = Membership(project=form.instance, user=self.request.user, role='owner')
membership.save()
return response
示例14: password_reset
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def password_reset(request):
"""REST API reset password view"""
serializer = UsernameSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
username = serializer.validated_data.get('username')
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
pass
else:
context = {
'email': username,
'domain': get_current_site(request).domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'user': user,
'token': default_token_generator.make_token(user),
'protocol': 'https' if request.is_secure() else 'http',
}
send_mail(
request,
'password_reset',
[username],
context=context,
send_copy_to_admin=False)
return Response(dict(), status=status.HTTP_201_CREATED)
示例15: resend_signup_email
# 需要导入模块: from django.contrib.sites import shortcuts [as 别名]
# 或者: from django.contrib.sites.shortcuts import get_current_site [as 别名]
def resend_signup_email(request):
user = request.user
current_site = get_current_site(request)
subject = 'Activate Your FAST AutoGrader Account'
message = render_to_string('account/account_activation_email.html', {
'user': user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user),
})
user.email_user(subject, message)
messages.success(request, 'Verification email sent, check your email account.')
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))