Exemplo n.º 1
0
def _sort_by(o, q):
    import cmemcache as memcache
    mc = memcache.Client([MEMCACHE], debug=0)
    peers = mc.get('peers')
    if not peers:
	peers = []
    if o == 'd':
	# date
	return q.order_by('-created')
    elif o == 'L':
	# Leechers Desc
	ids = [t['torrent__id'] for t in q.order_by('created').values('torrent__id')]
	return sort_result(ids, peers, by_seeds=False)
    elif o == 'l':
	# Leechers Asc
	ids = [t['torrent__id'] for t in q.order_by('-created').values('torrent__id')]
	return sort_result(ids, peers, asc=True, by_seeds=False)
    elif o == 'S':
	# Seeds Desc
	ids = [t['torrent__id'] for t in q.order_by('created').values('torrent__id')]
	return sort_result(ids, peers)
    elif o == 's':
	# Seeds Asc
	ids = [t['torrent__id'] for t in q.order_by('-created').values('torrent__id')]
	return sort_result(ids, peers, asc=True)
    elif o == 'B':
	# Size Desc
	return q.order_by('torrent__bytes')
    elif o == 'b':
	# Size Asc
	return q.order_by('-torrent__bytes')
    else:
	# date
	return result.order_by('-created')
Exemplo n.º 2
0
def _sort_by(o, q):
    import cmemcache as memcache
    mc = memcache.Client([MEMCACHE], debug=0)
    peers = mc.get('peers')
    if not peers:
        peers = []
    if o == 'd':
        # date
        return q.order_by('-created')
    elif o == 'L':
        # Leechers Desc
        ids = [
            t['torrent__id']
            for t in q.order_by('created').values('torrent__id')
        ]
        return sort_result(ids, peers, by_seeds=False)
    elif o == 'l':
        # Leechers Asc
        ids = [
            t['torrent__id']
            for t in q.order_by('-created').values('torrent__id')
        ]
        return sort_result(ids, peers, asc=True, by_seeds=False)
    elif o == 'S':
        # Seeds Desc
        ids = [
            t['torrent__id']
            for t in q.order_by('created').values('torrent__id')
        ]
        return sort_result(ids, peers)
    elif o == 's':
        # Seeds Asc
        ids = [
            t['torrent__id']
            for t in q.order_by('-created').values('torrent__id')
        ]
        return sort_result(ids, peers, asc=True)
    elif o == 'B':
        # Size Desc
        return q.order_by('torrent__bytes')
    elif o == 'b':
        # Size Asc
        return q.order_by('-torrent__bytes')
    else:
        # date
        return result.order_by('-created')
def summary(context):
    mc = memcache.Client([MEMCACHE], debug=0)
    peers = mc.get('peers')
    render_dict = {}
    if not peers:
	for s in SECTIONS:
	    render_dict.update({s[0]: Topic.objects.filter(section=s[0], approved=True).order_by('-created')[:10]})
	return render_dict
    now = datetime.datetime.now()
    cursor = connection.cursor()
    for s in SECTIONS:
	ids = [t['torrent__id'] for t in Topic.objects.filter(section=s[0], approved=True).order_by('-created').values('torrent__id')]
	render_dict.update({s[0]: sort_result(ids, peers, limit=10)})
    connection.close()
    context.update(render_dict)
    return context
Exemplo n.º 4
0
def summary(context):
    mc = memcache.Client([MEMCACHE], debug=0)
    peers = mc.get('peers')
    render_dict = {}
    if not peers:
        for s in SECTIONS:
            render_dict.update({
                s[0]:
                Topic.objects.filter(section=s[0],
                                     approved=True).order_by('-created')[:10]
            })
        return render_dict
    now = datetime.datetime.now()
    cursor = connection.cursor()
    for s in SECTIONS:
        ids = [
            t['torrent__id']
            for t in Topic.objects.filter(section=s[0], approved=True).
            order_by('-created').values('torrent__id')
        ]
        render_dict.update({s[0]: sort_result(ids, peers, limit=10)})
    connection.close()
    context.update(render_dict)
    return context