예제 #1
0
    def post(self):
        """POST handler for gallery albums.

        URL pattern: /albums
        POST data must contain album metadata: 'name'.

        Returns 201 CREATED with JSON data structure describing new album.
        Returns Content-type: application/json.
        Also returns Location header pointing to API URL for album details.
        
        Include 'wrapjson' parameter in POST to wrap returned JSON in
        a <textarea>. This also changes the returned Content-type to text/html.

        If request is poorly formatted returns 400 BAD REQUEST.

        Returns 401 UNAUTHORIZED to all calls if authorization fails.
        """
        try:
            data = dict(((str(k), v) for k, v in self.request.POST.items()))
            album = Album(album_id=config.ALBUM_ID_GENERATOR(),
                          **data)
        except:
            data = {}
            self.error(400)
        else:
            if not config.DEMO_MODE:
                album.put() 

            data = album.to_dict()
            self.response.headers['Location'] = data['url']
            self.response.set_status(201)
        
        write_json(self, data, wrapjson='wrapjson' in self.request.POST)
예제 #2
0
    def get(self):
    	user = users.get_current_user()
        if user is not None:
            nickname = users.get_current_user().nickname()
            logInOut = users.create_logout_url(self.request.uri)
            greeting = "Please Enter Your Picasa Album Address:"
            gd_client = gdata.photos.service.PhotosService()
            
            # try delete the user's album in the DB
            # pass if can't find.
            try:
                query = "Where owner = '%s'" % (nickname)
                allAlbum = Album.gql(query)
                db.delete(allAlbum)
            except:
                print "no album deleted for %s" % (nickname)
                pass

            # Grab user album list from Google Picasa and store in DB    
            try:
                albumList = gd_client.GetUserFeed(user=user)
                for album in albumList.entry:
                    newAlbum = Album()
                    newAlbum.owner = nickname
                    newAlbum.albumName = album.title.text
                    newAlbum.albumID = album.gphoto_id.text
                    newAlbum.albumPhoto = album.numphotos.text
                    newAlbum.put()
            except:
                print "%s album not added into DB" % (nickname)
                pass
                    # Grab all available albums for the user
            nickname = users.get_current_user().nickname()
            query = "Where owner = '%s'" % (nickname)
            time.sleep(1)
            allAlbum = Album.gql(query)
            print query
            print allAlbum.count()

            template_values = {
                    'user': user,
                    'logInOut': logInOut,
                    'greeting': greeting,
                    'albumInfo': allAlbum,
            }
            return render_template(self, 'index.html', template_values)
        
        else:
            logInOut = users.create_login_url(self.request.uri)
            greeting = "Please Login to continue."

            template_values = {
                'user': user,
                'logInOut': logInOut,
                'greeting': greeting,
            }
            return render_template(self, 'index.html', template_values)
        return render_template(self, 'index.html', template_values)
예제 #3
0
    def post(self):
        user = get_user()

        if user:
            album = Album(parent=DEFAULT_DOMAIN_KEY)
            album.author = user.key
            album.name = self.request.get('album_name')
            album.description = self.request.get('album_desc')

            album.put()

            self.redirect('/album/%s/view' % album.key.integer_id())
        else:
            self.redirect_to_login()
예제 #4
0
    def post(self):
        if not users.is_current_user_admin():
            self.redirect('/')
        else:
            try:
                key = ndb.Key(urlsafe=self.request.get('key'))
                album = key.get()
            except:
                album = Album()

            album.populate(name=self.request.get('name'),
                           description=self.request.get('description'))
            album.put()

            self.redirect("/add-album?key=" + album.ukey())
예제 #5
0
def generate_data():
    faker = Faker()

    for i in range(0, 24):
        name = faker.name()
        u = User(name=name)
        u.put()
        full = faker.lorem()
        firstbio, secounddis = full[:len(full) / 2], full[len(full) / 2:]
        a = Artist(name=name,
                   owner=u._key,
                   is_active=True,
                   location=faker.full_address(),
                   bio=firstbio)
        a.put()

        cover_art = "http://lorempixel.com/1024/1024/{}".format(
            random.choice(image_sets))

        track_list = []
        for i in range(0, 12):
            t = Track(title=faker.name(),
                      artist_id=a._key,
                      artist_name=a.name,
                      source_file=random.choice(song_set),
                      explicit=False,
                      is_active=True,
                      price=CurrencyValue(amount=0, currency="USD"))
            t.put()
            track_list.append(t._key)

        alb = Album(title=faker.name(),
                    artist_name=a.name,
                    artist_id=a._key,
                    tracks=track_list,
                    cover_art=cover_art,
                    description=secounddis,
                    release_date=datetime.utcnow(),
                    genre_id=random.choice(genres),
                    price=CurrencyValue(amount=0, currency="USD"),
                    is_active=True)

        alb.put()
예제 #6
0
 def get(self):
     album = ""
     edit = 0
     # Check whether we're creating a album or a Question
     if self.request.GET['album'] == '1':
         questions = ""
         retrieve = 0
         # If coming back from cancelling /question
         if self.request.GET.get('cancel'):
             urlstring = self.request.GET['cancel']
             album_key = ndb.Key(urlsafe=urlstring)
             album = album_key.get()
             questions = Question.query(
                 ancestor=album_key).order(-Question.date).fetch()
             retrieve = 1
         else:
             album = Album(album_type=self.request.GET.get('type'))
             album.album_id = album.put().id()
             album.put()
             # self.response.write(str(album.album_id))
         template_values = {
             'album': album,
             'album_type': album.album_type,
             'questions': questions,
             'edit': edit,
             'retrieve': retrieve
         }
         template = JINJA_ENVIRONMENT.get_template('create.html')
         time.sleep(0.2)
         self.response.write(template.render(template_values))
     else:
         # Create a new Question with edit = 0 to indicate new entry
         urlstring = self.request.GET['id']
         album_key = ndb.Key(urlsafe=urlstring)
         album = album_key.get()
         template_values = {
             'album': album,
             'album_type': album.album_type,
             'edit': edit
         }
         template = JINJA_ENVIRONMENT.get_template('question.html')
         self.response.write(template.render(template_values))
