From 3ed46c3f6d51d01e5353100f6fc4c9524804fcb9 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 15 Feb 2012 23:32:06 +0530 Subject: [PATCH] add random order. fixes #414 --- pandora/0xdb.jsonc | 6 ++++++ pandora/item/tasks.py | 14 ++++++++++++-- pandora/padma.jsonc | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pandora/0xdb.jsonc b/pandora/0xdb.jsonc index 4677d2af1..648654c32 100644 --- a/pandora/0xdb.jsonc +++ b/pandora/0xdb.jsonc @@ -442,6 +442,12 @@ "capability": "canSeeFiles", "find": true }, + { + "id": "random", + "title": "Random", + "type": "integer", + "columnWidth": 60 + }, { "id": "created", "title": "Date Created", diff --git a/pandora/item/tasks.py b/pandora/item/tasks.py index ff219b39e..b3b1c75f2 100644 --- a/pandora/item/tasks.py +++ b/pandora/item/tasks.py @@ -3,7 +3,8 @@ import os from datetime import timedelta, datetime import gzip - +import random +random from django.conf import settings from ox.utils import ET @@ -14,8 +15,17 @@ import models @periodic_task(run_every=timedelta(days=1)) def cronjob(**kwargs): - print "do some cleanup stuff once a day" + update_random_sort() +def update_random_sort(): + if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']): + random.seed() + ids = [f['item'] for f in models.ItemSort.objects.values('item')] + random.shuffle(ids) + n = 0 + for i in ids: + models.ItemSort.objects.filter(pk=i).update(random=n) + n += 1 @task(ignore_resulsts=True, queue='default') def update_poster(itemId): diff --git a/pandora/padma.jsonc b/pandora/padma.jsonc index 358eaf8d9..50790a3bf 100644 --- a/pandora/padma.jsonc +++ b/pandora/padma.jsonc @@ -351,6 +351,12 @@ "capability": "canSeeFiles", "find": true }, + { + "id": "random", + "title": "Random", + "type": "integer", + "columnWidth": 60 + }, { "id": "created", "title": "Date Created",