Exemple #1
0
 def serialize(cls, serializeable: cubeupdate.CubeChange) -> compacted_model:
     return {
         'type': serializeable.__class__.__name__,
         'id': serializeable.persistent_hash(),
         'explanation': serializeable.explain(),
         'content': JsonId.serialize(serializeable),
         'category': serializeable.category.value,
     }
Exemple #2
0
 def upload_limited_deck(self, pool_id: t.Union[str, int], name: str,
                         deck: Deck) -> LimitedDeck:
     return LimitedDeck.deserialize(
         self._make_request(f'limited/pools/{pool_id}',
                            method='POST',
                            data={
                                'deck': JsonId.serialize(deck),
                                'name': name,
                            }),
         self,
     )
Exemple #3
0
    def _persist_cube(cls, cube: Cube) -> None:
        if not os.path.exists(cls.LOCAL_CUBES_PATH):
            os.makedirs(cls.LOCAL_CUBES_PATH)

        with open(
                os.path.join(
                    cls.LOCAL_CUBES_PATH,
                    datetime.datetime.strftime(
                        datetime.datetime.today(),
                        cls.TIMESTAMP_FORMAT,
                    ),
                ),
                'w',
        ) as f:
            f.write(JsonId.serialize(cube))
Exemple #4
0
    def persist(self, trap_collection: TrapCollection):
        if not os.path.exists(self._OUT_DIR):
            os.makedirs(self._OUT_DIR)

        with open(
                os.path.join(
                    self._OUT_DIR,
                    datetime.datetime.strftime(
                        datetime.datetime.today(),
                        self.TIMESTAMP_FORMAT,
                    ),
                ) + '.json',
                'w',
        ) as f:

            f.write(JsonId.serialize(trap_collection))
Exemple #5
0
 def serialize(self, deck: Deck) -> t.AnyStr:
     return JsonId.serialize(deck)
Exemple #6
0
def serialize_cardboard_cubeable_string(
        cardboard_cubeable: CardboardCubeable) -> t.Any:
    return cardboard_cubeable.name if isinstance(
        cardboard_cubeable,
        Cardboard) else JsonId.serialize(cardboard_cubeable)
Exemple #7
0
def serialize_cubeable_string(cubeable: Cubeable) -> t.Any:
    return str(cubeable.id) if isinstance(
        cubeable, Printing) else JsonId.serialize(cubeable)
Exemple #8
0
 def value_to_string(self, obj):
     return JsonId.serialize(self.value_from_object(obj))
Exemple #9
0
 def get_prep_value(self, value):
     if value is None:
         return None
     if isinstance(value, dict):
         return json.dumps(value)
     return JsonId.serialize(value)
Exemple #10
0
 def to_native(self, value: T) -> str:
     if isinstance(value, Cardboard):
         return value.name
     return JsonId.serialize(value)
Exemple #11
0
 def to_native(self, value: T) -> str:
     if isinstance(value, Printing):
         return str(value.id)
     return JsonId.serialize(value)
Exemple #12
0
 def get(self, request: Request, *args, **kwargs) -> Response:
     return Response(
         status=status.HTTP_200_OK,
         content_type='application/text',
         data=JsonId.serialize(self.get_object().pool),
     )
Exemple #13
0
 def serialize(cls, pool: Pool) -> t.AnyStr:
     return JsonId.serialize(pool)