本文整理汇总了Python中menus.utils.set_language_changer函数的典型用法代码示例。如果您正苦于以下问题:Python set_language_changer函数的具体用法?Python set_language_changer怎么用?Python set_language_changer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_language_changer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: blog_archive_day
def blog_archive_day(request, **kwargs):
blog_slug = kwargs.pop('blog_slug')
kwargs['queryset'] = kwargs['queryset'].published().filter(
blog__slug=blog_slug)
set_language_changer(request, language_changer)
return archive_day(request, extra_context={ 'blog_slug': blog_slug },
**kwargs)
示例2: get
def get(self, request, *args, **kwargs):
try:
category = self.get_category()
except FallbackLanguageResolved as flr:
# We have the category, but it is in a fallback language.
category = flr.object
# only look at questions within this category
queryset = self.get_queryset().filter(category=category.pk)
question = self.get_object(queryset=queryset)
set_language_changer(request, question.get_absolute_url)
if hasattr(request, 'toolbar'):
request.toolbar.set_object(question)
setattr(request, request_faq_category_identifier, question.category)
setattr(request, request_faq_question_identifier, question)
response = super(FaqAnswerView, self).get(request, *args, **kwargs)
# FIXME: We should check for unique visitors using sessions.
# update number of visits
question_only_queryset = self.get_queryset().filter(pk=question.pk)
question_only_queryset.update(
number_of_visits=models.F('number_of_visits') + 1)
return response
示例3: get_context_data
def get_context_data (self, **kwargs):
context = super(Detail, self).get_context_data(**kwargs)
obj = context['obj']
context['url_feed'] = reverse('draftlaw_feed_detail', args=[obj.pk])
set_language_changer(self.request, obj.get_absolute_url)
return context
示例4: blog_archive_tagged
def blog_archive_tagged(request, **kwargs):
blog_slug = kwargs.pop('blog_slug')
kwargs['queryset_or_model'] = (kwargs['queryset_or_model'].published()
.filter(blog__slug=blog_slug))
set_language_changer(request, language_changer)
return tagged_object_list(request, extra_context={ 'blog_slug': blog_slug },
**kwargs)
示例5: get
def get(self, request, *args, **kwargs):
response = super(PostDetailView, self).get(request, *args, **kwargs)
post = response.context_data.get('post', None)
if post:
setattr(request, request_post_identifier, post)
if post.language:
set_language_changer(request, post_language_changer)
return response
示例6: get_context_data
def get_context_data (self, **kwargs):
context = super(Detail, self).get_context_data(**kwargs)
context['form'] = _get_form(self, context['obj'].representative)
context['url_feed'] = reverse('question_feed_list')
set_language_changer(self.request, context['obj'].get_absolute_url)
return context
示例7: blog_archive_author
def blog_archive_author(request, **kwargs):
author = kwargs.pop('author')
kwargs['queryset'] = kwargs['queryset'].published().filter(entrytitle__author__username=author)
kwargs['extra_context'] = {
'author': get_object_or_404(User, username=author),
}
set_language_changer(request, language_changer)
return object_list(request, **kwargs)
示例8: get_context_data
def get_context_data (self, **kwargs):
context = super(Detail, self).get_context_data(**kwargs)
draftlaw_url = 'https://matsne.gov.ge/index.php?geo=on&searchTarget=title&searchDocumentsFilter=all&courtDecisionsARGUMENT=&sortCombo=signingDate_asc&queryString=&option=com_ldmssearch&view=docSearchResults&searchType=advanced&limitstart=0&lang=ge&documentNumber='
obj = context['obj']
context['stages'] = DraftLawForList(obj,obj.bureau_date)
context['url_feed'] = reverse('draftlaw_feed_detail', args=[obj.pk])
context['draftlaw_url'] = draftlaw_url
set_language_changer(self.request, obj.get_absolute_url)
return context
示例9: blog_archive_author
def blog_archive_author(request, **kwargs):
blog_slug = kwargs.pop('blog_slug')
author = kwargs.pop('author')
kwargs['queryset'] = kwargs['queryset'].published().filter(
blog__slug=blog_slug, entrytitle__author__username=author).distinct()
kwargs['extra_context'] = {
'author': author,
'blog_slug': blog_slug,
}
set_language_changer(request, language_changer)
return object_list(request, **kwargs)
示例10: process_request
def process_request(self, request):
set_language_changer(request, _SimpleLanguageChanger(request))
host = request.get_host().lower().strip()
if 'localhost' in host or not host or host=='testserver' or settings.INSIDE_TESTING:
return None
if host[:3] in ('www','dev'):
host = host[4:]
if ':' in host:
host = host[:host.find(':')]
host_hash = md5(host+'iddqd').hexdigest()
return None
示例11: get_context_data
def get_context_data (self, **kwargs):
context = super(Detail, self).get_context_data(**kwargs)
context['counts1'] = VotingRecordResult.get_counts(record=context['obj'],session=1)
context['votes1'] = VotingRecordResult.objects.filter(record=context['obj'], session=1)
context['counts2'] = VotingRecordResult.get_counts(record=context['obj'],session=2)
context['votes2'] = VotingRecordResult.objects.filter(record=context['obj'], session=2)
context['counts3'] = VotingRecordResult.get_counts(record=context['obj'],session=3)
context['votes3'] = VotingRecordResult.objects.filter(record=context['obj'], session=3)
order_by = VotingRecord._meta.ordering
context['amended_by'] =\
context['obj'].amended_by.all().order_by(*order_by)
context['amending'] =\
context['obj'].amending.all().order_by(*order_by)
set_language_changer(self.request, context['obj'].get_absolute_url)
return context
示例12: get
def get(self, request, *args, **kwargs):
# triggers a redirect if the old category url format is used.
category = self.get_category_or_404()
category_url = category.get_absolute_url(self.current_language)
if request.path != category_url:
# say we have one category with two translations:
# /en/faq/category-en/
# /de/faq/category-de/
# with this check we make sure that any request to
# /en/faq/category-de/ gets redirected to /en/faq/category-en/
return HttpResponsePermanentRedirect(category_url)
self.category = category
setattr(self.request, request_faq_category_identifier, self.category)
set_language_changer(self.request, self.category.get_absolute_url)
response = super(FaqByCategoryView, self).get(request, *args, **kwargs)
return response
示例13: get_object
def get_object(self):
try:
obj = super(EntryDateDetailView, self).get_object()
except Http404 as e:
# No entry has been found for a given language, we fallback to search for an entry in any language
# Could find multiple entries, in this way we cannot decide which one is the right one, so we let
# exception be propagated FIXME later
if is_multilingual():
try:
queryset = self.get_unfiltered_queryset()
obj = super(EntryDateDetailView, self).get_object(queryset=queryset)
except Entry.MultipleObjectsReturned as s:
raise e
# We know there is only one title for this entry, so we can simply use get()
raise Redirect(obj.entrytitle_set.get().get_absolute_url())
else:
raise e
set_language_changer(self.request, obj.language_changer)
return obj
示例14: get
def get(self, request, *args, **kwargs):
"""
This handles non-permalinked URLs according to preferences as set in
NewsBlogConfig.
"""
if not hasattr(self, 'object'):
self.object = self.get_object()
set_language_changer(request, self.object.get_absolute_url)
url = self.object.get_absolute_url()
if (self.config.non_permalink_handling == 200 or request.path == url):
# Continue as normal
return super(ArticleDetail, self).get(request, *args, **kwargs)
# Check to see if the URL path matches the correct absolute_url of
# the found object
if self.config.non_permalink_handling == 302:
return HttpResponseRedirect(url)
elif self.config.non_permalink_handling == 301:
return HttpResponsePermanentRedirect(url)
else:
raise Http404('This is not the canonical uri of this object.')
示例15: dispatch
def dispatch(self, request, *args, **kwargs):
self.namespace, self.config = get_app_instance(request)
self.request_language = get_language(request)
self.queryset = (
Event.objects.namespace(self.namespace)
.published()
.language(self.request_language)
.order_by(*ORDERING_FIELDS)
)
self.event = self.queryset.active_translations(
self.request_language, slug=kwargs['slug']).first()
if not self.event:
raise Http404("Event not found")
set_language_changer(request, self.event.get_absolute_url)
setattr(self.request, request_events_event_identifier, self.event)
if hasattr(request, 'toolbar'):
request.toolbar.set_object(self.event)
return super(EventDetailView, self).dispatch(request, *args, **kwargs)