Exemple #1
0
    def handle(self, *args, **options):
        if not os.path.isdir(options["folder"]):
            raise Exception("You must specify a directory to import")

        foldername = os.path.relpath(options["folder"])
        album, date, title = foldername.split("_", maxsplit=2)
        date = parse_date("{}-{}-{}".format(date[:4], date[4:6], date[6:]))
        slug = slugify("-".join([str(date), title]))

        if Album.objects.filter(title=title, date=date).exists():
            self.stdout.write(
                "An album with title ({}) and"
                " date ({}) already exists.".format(title, date)
            )
            return

        self.stdout.write("Importing album '{}' ({})".format(title, str(date)))
        album = Album(title=title, date=date, slug=slug)
        album.save()

        n = 0
        for filename in os.listdir(options["folder"]):
            try:
                photo = Photo(album=album)
                file = open(os.path.join(options["folder"], filename), "rb")
                photo.file.save(filename, File(file))
                photo.save()
                n += 1
            except Exception:
                self.stdout.write("Could not import {}".format(filename))

        self.stdout.write("Imported {} photos from {}".format(n, options["folder"]))
Exemple #2
0
 def save(self, *args, **kwargs):
     new = False
     if not self.id:
         album = Album(title="Playdate Photos", created_by=self.organizer)
         album.save()
         self.album=album;
         new=True
     
     super(Playdate, self).save(*args, **kwargs)
     if new:
         self.album.owner = self
         self.album.save()
Exemple #3
0
 def save(self, *args, **kwargs):
     new = False
     if not self.id:
         new = True
         album = Album(title="Profile Photos")
         album.save()
         self.album=album;
     
     super(Child, self).save(*args, **kwargs)
     if new:
         self.album.owner = self
         self.album.save()
Exemple #4
0
    def save(self, *args, **kwargs):
        new = False
        if not self.id:
            new = True
            album = Album(title="Profile Photos")
            album.save()
            self.album = album

        super(Child, self).save(*args, **kwargs)
        if new:
            self.album.owner = self
            self.album.save()
    def test_get_annotated_accessible_albums(self):
        request = self.rf.get("/")
        request.member = None
        album = Album(date=datetime(year=2017, month=1, day=1), slug="test")
        album.save()

        self.assertEqual(Album.objects.count(), 1)

        with self.subTest(membership=None):
            albums = Album.objects.all()
            albums = get_annotated_accessible_albums(request, albums)
            for album in albums:
                self.assertFalse(album.accessible)

        request.member = self.member
        with self.subTest(membership=None):
            albums = Album.objects.all()
            albums = get_annotated_accessible_albums(request, albums)
            for album in albums:
                self.assertFalse(album.accessible)

        membership = Membership.objects.create(
            user=self.member,
            type=Membership.MEMBER,
            since=datetime(year=2016, month=1, day=1),
        )
        with self.subTest(membership_since=membership.since,
                          membership_until=membership.until):
            albums = Album.objects.all()
            albums = get_annotated_accessible_albums(request, albums)
            for album in albums:
                self.assertTrue(album.accessible)

        membership.until = datetime(year=2016, month=1, day=1)
        membership.save()
        with self.subTest(membership_since=membership.since,
                          membership_until=membership.until):
            albums = Album.objects.all()
            albums = get_annotated_accessible_albums(request, albums)
            for album in albums:
                self.assertFalse(album.accessible)

        membership.until = datetime(year=2017, month=1, day=1)
        membership.save()
        with self.subTest(membership_since=membership.since,
                          membership_until=membership.until):
            albums = Album.objects.all()
            albums = get_annotated_accessible_albums(request, albums)
            for album in albums:
                self.assertTrue(album.accessible)
Exemple #6
0
    def save(self, *args, **kwargs):
        new = False
        if not self.id:
            album = Album(title="Profile Photos", created_by=self.user)
            album.save()
            self.album = album
            new = True
            # create first update
            up = create_update(self.user, "user_joined")
            create_user_update(self.user, up)

        super(Profile, self).save(*args, **kwargs)
        if new:
            self.album.owner = self
            self.album.save()
Exemple #7
0
    def save(self, *args, **kwargs):
        new = False
        if not self.id:
            album = Album(title="Profile Photos", created_by=self.user)
            album.save()
            self.album=album;
            new=True
            # create first update
            up = create_update(self.user, "user_joined")
            create_user_update(self.user, up)

        
        super(Profile, self).save(*args, **kwargs)
        if new:
            self.album.owner = self
            self.album.save()
    def test_is_album_accessible(self):
        request = self.rf.get("/")
        request.member = None
        album = Album(date=datetime(year=2017, month=1, day=1), slug="test")

        with self.subTest(membership=None):
            self.assertFalse(is_album_accessible(request, album))

        request.member = self.member
        with self.subTest(membership=None):
            self.assertFalse(is_album_accessible(request, album))

        membership = Membership.objects.create(
            user=self.member,
            type=Membership.MEMBER,
            since=datetime(year=2016, month=1, day=1),
        )
        with self.subTest(membership_since=membership.since,
                          membership_until=membership.until):
            self.assertTrue(is_album_accessible(request, album))

        membership.until = datetime(year=2016, month=1, day=1)
        membership.save()
        with self.subTest(membership_since=membership.since,
                          membership_until=membership.until):
            self.assertFalse(is_album_accessible(request, album))

        membership.until = datetime(year=2017, month=1, day=1)
        membership.save()
        with self.subTest(membership_since=membership.since,
                          membership_until=membership.until):
            self.assertTrue(is_album_accessible(request, album))
Exemple #9
0
    def manageAlbum(self, fname, fpath) :
        self.stdout.write("Checking if the is already an album with this name")
        try :
            a = Album.objects.get(title__exact=fname)
            self.stdout.write("Album %s already present, adding pics to it" % fname)
        except :
            self.stdout.write("Album %s does not exists, creating it" % fname)
            a = Album(title=fname, date=datetime.now(), path=fpath)
            a.save()

        self.stdout.write(pformat(a))

        ls = os.listdir(fpath)
        for f in ls :
            ppath = os.path.join(fpath, f)
            if (os.path.isfile(ppath)) :
                self.addPicToAlbum(f, os.path.join(fpath, f), a.id)
        os.rmdir(fpath)
Exemple #10
0
    def create_photo_album(self):
        album = Album()

        album.title_nl = _generate_title()
        album.title_en = album.title_nl

        album.date = _faker.date_between("-1y", "today")

        album.slug = slugify("-".join([str(album.date), album.title_nl]))

        if random.random() < 0.25:
            album.hidden = True
        if random.random() < 0.5:
            album.shareable = True

        album.save()

        for _ in range(random.randint(20, 30)):
            self.create_photo(album)