Esempio n. 1
0
class Collection:
    urls = ["painting", "sculpture", "museum", "art", "vatican"]

    def __init__(self, museum, entry=None, choice=0, lock=0, fake=Faker()):
        self.id = -1
        self.museum = museum
        if entry is None:
            fake.add_provider(lorem)
            title_list = [i.capitalize() for i in fake.words(3)]
            title = " ".join(title_list) + " Collection"
            introduction = fake.text()
            description = "**Description:** " + fake.paragraph(10)
            image = "https://loremflickr.com/600/400/"
            image += self.urls[choice] + "?lock=" + str(lock)
            self.entry = Entry(title, introduction, image, description)
        else:
            self.entry = entry

    def __str__(self):
        return self.entry.name + "," + str(self.id)

    def __dict__(self):
        return {
            "user": self.museum.user.__dict__(),
            "collection": self.entry.__dict__(),
            "museum": {"id": self.museum.id}
        }
Esempio n. 2
0
class Museum:
    urls = ["painting", "sculpture", "museum", "art", "vatican"]

    def __init__(self, user: User, entry=None, choice=0, lock=0, fake=Faker()):
        self.id = -1
        self.user = user
        self.collections = []
        if entry is None:
            fake.add_provider(lorem)
            title_list = [i.capitalize() for i in fake.words(3)]
            title = " ".join(title_list) + " Museum"
            introduction = fake.text()
            description = "**Description:** " + fake.paragraph(10)
            image = "https://loremflickr.com/600/400/"
            image += self.urls[choice] + "?lock=" + str(lock)
            self.entry = Entry(title, introduction, image, description)
        else:
            self.entry = entry

    def __str__(self):
        return self.entry.__str__() + "," + self.user.username + "," + str(
            self.id)

    def __dict__(self):
        return {"user": self.user.__dict__(), "museum": self.entry.__dict__()}

    def add_collection(self, choice=0, lock=0, fake=Faker()):
        collection = Collection(self, choice=choice, lock=lock, fake=fake)
        r = requests.post("http://127.0.0.1:5300/request/add-collection",
                          json=collection.__dict__())
        print(r.text)
        self.collections.append(collection)

    def get_collections_ids(self):
        r = requests.get("http://127.0.0.1:5300/request/museum/" +
                         str(self.id))
        collections_list = r.json()["collectionList"]
        for collection in self.collections:
            for collection_json in collections_list:
                if collection.entry.name == collection_json["name"]:
                    collection.id = collection_json["id"]

    def add_artifact(self, collections, choice=0, lock=0, fake=Faker()):
        artifact = Artifact(self,
                            collections,
                            choice=choice,
                            lock=lock,
                            fake=Faker())
        r = requests.post("http://127.0.0.1:5300/request/add-artifact",
                          json=artifact.__dict__())
        print(r.text)