コード例 #1
0
ファイル: query.py プロジェクト: amnan181/new-social-api
class ProductType(ObjectType):
    id = Int(required=True)
    title = String(required=True)
    slug = String(required=True)
    price = Decimal(required=True, default_value=0.0)
    description = String(required=True)
    stack = Int(required=True)
    available = Boolean(required=True, default_value=True)
    sale_percent = Decimal(required=True, default_value=0.0)
    weight = Float(required=True)
コード例 #2
0
class EnrollmentType(DjangoObjectType):
    enrollment_balance = Decimal(source='enrollment_balance')
    sessions_left = Int(source='sessions_left')
    last_paid_session_datetime = DateTime(source='last_paid_session_datetime')

    class Meta:
        model = Enrollment
コード例 #3
0
class Game(ObjectType):
    gameId = String()
    gameWeekYear = String()
    date = String()
    dateIsValid = Boolean()
    network = String()
    home = String()
    visitor = String()
    homeAbbreviation = String()
    visitorAbbreviation = String()
    isNeutralSite = Boolean()
    homeTeam = Field(Team)
    visitorTeam = Field(Team)
    homeFinalScore = Decimal()
    visitorFinalScore = Decimal()
    headline = String()
コード例 #4
0
class Team(ObjectType):
    id = Decimal()
    abbreviation = String()
    alternateColor = String()
    color = String()
    conference = Field(Conference)
    displayName = String()
    location = String()
    name = String()

    def resolve_conference(parent, info, **kwargs):
        global conferences_cache

        if len(conferences_cache):
            return conferences_cache[int(parent.conference)]

        db = boto3.resource('dynamodb')
        leaguesTable = db.Table('cfb-guide-prod-leagues')

        response = leaguesTable.scan(Select='ALL_ATTRIBUTES')

        for item in response['Items']:
            conf_id = int(item['id'])
            conferences_cache[conf_id] = item

        return conferences_cache[int(parent.conference)]
コード例 #5
0
class ProductType(ObjectType):
    id = String(required=True)
    name = String(required=True)
    short_name = String()
    price = Decimal()
    description = String()
    picture = String()
コード例 #6
0
class EnrollmentType(DjangoObjectType):
    enrollment_balance = Decimal(source="enrollment_balance")
    sessions_left = Int(source="sessions_left")
    last_paid_session_datetime = DateTime(source="last_paid_session_datetime")

    class Meta:
        model = Enrollment
コード例 #7
0
def convert_field_to_decimal(
    field,
    registry=None,
    required=None,
    field_many_to_many_extras=None,
    field_foreign_key_extras=None,
    field_one_to_one_extras=None,
):
    return Decimal(description=field.help_text,
                   required=is_required(field, required))
コード例 #8
0
ファイル: mutations.py プロジェクト: jsflca2012/mainframe
    class Arguments:
        course_id = ID(name='id')
        course_type = CourseTypeEnum()
        academic_level = AcademicLevelEnum()
        title = String()
        description = String()
        instructor_id = ID(name='instructor')
        hourly_tuition = Decimal()
        total_tuition = Decimal()
        course_category_id = ID(name='courseCategory')

        # Logistical information
        room = String()
        day_of_week = DayOfWeekEnum()
        start_date = DateTime()
        end_date = DateTime()
        start_time = Time()
        end_time = Time()
        max_capacity = Int()
        is_confirmed = Boolean()
コード例 #9
0
ファイル: mutations.py プロジェクト: omou-org/mainframe
    class Arguments:
        course_id = ID(name="id")
        course_type = CourseTypeEnum()
        academic_level = AcademicLevelEnum()
        title = String()
        description = String()
        instructor_id = ID(name="instructor")
        hourly_tuition = Decimal()
        total_tuition = Decimal()
        course_category_id = ID(name="courseCategory")

        course_link = String()
        course_link_description = String()

        google_class_code = String()

        # Logistical information
        room = String()
        start_date = DateTime()
        end_date = DateTime()
        max_capacity = Int()
        is_confirmed = Boolean()
        availabilities = List(CourseAvailabilityInput)
コード例 #10
0
def convert_field_to_decimal(field, registry=None):
    return Decimal(description=field.help_text, required=not field.null)
コード例 #11
0
class Conference(ObjectType):
    id = Decimal()
    name = String()
    parent_id = Decimal()
