Exemple #1
0
    def to_dto(self,caption):

        try:
            userProfile = UserProfile.objects.get(user = caption.author)
            nickname = userProfile.nickname
        except ObjectDoesNotExist:
            nickname = 'Anonymous'
            
        captionDTO = CaptionDTO()
        photoService = PhotoService()

        #Create array from frames string and retrieve photos
        photos = Photo.objects.filter(pk__in=caption.frames.split(','))
        
        dto_array = []
        
        #Convert photos into PhotoDTOs and append them to result array
        for photo in photos:
            dto_array.append(photoService.to_dto(photo))
            
        captionDTO.photos        = dto_array
        captionDTO.thumb_path    = caption.thumb_path
        captionDTO.photo_path    = caption.photo_path
        captionDTO.caption_data  = caption.caption_data
        captionDTO.effect_data   = caption.effect_data
        captionDTO.filter_data   = caption.filter_data
        captionDTO.object_data   = caption.object_data
        captionDTO.django_id     = caption.id
        captionDTO.author_name   = nickname
        captionDTO.link          = caption.link
        
        return captionDTO
Exemple #2
0
    def addCaption(self,request,captionDTO):
            
        ip   = request.META['REMOTE_ADDR']   
        #Anonymous user
        if request.user.is_anonymous():
            user = None
        else:
            user = request.user
    
        photoService = PhotoService()

        #Batch insert photos
        #Result is array of INSERTED photos (multiple entries allowed,but not inserted)
        photos = photoService.saveCaptionPhotos(captionDTO.photos)

        #Save the queue of photos using their ids 
        frames       = ','.join(str(photo.id)   for photo in photos)
        frame_delays = ','.join(str(delay)      for delay in captionDTO.frame_delays) 
        
        #Start writing into Caption record
        caption = Caption(caption_data  = captionDTO.caption_data,
                          thumb_path    = captionDTO.thumb_path,
                          photo_path    = captionDTO.photo_path,
                          frames        = frames,
                          frame_delays  = frame_delays,
                          author        = user,
                          author_ip     = ip)
        
        caption.save()
        
        #Create nodes for Photo <-> Caption ManyToMany relationship 
        for photo in photos:
            node = Node_Caption_Photo(caption = caption,photo=photo)
            try:
                Node_Caption_Photo.objects.get(caption = caption,photo = photo)
            except:
                node.save();
        
        return self.to_dto(caption)
Exemple #3
0
def updatePhotoGateway(http_request, photoDTO):
    photoService = PhotoService()
    return photoService.updatePhoto(photoDTO, http_request.user)
Exemple #4
0
def deletePhoto(http_request, photo_id):
    photoService = PhotoService()
    return photoService.deletePhoto(photo_id, http_request.user)
Exemple #5
0
def getLatestAddedPhotos(http_request):
    photoService = PhotoService()
    return photoService.getLatestAddedPhotos()
Exemple #6
0
def getAlbumPhotos(http_request, album_id):
    photoService = PhotoService()
    return photoService.getAlbumPhotos(album_id)
Exemple #7
0
def getPhotoByLink(http_request, photo_link):
    photoService = PhotoService()
    return photoService.getPhotoByLink(photo_link)