示例#1
0
    def __init__(self,
                 db: CardDatabase,
                 document_id: str = values.DOCUMENT_ID):
        self._db = db

        self._printing_tree_parser = PrintingTreeParser(db)
        self._sheet_client = GoogleSheetClient(document_id)
示例#2
0
文件: views.py 项目: guldfisk/cubeapp
    def post(self, request, *args, **kwargs):
        serializer: serializers.ParseTrapSerializer = self.get_serializer(
            data=request.data)
        serializer.is_valid(raise_exception=True)

        try:
            intention_type = IntentionType[
                serializer.validated_data['intention_type']]
        except KeyError:
            intention_type = IntentionType.NO_INTENTION

        try:
            trap = Trap(
                node=PrintingTreeParser(
                    db,
                    allow_volatile=True,
                ).parse(serializer.validated_data['query']),
                intention_type=intention_type,
            )
        except PrintingTreeParserException as e:
            return Response(str(e), status=status.HTTP_400_BAD_REQUEST)

        return Response(orpserialize.TrapSerializer.serialize(trap),
                        status=status.HTTP_200_OK,
                        content_type='application/json')
示例#3
0
文件: views.py 项目: guldfisk/cubeapp
    def post(self, request, *args, **kwargs):
        serializer: serializers.ParseTrapSerializer = self.get_serializer(
            data=request.data)
        serializer.is_valid(raise_exception=True)

        value = serializer.validated_data.get('weight', 1)

        try:
            constrained_node = ConstrainedNode(
                node=PrintingTreeParser(
                    db,
                    allow_volatile=True,
                ).parse(serializer.validated_data['query']),
                groups=[
                    group.rstrip().lstrip() for group in
                    serializer.validated_data.get('groups', '').split(',')
                ],
                value=value if value is not None else 1,
            )
        except PrintingTreeParserException as e:
            return Response(str(e), status=status.HTTP_400_BAD_REQUEST)

        return Response(orpserialize.ConstrainedNodeOrpSerializer.serialize(
            constrained_node),
                        status=status.HTTP_200_OK,
                        content_type='application/json')
示例#4
0
    def __init__(self,
                 db: CardDatabase,
                 document_id: str = values.DOCUMENT_ID,
                 sheet_id: str = SHEET_ID):
        self._db = db
        self._printing_tree_parser = PrintingTreeParser(self._db)
        self._document_id = document_id
        self._sheet_id = sheet_id
        self._printing_matcher = re.compile(
            "\\s*([\\w\\-': ,/]+)\\|([A-Z0-9_]+)")
        self._ticket_matcher = re.compile("([\\w ]+):(.*)")
        self._id_matcher = re.compile('\\d+$')

        self._sheet_client = GoogleSheetClient(document_id)