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


Python Photo.viewables方法代码示例

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


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

示例1: get_photo_detail

# 需要导入模块: from photos.models import Photo [as 别名]
# 或者: from photos.models.Photo import viewables [as 别名]
def get_photo_detail( request, object_id=None, photo_id=None, event_id=None, photo_detail_type=None, is_render_to_string=False ):
    # time_start = datetime.now()
    
    ct_event = ContentType.objects.get_for_model(Event)
    ct_review = ContentType.objects.get_for_model(Review)
    user = request.user
    
    if not photo_id or not photo_detail_type:
        photo_id = request.POST['photo_id']
        photo_detail_type = request.POST['photo_detail_type']
    
    #from view
    if event_id:
        # only place and user profile have event photos
        object_id = event_id
    else:
        # from view
        if object_id:
            pass
        # from ajax
        else: 
            object_id = request.POST.get('object_id', None)
    
    photo = Photo.objects.get(pk=photo_id)
    photo_owner = photo.user
    # time_end = datetime.now()
    # time_elapsed = total_milliseconds(time_end - time_start)
    # print "Stage 0.5: %d" % time_elapsed

    # if not p_photo.viewable_by(user):
    #     raise Exception("You don't have permission to see this photo.")
    #     if is_render_to_string:
    #         raise Exception("You don't have permission to see this photo.")
    #     else:
    #         raise Exception("You don't have permission to see this photo.")
    # 
    # if user.is_anonymous():
    #     raise Exception('you are not a site user')
    
    # time_start = time_end
    # time_end = datetime.now()
    # time_elapsed = total_milliseconds(time_end - time_start)    
    # print "Stage 1: %d" % time_elapsed
    
    #===========================================================================
    # special case for the view of event photo detail page 
    #===========================================================================
    if photo.content_type == ct_event:
        photo_detail_type = PhotoDetailType.EVENT_PHOTO
        object_id = photo.object_id
        url_4_html5 = reverse('event-photo-detail', args=[object_id, photo.id])
         
    if photo_detail_type == PhotoDetailType.PLACE_PHOTO:
        photos = Photo.viewables(user).filter( place=photo.place.id ).exclude(content_type=ct_event).order_by('-created')
        url_4_html5 = reverse('place-photo-detail', args=[photo.place.id, photo.id]).replace('None', '')
    
    elif photo_detail_type == PhotoDetailType.PLACE_REVIEW:
        photos = Photo.viewables(user).filter( place=photo.place.id, content_type=ct_review ).order_by('-created')
        url_4_html5 = reverse('place-review-detail', args=[photo.place.id, photo.id])
    
    elif photo_detail_type == PhotoDetailType.DISH_REVIEW:
        photos = Photo.viewables(user).filter( dish=photo.dish.id, content_type=ct_review ).order_by('-created')
        url_4_html5 = reverse('dish-review-detail', args=[photo.dish.id, photo.id])
    
    elif photo_detail_type == PhotoDetailType.USER_PHOTO:
        photos = Photo.viewables(user).filter( user=photo_owner, content_type=ct_review).order_by('-created')
        url_4_html5 = reverse('userprofile-photo-detail', args=[photo_owner.id, photo.id]).replace('None', '')
    
    elif photo_detail_type == PhotoDetailType.EVENT_PHOTO:
        event = Event.objects.get(pk=object_id)
        photos = Photo.viewables(user).filter(object_id=event.id).order_by('-created')
        url_4_html5 = reverse('userprofile-photo-detail', args=[photo_owner.id, photo.id])
    else:
        raise Http404
    
#    print "photo_detail_type: %s" % photo_detail_type
    
    
    #===========================================================================
    # keep photo sequence into session 
    #===========================================================================
    
    #ppdl is acronym of Privacy Photo Detail List 
    ppdl = request.session.get('ppdl', [] )
    
    def create_session():
        request.session['ppdl'] = list(photos)
        request.session['ppdl_created'] = datetime.utcnow()  
        request.session['ppdl_type'] = photo_detail_type
        
    # time_start = time_end        
    # time_end = datetime.now()
    # time_elapsed = total_milliseconds(time_end - time_start)    
    # print "Stage 2: %d" % time_elapsed
    # save ppdl in session at the first time user access a detail page
    if not ppdl:
        create_session()
    else:
        # ppdl = request.session['ppdl']
        ppdl_created = request.session['ppdl_created']
#.........这里部分代码省略.........
开发者ID:gage,项目名称:proto,代码行数:103,代码来源:ajax.py


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