當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。