Exemplo n.º 1
0
 def savePhoto(self,photo):
     
     networkService = NetworkService()
     network = networkService.saveNetwork(photo.network_name)
     now = datetime.now()
     
     try:
         #Photo has been inserted before
         if photo.django_id != 0:
             photo = Photo.objects.get(id=photo.django_id)
             photo.is_captioned = True
             photo.last_caption_date = now
             photo.save()
             #Add photo to result array
             return photo
         #Copies of new photos are in the source array
         else:
             photo = Photo.objects.get(network = network,
                                       foreign_photo_id = photo.photo_id,
                                       foreign_album_id = photo.album_id,
                                       foreign_owner_id = photo.owner_id
                                       )
             photo.is_captioned = True
             photo.last_caption_date = now
             photo.save()
             #Add photo to result array
             return photo
     except ObjectDoesNotExist:
         #return 'photo not found'
         photo = Photo(foreign_photo_id = photo.photo_id,
                       foreign_album_id = photo.album_id,
                       foreign_owner_id = photo.owner_id,
                       last_caption_date = now,
                       photo_path    = photo.photo_path,
                       thumb_path    = photo.thumb_path,
                       is_public     = True,
                       is_captioned  = True,
                       network       = network)
         
         #Insert new photo
         photo.save()
         #Add photo to result array
         return photo
Exemplo n.º 2
0
 def batch_photo_create(self,form):
     
     network_id      = form.cleaned_data['network_id']
     album_id        = form.cleaned_data['album_id']
     num_photos      = form.cleaned_data['num_photos']
     start_index     = form.cleaned_data['start_index']
     write_page_no   = form.cleaned_data['write_page_no']
     source_url      = form.cleaned_data['source_url']
     
     network = Network.objects.get(id = network_id)
     album   = Album.objects.get(id = album_id)
     
     if(start_index < 0 or num_photos <= 0):
         return
     
     for i in range(start_index,start_index+num_photos):
         
         
         photo_path  = album.s3_path +self.handle_index_format(i)+"."+DEFAULT_EXTENSION
         thumb_path  = album.s3_path +"tn_"+self.handle_index_format(i)+"."+DEFAULT_EXTENSION
         
         if(write_page_no):
             page_no = i
         else:
             page_no = 0
         
         if source_url == "":
             source_url = None
         
         photo = Photo(photo_path    = photo_path,
                       thumb_path    = thumb_path,
                       network       = network,
                       album         = album,
                       page_no       = page_no,
                       source_url    = source_url)
         
         photo.save()
     
     else:
         pass
Exemplo n.º 3
0
    def receive_single_file(self,file,user_id,album_id):
     
        uuid_name = str(uuid.uuid4())

        filename    = self.create_filename(user_id,uuid_name)
        thumbname   = self.create_thumbname(user_id,uuid_name)
        
        content = file.read()
        
        #self.store_in_s3(filename,content)
        image_jpeg = self.create_jpeg(content)
        self.store_in_s3(filename, image_jpeg)

        thumbnail       = self.create_thumbnail(content)
        self.store_in_s3(thumbname, thumbnail)
        
        size    = len(image_jpeg)
        album   = Album.objects.get(id = album_id)
        network = Network.objects.get(name='Captionmash')
 
        photo   = Photo(photo_path = AWS_ADDRESS + filename,
                        thumb_path = AWS_ADDRESS + thumbname,
                        is_public = True,
                        network = network,
                        album = album,
                        file_size = size)

        photo.save()
        
        num_photos = Photo.objects.filter(album = album,is_visible = True).count()
        
        #Set album image to uploaded image if there's no photos
        if num_photos == 1:
            album.thumb_path = photo.thumb_path
            album.photo_path = photo.photo_path
            album.save()
            
        return True