示例#1
0
def list(cls):
    num = int(request.args.get("num"))
    count = int(request.args.get("count"))
    if count > 20:
        return render_template('404.html')
    result = get_list(num, count, cls)
    list = []
    sum = get_count(cls)
    for item in result:
        list.append({
            'id': item['id'],
            'title': chs_to_cht(item['title']),
            'class': item['class'],
            'digest': chs_to_cht(item['digest']),
            'cover': item['cover']
        })
    all_page_name = int(sum / count) + 1
    if all_page_name > 20:
        all_page_name = 20
    data = {
        'list': list,
        'count': all_page_name,
        'cls': cls,
        'pageNum': num,
    }

    return render_template('list.html', data=data)
示例#2
0
def GetSortedPlaylist(playlist):
  if isinstance(playlist, (str, unicode)):
    playlist = model.Playlist.get(playlist)

  # Build a dict of votes this user has casted.
  voted = {}
  user = users.get_current_user()
  query = model.YouTubeVote.all().filter('playlist = ', playlist)
  query.filter('user = '******'playlist =', playlist)
  results = []
  for config in configs:
    # TODO(nav): Consider caching title/thumbnail info.
    id = GetIdFromCounterName(playlist, config.name)
    video = model.YouTubeVideo.get_by_key_name(id)
    results.append({'id': id, 'title': video.title,
                    'thumbnails': video.thumbnails,
                    'count': model.get_count(config.name),
		    'voted': id in voted})
  results.sort(lambda x, y: cmp(y['count'], x['count']))
  return results
示例#3
0
文件: util.py 项目: wzhd/Vinergy
def name_count(count=0):
    '''Generate snippet name and count'''
    try:
        count = get_count()
    except:
        pass
    count += 1
    name = b52_encode(count)
    return (name, count)
示例#4
0
文件: util.py 项目: CatTail/Vinergy
def name_count(count=0):
  '''Generate snippet name and count'''
  try:
    count = get_count()
  except:
    pass
  count += 1
  name = b52_encode(count)
  return (name, count)
示例#5
0
  def get(self):
    id = self.request.get('id', None)
    title = self.request.get('title', None)
    thumbnails = self.request.get('thumbnail', allow_multiple=True)
    playlist_key = self.request.get('p', None)
    if not id or not title:
      return self.error(404)  # TODO(nav): Better error.

    # If not supplied, return the users own playlist.
    if playlist_key is None:
      user = users.get_current_user()
      playlist = model.Playlist.get_or_insert(user.user_id(), owner=user)
      playlist_key = str(playlist.key())
    
    # Is the user trying to cast a duplicate vote?
    playlist = model.Playlist.get(playlist_key)
    user = users.get_current_user()
    query = model.YouTubeVote.all().filter('playlist = ', playlist)
    query.filter('user = '******'id = ', id)
    if query.fetch(1):
      logging.info('User %s already voted for %s in playlist %s, not counting.',
                   user, id, playlist_key)
      self.response.out.write(json.dumps(
        {'added': False, 'message': 'Already voted for this song.'}))
    else:
      model.YouTubeVideo.get_or_insert(
        id, title=title,
        thumbnails=thumbnails)
      model.increment(playlist_key, GetCounterName(playlist_key, id)) 
      vote = model.YouTubeVote(user=user, playlist=playlist, id=id)
      vote.put()

      # Return the current count for this entry, along with metadata.
      entry = { 'id': id, 'title': title, 'thumbnails': thumbnails,
		'count': model.get_count(GetCounterName(
		  playlist, id)), 'voted': True }

      self.response.out.write(json.dumps(
	{'added': True, 'entry': entry}))