예제 #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,
     }
예제 #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,
     )
예제 #3
0
파일: load.py 프로젝트: guldfisk/misccube
    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))
예제 #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))
예제 #5
0
파일: deckio.py 프로젝트: guldfisk/mtgorp
 def serialize(self, deck: Deck) -> t.AnyStr:
     return JsonId.serialize(deck)
예제 #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)
예제 #7
0
def serialize_cubeable_string(cubeable: Cubeable) -> t.Any:
    return str(cubeable.id) if isinstance(
        cubeable, Printing) else JsonId.serialize(cubeable)
예제 #8
0
파일: orp.py 프로젝트: guldfisk/cubeapp
 def value_to_string(self, obj):
     return JsonId.serialize(self.value_from_object(obj))
예제 #9
0
파일: orp.py 프로젝트: guldfisk/cubeapp
 def get_prep_value(self, value):
     if value is None:
         return None
     if isinstance(value, dict):
         return json.dumps(value)
     return JsonId.serialize(value)
예제 #10
0
파일: orp.py 프로젝트: guldfisk/cubeapp
 def to_native(self, value: T) -> str:
     if isinstance(value, Cardboard):
         return value.name
     return JsonId.serialize(value)
예제 #11
0
파일: orp.py 프로젝트: guldfisk/cubeapp
 def to_native(self, value: T) -> str:
     if isinstance(value, Printing):
         return str(value.id)
     return JsonId.serialize(value)
예제 #12
0
파일: views.py 프로젝트: guldfisk/cubeapp
 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),
     )
예제 #13
0
 def serialize(cls, pool: Pool) -> t.AnyStr:
     return JsonId.serialize(pool)