Beispiel #1
0
    def test_entity_index(self):
        author = testing.create_user()
        jack_white = Entity.create_for_testing()
        seven_nations_army = Song.create_for_testing(author)
        self.add_contribution(seven_nations_army, jack_white, True)
        jolene = Song.create_for_testing(author)
        self.add_contribution(jolene, jack_white, True)

        # Approve only Jolene.
        seven_nations_army.reviewed = False
        seven_nations_army.save()
        jolene.reviewed = True
        jolene.save()

        # General public should see only Jolene.
        response = testing.get_public_client().get(
            jack_white.get_absolute_url())
        self.assertEqual(200, response.status_code)
        self.assertEqual(1, len(response.context['songs']))

        # The author should see both.
        response = testing.get_user_client(author).get(
            jack_white.get_absolute_url())
        self.assertEqual(200, response.status_code)
        self.assertEqual(2, len(response.context['songs']))

        # Any logged-in user should see both, too.
        response = testing.get_user_client().get(jack_white.get_absolute_url())
        self.assertEqual(200, response.status_code)
        self.assertEqual(2, len(response.context['songs']))
Beispiel #2
0
    def setUp(self):
        author = testing.create_user()
        song = Song.create_for_testing(author)
        entity = Entity.create_for_testing()
        contribution = EntityContribution()
        contribution.song = song
        contribution.entity = entity
        contribution.texted = True
        contribution.save()

        song.old_slug = "some-old-slug"
        song.reviewed = True
        song.save()

        self.song = song
        self.entity = entity
Beispiel #3
0
    def handle(self, *args, **options):
        print("Creating entities for Artists.")
        for artist in Artist.objects.all():
            if not artist.entity:
                entity = Entity()
                entity.name = artist.lastname
                entity.first_name = artist.firstname
                entity.slug = artist.slug
                entity.featured = artist.display
                entity.kind = artist.kind
                entity.website = artist.website
                entity.is_band = False
                entity.save()

                artist.entity = entity
                artist.save()
                print("Created entity: " + str(entity))
            else:
                print(str(artist) + " already has an Entity.")

        print("Creating entities for Bands.")
        for band in Band.objects.all():
            if not band.entity:
                entity = Entity()
                entity.name = band.name
                entity.slug = band.slug
                entity.featured = band.display
                entity.website = band.website
                entity.is_band = True
                entity.kind = Entity.TYPE_BAND
                entity.save()

                band.entity = entity
                band.save()
                print("Created entity: " + str(entity))
            else:
                print(str(band) + " already has an Entity.")

        print("Converting ArtistContributions.")
        for artist_contribution in ArtistContribution.objects.all():
            if not artist_contribution.entity_contribution:
                entity_contribution = EntityContribution()
                entity_contribution.song = artist_contribution.song
                entity_contribution.entity = artist_contribution.artist.entity
                entity_contribution.performed = artist_contribution.performed
                entity_contribution.texted = artist_contribution.texted
                entity_contribution.translated = artist_contribution.translated
                entity_contribution.composed = artist_contribution.composed
                entity_contribution.save()

                artist_contribution.entity_contribution = entity_contribution
                artist_contribution.save()
                print("Created entity cont.: " + str(entity_contribution))
            else:
                print(str(artist_contribution) + " already has an Entity.")

        print("Converting BandContributions.")
        for band_contribution in BandContribution.objects.all():
            if not band_contribution.entity_contribution:
                entity_contribution = EntityContribution()
                entity_contribution.song = band_contribution.song
                entity_contribution.entity = band_contribution.band.entity
                entity_contribution.performed = band_contribution.performed
                entity_contribution.texted = False
                entity_contribution.translated = False
                entity_contribution.composed = False
                entity_contribution.save()

                band_contribution.entity_contribution = entity_contribution
                band_contribution.save()
                print("Created entity cont.: " + str(entity_contribution))
            else:
                print(str(band_contribution) + " already has an Entity.")

        print("Converting artist performances.")
        for event in Event.objects.all():
            for artist in event.artists.all():
                entity_performance = EntityPerformance()
                entity_performance.event = event
                entity_performance.entity = artist.entity
                entity_performance.save()

                artist.entity.still_plays = True
                artist.entity.save()
                print("Added entity " + str(entity_performance.entity) + " on event " + str(event))

            for band in event.bands.all():
                entity_performance = EntityPerformance()
                entity_performance.event = event
                entity_performance.entity = band.entity
                entity_performance.save()

                band.entity.still_plays = True
                band.entity.save()
                print("Added entity " + str(entity_performance.entity) + " on event " + str(event))