예제 #7
0
	def get(self):
		album = ""
		edit = 0
		# Check whether we're creating a album or a Question
		if self.request.GET['album'] == '1':
			questions = ""
			retrieve = 0
			# If coming back from cancelling /question
			if self.request.GET.get('cancel'):
				urlstring = self.request.GET['cancel']
				album_key = ndb.Key(urlsafe=urlstring)
				album = album_key.get()
				questions = Question.query(ancestor=album_key).order(-Question.date).fetch()
				retrieve = 1
			else:
				album = Album(album_type=self.request.GET.get('type'))
				album.album_id = album.put().id()
				album.put()
				# self.response.write(str(album.album_id))
			template_values = {
				'album': album,
				'album_type': album.album_type,
				'questions': questions,
				'edit': edit,
				'retrieve': retrieve
			}
			template = JINJA_ENVIRONMENT.get_template('create.html')
			time.sleep(0.2)
			self.response.write(template.render(template_values))
		else:
			# Create a new Question with edit = 0 to indicate new entry
			urlstring = self.request.GET['id']
			album_key = ndb.Key(urlsafe=urlstring)
			album = album_key.get()
			template_values = {
				'album': album,
				'album_type': album.album_type,
				'edit': edit
			}
			template = JINJA_ENVIRONMENT.get_template('question.html')
			self.response.write(template.render(template_values))
예제 #8
0
파일: tasks.py 프로젝트: ppalucki/shcms
def update_photos():
    logging.info('-> updateing pages')
    from importing import get_docs_data, get_albums_data
    albums = get_albums_data(Var.get_value('admin'),Var.get_value('password'))
    
    docs_by_keys = dict((album['res_id'],album) for album in albums)    
    updated_or_deleted = set()
    
    updated_cnt = deleted_cnt = created_cnt = 0  
    pupdated_cnt = pdeleted_cnt = pcreated_cnt = 0
    # updateing
    for album in Album.all():        
        # delete
        if not album.res_id in docs_by_keys:
            for photo in album.photos:
                photo.delete()
                logging.info('photo %s deleted (in album=%s)', photo.res_id, album.res_id)
                pdeleted_cnt+=1
            album.delete()
            deleted_cnt+=1
            logging.info('album %s deleted'%album.res_id)
            updated_or_deleted.add( album.res_id )

        else:        
            # update existing album 
            doc = docs_by_keys[album.res_id]
            album.title = doc['title']
            album.put()            
            logging.info('album %s updated'%doc['res_id'])
            updated_or_deleted.add( album.res_id )            
            
            ######################
            # update/delete his photos            
            pupdated_or_deleted=set()
            pdocs_by_keys = dict( (pdoc['res_id'],pdoc) for pdoc in doc['photos'])
            #add/remove/update
            for photo in album.photos:
                if not photo.res_id in pdocs_by_keys:
                    photo.delete()
                    pdeleted_cnt+=1
                    logging.info('photo %s deleted (in album=%s)', photo.res_id, album.res_id)
                else:
                    pdoc = pdocs_by_keys[photo.res_id]
                    photo.title = pdoc['title']
                    photo.src = pdoc['src']
                    photo.mimetype = pdoc['mimetype']
                    photo.height = pdoc['height']
                    photo.width = pdoc['width']      
                    photo.order = doc['photos'].index(pdoc)              
                    photo.put()
                    pupdated_cnt+=1
                    logging.info('photo %s updated (in album=%s)', photo.res_id, album.res_id)                
                pupdated_or_deleted.add(photo.res_id)
            
            ######################
            ## create new photos
            new_photos_ids = set(pdocs_by_keys) - pupdated_or_deleted
            for new_photo_id in new_photos_ids:
                pdoc = pdocs_by_keys[new_photo_id]
                Photo(
                    album=album,                
                    key_name=pdoc['res_id'],
                    src=pdoc['src'],
                    title=pdoc['title'],
                    mimetype=pdoc['mimetype'],
                    height=pdoc['height'],
                    width=pdoc['width'],
                    order=doc['photos'].index(pdoc)          
                ).put()
                logging.info('photo %s created (in album=%s)', photo.res_id, album.res_id)
                pcreated_cnt+=1        
            updated_cnt+=1
        
    # new pages
    new_albums_ids = set(docs_by_keys) - updated_or_deleted
    for new_album_id in new_albums_ids:
        doc = docs_by_keys[new_album_id]
        # create new album
        album = Album(key_name=doc['res_id'],
                      title = doc['title'])
        album.put()        
        for pdoc in doc['photos']:
            # create new photo
            Photo(
                album=album,                
                key_name=pdoc['res_id'],
                src=pdoc['src'],
                title=pdoc['title'],
                mimetype=pdoc['mimetype'],
                height=pdoc['height'],
                width=pdoc['width'],
                order=doc['photos'].index(pdoc)           
            ).put()
            pcreated_cnt+=1
            logging.info('photo %s created (in album=%s)', pdoc['res_id'], album.res_id )                        
        logging.info('album %s created'%doc['res_id'])
        created_cnt+=1
        
    logging.info('<- updateing album/photos updated=%s created=%s deleted=%s pupdated=%s pcreated=%s pdeleted=%s',
                    updated_cnt, created_cnt, deleted_cnt, pupdated_cnt, pcreated_cnt, pdeleted_cnt)