347
|
1 |
''' |
|
2 |
set just created medias and contents public |
|
3 |
''' |
|
4 |
import csv |
|
5 |
|
|
6 |
from django.conf import settings |
|
7 |
from django.core.management.base import BaseCommand |
|
8 |
from django.contrib.auth.models import Group |
|
9 |
|
|
10 |
from ldt.security.cache import cached_assign |
|
11 |
from ldt.ldt_utils.models import Content, Media |
|
12 |
|
|
13 |
|
|
14 |
class Command(BaseCommand): |
|
15 |
''' |
|
16 |
command |
|
17 |
''' |
|
18 |
|
|
19 |
def add_arguments(self, parser): |
|
20 |
''' |
|
21 |
add arguments |
|
22 |
''' |
|
23 |
parser.add_argument('-p', |
|
24 |
nargs='+', |
|
25 |
dest='pathes', |
|
26 |
default=None) |
|
27 |
|
|
28 |
def handle(self, *args, **options): |
|
29 |
''' |
|
30 |
handle command |
|
31 |
''' |
|
32 |
sources = [] |
|
33 |
for path in options['pathes']: |
|
34 |
self.stdout.write(path) |
|
35 |
try: |
|
36 |
csvfile = open(path, 'r') |
|
37 |
except IOError: |
|
38 |
self.stdout.write('file can\'t be opened') |
|
39 |
continue |
|
40 |
files = csv.reader(csvfile) |
|
41 |
sources += list([content[0] for content in files]) |
|
42 |
csvfile.close() |
|
43 |
everyone = Group.objects.get(name=settings.PUBLIC_GROUP_NAME) |
|
44 |
for source in sources: |
|
45 |
media = Media.objects.get(src=source) |
|
46 |
content = Content.objects.get(media_obj_id=media.id) |
|
47 |
content.is_public = True |
|
48 |
content.save() |
|
49 |
cached_assign('view_content', everyone, content) |
|
50 |
cached_assign('view_media', everyone, media) |
|
51 |
|
|
52 |
|