From e00b435e2c6bd3c32f91a2c66a9fd1a79600a489 Mon Sep 17 00:00:00 2001 From: Janez K Date: Tue, 20 Nov 2012 12:56:34 +0100 Subject: [PATCH] dodal ukaz za avtomatsko izpolnitev polja static_image --- .../management/commands/fill_static_images.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 workflows/management/commands/fill_static_images.py diff --git a/workflows/management/commands/fill_static_images.py b/workflows/management/commands/fill_static_images.py new file mode 100755 index 0000000..dffc4e2 --- /dev/null +++ b/workflows/management/commands/fill_static_images.py @@ -0,0 +1,21 @@ +from django.core.management.base import NoArgsCommand +from workflows.models import * + +import os + +class Command(NoArgsCommand): + help = 'This command fills the static image field of every abstract widget in the database that doesn\'t have the static image field set (by using the data from the media). Use with care.' + option_list = NoArgsCommand.option_list + def handle_noargs(self, **options): + self.stdout.write('Working') + self.stdout.flush() + ctr = 0 + for a in AbstractWidget.objects.all(): + if a.image and not a.static_image: + a.static_image = os.path.basename(a.image.name) + a.save() + self.stdout.write('.') + self.stdout.flush() + ctr = ctr + 1 + self.stdout.write(' done\n') + self.stdout.write('%i widgets affected.\n' % ctr) -- GitLab