本文整理汇总了Python中django.views.generic.detail.DetailView类的典型用法代码示例。如果您正苦于以下问题:Python DetailView类的具体用法?Python DetailView怎么用?Python DetailView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DetailView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: item_tracks
def item_tracks(request, item_id):
return DetailView.as_view(
request,
queryset = Item.objects,
object_id = item_id,
template_name = "spindle/item_tracks.html",
template_object_name = "item")
示例2: get_context_data
def get_context_data(self, **kwargs):
context = DetailView.get_context_data(self, **kwargs)
context['questions'] = self.object.get_ds_cau_hoi()
return context
示例3: deck_detail
def deck_detail(request, deck_id=None):
deck = get_deck_or_404(request.user, deck_id)
if request.user.is_authenticated:
# Redirect if the user is already subscribed to this deck.
subscriber = deck.get_subscriber_deck_for_user(request.user)
if subscriber:
return redirect(subscriber.get_absolute_url())
fact_tags = deck.fact_tags()
detail_args = {
'queryset': Deck.objects.filter(active=True),
'template_object_name': 'deck',
'extra_context': {
'field_types': FactType.objects.get(id=1).fieldtype_set.all().order_by('ordinal'),
'fact_tags': fact_tags,
'textbook_source_form': TextbookSourceForm(),
'textbook_form': TextbookForm(),
},
'object_id': deck_id,
}
#detail_args['extra_context'].update(study_options_context(request, deck_id=deck_id))
return DetailView.as_view(request, **detail_args)
示例4: get_context_data
def get_context_data(self, **kwargs):
context = DetailView.get_context_data(self, **kwargs)
category_slug = self.request.GET.get('cat', None)
category = get_category_by_slug(category_slug)
context['category'] = category
context['next_project'] = self.get_object().next(category_slug)
context['previous_project'] = self.get_object().previous(category_slug)
return context
示例5: get_context_data
def get_context_data(self, **kwargs):
context = DetailView.get_context_data(self, **kwargs)
context['khthi'] = self.object.khthi
context['thi_sinh'] = self.object.thi_sinh
context['khthi_dangthi'] = KHTHI_DANGTHI
return context
示例6: user_with_software
def user_with_software(request):
"""Deprecated"""
userlist = User.objects.filter(software__isnull=False).distinct().order_by('username')
return DetailView.as_view(request,
paginate_by=20,
queryset=userlist,
template_name='software/user_list.html',
extra_context=get_latest_news(),
)
示例7: software_all_dataformats
def software_all_dataformats(request):
"""Deprecated"""
dataformatlist = DataFormat.objects.filter(name__isnull=False).distinct().order_by('slug')
return DetailView.as_view(request,
paginate_by=20,
queryset=dataformatlist,
template_name='software/dataformat_list.html',
extra_context=get_latest_news(),
)
示例8: software_all_opsyss
def software_all_opsyss(request):
"""Deprecated"""
opsyslist = OpSys.objects.filter(name__isnull=False).distinct().order_by('slug')
return DetailView.as_view(request,
paginate_by=20,
queryset=opsyslist,
template_name='software/opsys_list.html',
extra_context=get_latest_news(),
)
示例9: preview
def preview(request, post_id, slug):
try:
post = Post.objects.select_related().get(pk=post_id, slug=slug)
if post.is_published:
return HttpResponsePermanentRedirect(post.get_absolute_url())
else:
return DetailView.as_view(
model=Post, queryset=Post.objects.select_related().all(), object_id=post_id, context_object_name="post"
)
except Post.DoesNotExist:
return HttpResponseRedirect(reverse("blogdor_archive"))
示例10: get
def get(self, request, *args, **kwargs):
self.object.notificacoes.unread().filter(
user=request.user).update(
read=True,
modified=timezone.now())
if self.object.owner:
return redirect(
reverse_lazy('cmj.ouvidoria:solicitacao_interact',
kwargs=kwargs))
return DetailView.get(self, request, *args, **kwargs)
示例11: _post
def _post(request, year, slug):
try:
return DetailView.as_view(
model=Post,
queryset=Post.objects.published().select_related().filter(date_published__year=year),
slug=slug,
context_object_name="post",
)
except Http404, e:
try:
post = (
Post.objects.published()
.filter(date_published__year=year, slug__startswith=slug)
.latest("date_published")
)
return HttpResponseRedirect(post.get_absolute_url())
except Post.DoesNotExist:
raise e
示例12: get_object
def get_object(self, queryset=None):
"""
Supports ALL of the types of permalinks that we've defined in urls.py.
However, it does require that either the id and the slug is available
and unique.
"""
if queryset is None:
queryset = self.get_queryset()
slug = self.kwargs.get(self.slug_url_kwarg, None)
pk = self.kwargs.get(self.pk_url_kwarg, None)
if pk is not None:
# Let the DetailView itself handle this one
return DetailView.get_object(self, queryset=queryset)
elif slug is not None:
# Let the TranslatedSlugMixin take over
return super(ArticleDetail, self).get_object(queryset=queryset)
raise AttributeError('ArticleDetail view must be called with either '
'an object pk or a slug')
示例13: generic_wrapper
def generic_wrapper(request, *args, **kwargs):
"""
This allows us to get the mediatype variable from the url and pass the
correct queryset to the generic view
"""
if 'mediatype' in kwargs and kwargs['mediatype'] in media_dict:
mediatype = kwargs.pop('mediatype')
queryset = media_dict[mediatype]['queryset']
if 'extra_context' in kwargs:
kwargs['extra_context'].update({'mediatype': mediatype})
else:
kwargs['extra_context'] = {'mediatype': mediatype}
if 'enlarge' in kwargs:
kwargs.pop('enlarge')
kwargs['template_name'] = 'massmedia/enlarge_%s_detail.html' % mediatype
if 'slug' in kwargs or 'object_id' in kwargs:
return DetailView.as_view(queryset=queryset)(request, *args, **kwargs)
if 'template_name' not in kwargs:
kwargs['template_name'] = 'massmedia/list.html'
return ListView.as_view(queryset=queryset)(request, *args, **kwargs)
return HttpResponseNotFound()
示例14: thread
def thread(request, forum, thread):
"""
Increments the viewed count on a thread then displays the
posts for that thread, in chronological order.
"""
f = get_object_or_404(Forum, slug=forum)
t = get_object_or_404(Thread, pk=thread)
p = t.post_set.all().order_by("time")
t.views += 1
t.save()
inputform = create_newpostform(request)
extra = get_latest_news()
extra["forum"] = f
extra["form"] = inputform
extra["thread"] = t
extra["form_action"] = "reply/"
return DetailView.as_view(
request, paginate_by=10, queryset=p, template_name="community/thread.html", extra_context=extra
)
示例15: reply
def reply(request, forum, thread):
"""
If a thread isn't closed, and the user is logged in, post a reply
to a thread. Note we don't have "nested" replies at this stage.
"""
f = get_object_or_404(Forum, slug=forum)
t = get_object_or_404(Thread, pk=thread)
p = t.post_set.all().order_by("-time")[:1]
if t.closed:
return HttpResponseRedirect("/accounts/login?next=%s" % request.path)
if request.method == "POST":
form = create_newpostform(request)
if form.is_valid():
if request.user.is_authenticated() or form.login(request):
p = Post(thread=t, author=request.user, body=form.cleaned_data["body"], time=datetime.now())
if form.data.has_key(u"post"):
p.save()
return HttpResponseRedirect(p.get_absolute_url())
else:
return render_to_response(
"community/thread.html",
RequestContext(
request, {"forum": f, "form": form, "thread": t, "posting": p, "form_action": ""}
),
)
else:
form = create_newpostform(request)
return DetailView.as_view(
request,
paginate_by=10,
queryset=p,
template_name="community/thread.html",
extra_context={"forum": f, "form": form, "thread": t, "form_action": ""},
)