当前位置: 首页>>代码示例>>Python>>正文


Python Photo.unsaved方法代码示例

本文整理汇总了Python中models.Photo.unsaved方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.unsaved方法的具体用法?Python Photo.unsaved怎么用?Python Photo.unsaved使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Photo的用法示例。


在下文中一共展示了Photo.unsaved方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: albumpage

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import unsaved [as 别名]
def albumpage(request, albumid, pageno):
    
    pageno = int(pageno)

    user = Helpers.getUser(request)
    album = get_object_or_404(Album, id=albumid, owner=user)
    
    context = {"album": album}

    # Fetch information about the requested page
    context["pageno"] = pageno

    albumpage = get_object_or_404(AlbumPage, album=albumid, pageno=pageno)
    context["albumpage"] = albumpage

    if pageno > 1:
        context["prevpageno"] = int(pageno) - 1

    if pageno < album.pages.count():
        context["nextpageno"] = int(pageno) + 1
        
    photosdict = Helpers.createPhotoDictionary(albumpage)
    context["photos"] = photosdict

    # If we returned from the search/basket page, there's a caption in the URL. Extract that
    # There is a maximum of 4 photos per page in any layout
    if request.method == 'GET':
        if "search-result-url" in request.GET:
            photono = request.GET["photono"] if "photono" in request.GET else None 
            if photono in photosdict:
                photo = photosdict[photono]
            else:
                photo = Photo(albumpage_id=albumpage.id, photono=photono)
                photosdict[photono] = photo
            photo.url = request.GET["search-result-url"]
            photo.unsaved = True
            context["unsaved"] = True
            
 
    # If this was an edit, update the objects with the new values
    if request.method == 'POST':
        # There is a maximum of 4 photos per page in any layout
        for photono in range(1, 5):
            newcaption = request.POST.get("photo-%d-caption" % photono, None)
            newurl = request.POST.get("photo-%d-url" % photono, None)
            if newcaption or newurl:
                if photono in photosdict:
                    photo = photosdict[photono]
                else:
                    photo = Photo(albumpage_id=albumpage.id, photono=photono)
                    photosdict[photono] = photo
                photo.caption = newcaption
                photo.url = newurl
                photo.save()
                album.cover = photo
                album.save()
            

    # Render response.
    # First choose the template to use for this page's layout.
    context["layouttemplate"] = 'albumpage-layout-%d.html' % albumpage.layout

    # for convenience, editmode is passed to the template as a string that can
    # be appended to URLs
    if "edit" in request.GET:
        context["editmode"] = "?edit=true"

    return render_to_response('albumpage.html', context, context_instance=RequestContext(request))
开发者ID:joooda,项目名称:omatesti,代码行数:70,代码来源:views.py


注:本文中的models.Photo.unsaved方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。