コード例 #12
0
class Query:
    berth_products = DjangoConnectionField(
        BerthProductNode,
        description="**Requires permissions** to access payments.",
    )
    berth_product = Node.Field(
        BerthProductNode,
        description="**Requires permissions** to access payments.",
    )
    berth_product_for_width = Field(
        BerthProductNode,
        width=Decimal(required=True),
        description="**Requires permissions** to access payments.",
    )

    winter_storage_products = DjangoConnectionField(
        WinterStorageProductNode,
        description="**Requires permissions** to access payments.",
    )
    winter_storage_product = Node.Field(
        WinterStorageProductNode,
        description="**Requires permissions** to access payments.",
    )

    additional_products = DjangoConnectionField(
        AdditionalProductNode,
        product_type=AdditionalProductTypeEnum(),
        description="**Requires permissions** to access payments.",
    )
    additional_product = Node.Field(
        AdditionalProductNode,
        description="**Requires permissions** to access payments.",
    )
    additional_product_services = List(
        AdditionalProductServiceNode, product_type=AdditionalProductTypeEnum())

    order = Node.Field(
        OrderNode,
        description="**Requires permissions** to access payments.",
    )
    orders = DjangoConnectionField(
        OrderNode,
        statuses=List(OrderStatusEnum),
        order_type=OrderTypeEnum(),
        description="**Requires permissions** to access payments.",
    )
    order_refunds = DjangoConnectionField(
        OrderRefundNode,
        order_id=ID(required=True),
        description="Returns the Order Refund objects associated to the order."
        "\n\n**Requires permissions** to access payments.",
    )
    berth_switch_offer = Node.Field(
        BerthSwitchOfferNode,
        description="**Requires permissions** to access offers.",
    )
    berth_switch_offers = DjangoConnectionField(BerthSwitchOfferNode)

    order_details = Field(OrderDetailsType, order_number=String(required=True))

    @view_permission_required(BerthProduct)
    def resolve_berth_product_for_width(self, info, width, **kwargs):
        return BerthProduct.objects.get_in_range(width)

    def resolve_additional_products(self, info, **kwargs):
        product_type = kwargs.get("product_type")
        if product_type:
            product_type = AdditionalProductType(product_type)
            if product_type == AdditionalProductType.FIXED_SERVICE:
                return AdditionalProduct.objects.filter(
                    service__in=ProductServiceType.FIXED_SERVICES())
            elif product_type == AdditionalProductType.OPTIONAL_SERVICE:
                return AdditionalProduct.objects.filter(
                    service__in=ProductServiceType.OPTIONAL_SERVICES())

        return AdditionalProduct.objects.all()

    def resolve_additional_product_services(self, info, **kwargs):
        service_list = list(ProductServiceType)
        product_type = kwargs.get("product_type")

        if product_type:
            product_type = AdditionalProductType(product_type)
            if product_type == AdditionalProductType.FIXED_SERVICE:
                service_list = ProductServiceType.FIXED_SERVICES()
            elif product_type == AdditionalProductType.OPTIONAL_SERVICE:
                service_list = ProductServiceType.OPTIONAL_SERVICES()

        return [
            AdditionalProductServiceNode(service=service)
            for service in service_list
        ]

    def resolve_orders(self, info, order_type=None, statuses=None, **kwargs):
        qs = Order.objects.all()
        if order_type:
            if order_type == "BERTH":
                qs = Order.objects.berth_orders()
            else:
                qs = Order.objects.winter_storage_orders()

        if statuses:
            qs = qs.filter(status__in=statuses)
        return qs

    def resolve_order_refunds(self, info, order_id, **kwargs):
        return OrderRefund.objects.filter(
            order_id=from_global_id(order_id, OrderNode))

    def resolve_order_details(self, info, order_number):
        try:
            order = Order.objects.get(order_number=order_number)
        except Order.DoesNotExist as e:
            raise VenepaikkaGraphQLError(e)

        is_application_order = (hasattr(order, "lease") and getattr(
            order.lease, "application", None) is not None)

        order_type = Query._get_order_type(order)

        if isinstance(order.lease, BerthLease):
            place_number = order.lease.berth.number
            section_identifier = order.lease.berth.pier.identifier
            area_name = order.lease.berth.pier.harbor.name
        elif isinstance(order.lease, WinterStorageLease):
            if order.lease.place:
                place_number = str(order.lease.place.number)
                section_identifier = order.lease.place.winter_storage_section.identifier
                area_name = order.lease.place.winter_storage_section.area.name
            else:
                # unmarked ws lease
                place_number = None
                section_identifier = order.lease.section.identifier
                area_name = order.lease.section.area.name
        else:
            place_number = None
            section_identifier = None
            area_name = None

        return OrderDetailsType(
            status=order.status,
            order_type=order_type,
            area=area_name,
            section=section_identifier,
            place=place_number,
            is_application_order=is_application_order,
        )

    @staticmethod
    def _get_order_type(order):
        # in graphene-python, all resolvers are implictly staticmethods, so need to make this utility static too.
        order_type = OrderTypeEnum.UNKNOWN
        if order.order_type == OrderType.ADDITIONAL_PRODUCT_ORDER:
            order_type = OrderTypeEnum.ADDITIONAL_PRODUCT
        elif order.product:
            if isinstance(order.product, BerthProduct):
                order_type = OrderTypeEnum.BERTH
            elif isinstance(order.product, WinterStorageProduct):
                order_type = OrderTypeEnum.WINTER_STORAGE
        elif order.lease:
            if isinstance(order.lease, BerthLease):
                order_type = OrderTypeEnum.BERTH
            elif isinstance(order.lease, WinterStorageLease):
                order_type = OrderTypeEnum.WINTER_STORAGE
        return order_type