本文整理汇总了Python中django.views.generic.detail.DetailView.as_view方法的典型用法代码示例。如果您正苦于以下问题:Python DetailView.as_view方法的具体用法?Python DetailView.as_view怎么用?Python DetailView.as_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.views.generic.detail.DetailView
的用法示例。
在下文中一共展示了DetailView.as_view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deck_detail
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
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)
示例2: item_tracks
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
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")
示例3: user_with_software
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
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(),
)
示例4: software_all_dataformats
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
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(),
)
示例5: software_all_opsyss
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
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(),
)
示例6: preview
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
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"))
示例7: _post
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
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
示例8: generic_wrapper
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
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()
示例9: thread
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
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
)
示例10: reply
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
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": ""},
)
示例11: patterns
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from django.conf.urls import patterns, url
from languages.models import Language
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
urlpatterns = patterns('',
url(r'^(?P<slug>[[email protected]\w]+)/$', DetailView.as_view(
queryset=Language.objects.all(),
slug_field='code',
context_object_name='language',
template_name='languages/language_detail.html'),
name = 'language_detail'),
url(r'^$', ListView.as_view(
queryset=Language.objects.all(),
context_object_name='language_list',
template_name='languages/language_list.html'),
name = 'language_list'),
)
示例12: url
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
from django.conf.urls import patterns, url, include
from django.views.generic import ListView
from django.views.generic.detail import DetailView
from . import models
from . import views
urlpatterns = [
url(r'^list/$', ListView.as_view(model=models.Scan),name='list'),
url(r'^detail/(?P<pk>\d+)/$', DetailView.as_view(model=models.Scan),name='detail'),
url(r'^create/$', views.ScanCreate.as_view()),
]
示例13: patterns
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
from .views import UserRegister, UserEdit, EventAdd, EventEdit, EventSearch, EventDelete, login_or_redirect, \
event_attend, user_follow
from .models import Event
# ##FOR TESTING ONLY###
from django.conf import settings
from django.conf.urls.static import static
# #####################
urlpatterns = patterns('',
url(r'^$', login_or_redirect, name="login"),
url(r'^logout/$', 'django.contrib.auth.views.logout_then_login', name="logout"),
url(r'^register/$', UserRegister.as_view(), name="register"),
url(r'^event/new$', login_required(EventAdd.as_view()), name="event-new"),
url(r'^event/delete/(?P<pk>\d+)/$', EventDelete.as_view(), name="event-delete"),
url(r'^event/edit/(?P<pk>\d+)/$', EventEdit.as_view(), name="event-edit"),
url(r'^event/(?P<pk>\d+)/$', login_required(DetailView.as_view(model=Event,
template_name='event/detail.html')),
name="event-detail"),
url(r'^event/search$', login_required(EventSearch.as_view()), name="event-search"),
url(r'^user/(?P<pk>\d+)/$', login_required(DetailView.as_view(model=User,
template_name='website/profile.html')),
name="user-profile"),
url(r'^event/attend/$', event_attend, name="event-attend"),
url(r'^user/follow/$', user_follow, name="user-follow"),
url(r'^user/edit/$', login_required(UserEdit.as_view()), name="user-edit"),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # FOR TESTING ONLY
示例14: url
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
url(r'^timeline/$', TimelineList.as_view(), name='timeline'),
url(r'^eventinfo/$', views.eventinfo, name='eventinfo'),
url(r'^graph/$', views.testgraph, name='graph'),
url(r'^prioritygraph/$', views.testgraphpriority, name='prioritygraph'),
url(r'^resolvegraph/$', views.resolvegraph, name='resolvegraph'),
url(r'^reqgraph/$', views.reqgraph, name='reqgraph'),
url(r'^reqprioritygraph/$', views.reqtestgraphpriority, name='reqprioritygraph'),
url(r'^reqresolvegraph/$', views.reqresolvegraph, name='reqresolvegraph'),
url(r'^author/(?P<pk>\d+)/$', views.userview, name='author'),
# tasks
url(r'^tasks/$', ListView.as_view(model=Task), name='tasks'),
url(r'^tasks/(?P<pk>\d+)/$', DetailView.as_view(model=Task), name='tdetail'),
url(r'^tasks/update/(?P<pk>\d+)/$', TaskUpdate.as_view(), name='task_update'),
url(r'^tasks/create/$', TaskCreate.as_view(), name='task_create'),
url(r'^task_ajax_comment/$', views.ajax_comment, name='task_ajax_comment', kwargs={'object_type':Task}),
url(r'statistics/$', views.StatisticsIndexView.as_view(), name='statistics'),
url(r'tags/$', TagsList.as_view(), name='tags'),
url(r'addtag/$', TagCreate.as_view(), name='addtag'),
url(r'tagdetail/(?P<pk>\d+)/$', TagDetail.as_view(), name='tagdetail'),
url(r'tagedit/(?P<pk>\d+)/$', TagUpdate.as_view(), name='tagedit'),
)
示例15: patterns
# 需要导入模块: from django.views.generic.detail import DetailView [as 别名]
# 或者: from django.views.generic.detail.DetailView import as_view [as 别名]
from django.contrib.auth.decorators import login_required
from django.views.generic.detail import DetailView
from django.conf.urls import patterns, url
from .models import Job
from .views import JobCreate, JobList, JobDelete, JobUpdate, JobsFeed
urlpatterns = patterns('',
url(r'^$', JobList.as_view(), name='jobs_list_all'),
url(r'^rss$', JobsFeed(), name='jobs_feed'),
url(r'^add/$', login_required(
JobCreate.as_view()), name='jobs_add'),
url(r'^(?P<slug>[\w-]+)/$',
DetailView.as_view(model=Job),
name='jobs_view'),
url(r'^(?P<pk>\d+)/delete/$',
login_required(JobDelete.as_view()),
name='jobs_delete'),
url(r'^(?P<pk>\d+)/update/$',
login_required(JobUpdate.as_view()),
name='jobs_update'),
url(r'^tag/(?P<tag>[\w-]+)/$',
JobList.as_view(),
name='jobs_list_by_tag'),
)