Ejemplo n.º 1
0
class Query(ObjectType):
    gyms = List(GymType, day=Date(), gym_id=String(name="id"))
    classes = List(
        ClassType,
        detail_ids=List(String),
        day=Date(),
        name=String(),
        tags=List(String),
        gym_id=String(),
        instructor=String(),
    )

    def resolve_gyms(self, info, day=None, gym_id=None):
        if gym_id is not None:
            gym = Data.gyms.get(gym_id)
            return [gym] if gym is not None else []
        return [gym for gym in Data.gyms.values() if gym.is_open(day)]

    def resolve_classes(self, info, **kwargs):
        result = []
        for classes in Data.classes_by_date.values():
            for c in classes.values():
                if c.filter(**kwargs):
                    result.append(c)
        return result
Ejemplo n.º 2
0
 class Input:
     ptnum = graphene.ID(required=False)
     lastname = graphene.String(required=True)
     firstname = graphene.String(required=True)
     birthday = Date(required=True)
     mrid = graphene.String()
     collected_at = Date(required=True)
     sample = PatientSampleInput(required=True)
Ejemplo n.º 3
0
 class Input:
     id = IntID(required=True)
     worker = IntID(required=True)
     report_date = Date(required=True)
     func_role = IntID(required=True)
     projects = graphene.List(IntID, required=True)
     process = IntID()
     sub_process = IntID()
     tasks = IntID()
     task = graphene.String()
     time_spent = Time(required=True)
     time_from = Time()
     time_to = Time()
     place = IntID(required=True)
     distance = graphene.Float()
     car = graphene.String()
     gas = graphene.String()
     where_from = graphene.String()
     where_to = graphene.String()
     money_spent = graphene.Int()
     vc_project = graphene.Int()
     vc_digits = graphene.Int()
     vc_digits_minor = graphene.Int()
     model = graphene.String()
     night_shift = graphene.Boolean()
     quality_grade = graphene.Int()
     time_grade = graphene.Int()
     comment = graphene.String()
Ejemplo n.º 4
0
class ClassType(ObjectType):
    id = String(required=True)
    gym_id = String()
    gym = Field(GymType)
    location = String(required=True)
    details_id = String(required=True)
    details = Field(ClassDetailType, required=True)
    date = Date(required=True)
    start_time = Time()
    end_time = Time()
    instructor = String(required=True)
    is_cancelled = Boolean(required=True)
    image_url = String(required=True)

    def resolve_gym(self, info):
        return Data.gyms.get(self.gym_id)

    def resolve_details(self, info):
        return Data.class_details.get(self.details_id)

    def filter(self,
               detail_ids=None,
               day=None,
               name=None,
               tags=None,
               gym_id=None,
               instructor=None):
        details = Data.class_details.get(self.details_id)
        return ((detail_ids is None or self.details_id in detail_ids)
                and (day is None or day == self.date)
                and (name is None or name in details.name)
                and (tags is None or any([tag in details.tags
                                          for tag in tags]))
                and (gym_id is None or gym_id == self.gym_id)
                and (instructor is None or instructor in self.instructor))
Ejemplo n.º 5
0
 class Input:
     ptnum = graphene.ID(required=True)
     lastname = graphene.String(required=True)
     firstname = graphene.String(required=True)
     birthday = Date(required=True)
     new_mrids = graphene.List(graphene.String, required=True)
     merge_mrids = graphene.List(MergeMRID, required=True)
Ejemplo n.º 6
0
 class Input:
     login = String(required=True)
     last_name = String(required=True)
     first_name = String(required=True)
     patronym = String()
     password = String(required=True)
     hire_date = Date(required=True)
     company = IntID(required=True)
Ejemplo n.º 7
0
class ProficiencySampleInput:
    name = graphene.String(required=True)
    source = graphene.String(required=True)
    vnum = graphene.String(required=True)
    test_code = graphene.String(required=True)
    sequence = graphene.String()
    filename = graphene.String()
    notes = graphene.String()
    labnotes = graphene.String()
    received_at = Date(required=True)
Ejemplo n.º 8
0
class Devotional(ObjectType):
    """Devotional graphql type definition."""
    id = ID()
    title = String()
    passage = String()
    body = String()
    creation_date = DateTime()
    publish_date = Date()
    author = Field(lambda: User)
    comments = List(lambda: Comment)

    def __init__(self, model, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.model = model

    @classmethod
    def get_devotional(cls, id):
        """Class method to get a Devotional instance given an id"""
        model = DevotionalModel.query.filter_by(id=id).first()

        return cls.create_devotional_from_model(model)

    @classmethod
    def create_devotional_from_model(cls, model):
        """
        Class method to create a Devotional instance given an SQLAlchemy model
        """
        return cls(
            id=model.id,
            title=model.title,
            passage=model.passage,
            body=model.body,
            creation_date=model.creation_date,
            publish_date=model.publish_date,
            model=model
        )

    def resolve_author(self, info):
        """Author resolver"""
        return User.create_user_from_model(self.model.author)

    def resolve_comments(self, info):
        """Comments resolver"""
        print(len(self.model.comments))
        print(self.model.comments[0])

        result = [Comment.create_comment_from_model(c) for c in self.model.comments]

        print(result)

        return result
Ejemplo n.º 9
0
class PatientSampleInput(graphene.InputObjectType):

    test_code = graphene.String(required=True)
    specimen_type = SpecimenType(required=True)
    sequence = graphene.String()
    filename = graphene.String()
    vnum = graphene.String(required=True)
    amplifiable = graphene.Boolean(required=True)

    physician_id = graphene.ID(required=True)
    clinic_id = graphene.ID(required=True)
    notes = graphene.String()
    labnotes = graphene.String()
    received_at = Date()
Ejemplo n.º 10
0
class Query(ObjectType):
    paged_absences = Field(PagedAbsences,
                           paged=PagedInput(required=True),
                           filters=AbsenceFilter(),
                           description='Постраничное отображение отсутствий')
    absence_reasons = List(AbsenceReasonType)
    absence_working_days = Field(AbsenceWorkingDaysType,
                                 begin=Date(required=True),
                                 end=Date(),
                                 working_days=Int())

    def resolve_paged_absences(self, info, paged, **kwargs):
        paged = {k: v for k, v in paged.items() if v is not None}
        result = Absence.objects.list_paged_absences(info, **kwargs, **paged)
        keys = ('absences', 'total_count')
        return PagedAbsences(**dict(zip(keys, result)))

    def resolve_absence_reasons(self, info):
        return AbsenceReason.objects.all()

    def resolve_absence_working_days(self,
                                     info,
                                     begin,
                                     end=None,
                                     working_days=None):
        if end:
            all_days = end - begin
            days_off = timedelta(days=DayOff.objects.filter(
                date__range=(begin, end)).count())
            working_days = (
                all_days - days_off
            ).days + 1  # Добавляем 1 день, так как дата окончания включена в период
            return AbsenceWorkingDaysType(working_days=working_days)

        if working_days:
            end = DayOff.objects.calculate_end_date(begin, working_days)
            return AbsenceWorkingDaysType(end=end)
Ejemplo n.º 11
0
class Item(ObjectType):
    key = String(required=True)
    product = Field(Product)
    upload_date = Date()
    current_price = Int()

    def resolve_key(self, info):
        if self.key not in ITEM:
            return GraphQLError("The item %s doesn't exist" % self.key)
        return self.key

    def resolve_current_price(self, info):
        return ITEM[self.key]["price"]

    def resolve_upload_date(self, info):
        return ITEM[self.key]["date"]

    def resolve_product(self, info):
        return Product(key=ITEM[self.key]["product"])
Ejemplo n.º 12
0
class BasicUserType(DjangoObjectType):
    gender = GenderChoicesPropertyEnum()
    occupations = List(String, description='Список должностей')
    birth_date = Date(description='День рождения')
    has_signature = Boolean(description='Есть подпись')

    class Meta:
        model = User
        interfaces = (UserType, )
        description = 'Объект пользователя с базовой информацией (доступно всем)'
        only_fields = ('id', 'last_name', 'first_name', 'patronym',
                       'work_phone', 'personal_phone', 'email', 'is_superuser',
                       'fired', 'head')

    def resolve_has_signature(self, info):
        if settings.DEBUG:
            img_path = os.path.abspath('warehouse\static')
            images = os.listdir(img_path)
            # print('images', images)
            for image in images:
                # print(image.rsplit('.')[0])
                if str(self.id) == image.rsplit('.')[0]:
                    # print('TRUE')
                    return True
            return False
        return False

    def resolve_gender(self, info, **kwargs):
        return self.gender

    def resolve_occupations(self, info, **kwargs):
        # noinspection PyUnresolvedReferences
        return map(lambda occupation: occupation.get_short_name(),
                   self.occupation_set.all())

    def resolve_birth_date(self, info, **kwargs):
        if info.context.user.has_perm('users.view_full_user'):
            return self.birth_date
        else:
            return None
Ejemplo n.º 13
0
def generate_type_dict(model):
    type_dict = {}
    for column in model.__table__.columns:
        if hasattr(model, 'private_fields') and column.name in model.private_fields:
            continue
        if column.type.python_type == int:
            type_dict[column.name] = Int()
        elif column.type.python_type == str:
            type_dict[column.name] = String()
        elif column.type.python_type == datetime.datetime:
            type_dict[column.name] = DateTime()
        elif column.type.python_type == datetime.date:
            type_dict[column.name] = Date()
        elif column.type.python_type == datetime.time:
            type_dict[column.name] = Time()
        elif column.type.python_type == bool:
            type_dict[column.name] = Boolean()
        elif column.type.python_type == decimal.Decimal:
            type_dict[column.name] = Float()
        else:
            raise Exception(f'Unknown column type {column.type.python_type}')
    return type_dict
Ejemplo n.º 14
0
class Query(ObjectType):
    schedule = SQLAlchemyConnectionField(
        Schedule,
        room=Int(required=True),
        day=Date(required=True),
        description="Поиск расписания занятий и зачётов по аудитории.")

    filter_group = SQLAlchemyConnectionField(Schedule,
                                             group=Int(required=True),
                                             day=Date(required=True),
                                             description="Фильтр по группам.")

    filter_teacher = SQLAlchemyConnectionField(
        Schedule,
        teacher=Int(required=True),
        day=Date(required=True),
        description="Фильтр по учителям.")

    exams = SQLAlchemyConnectionField(
        Exams,
        room=Int(required=False),
        day=Date(required=False),
        range=Date(required=False),
        description="Поиск расписания экзаменов и консультаций по аудитории.")

    gosses = SQLAlchemyConnectionField(
        Gosses,
        room=Int(required=False),
        day=Date(required=False),
        range=Date(required=False),
        description="Поиск расписания государственных экзаменов по аудитории.")

    test = SQLAlchemyConnectionField(
        Schedule,
        day=Date(required=True),
        now=Time(required=True),
        facility=Int(required=True),
        description="Список активных занятий в определенное время.")

    rooms = SQLAlchemyConnectionField(Rooms,
                                      id=Int(required=False),
                                      description="Поиск аудиторий(id).")

    node = relay.Node.Field()
    study_time = relay.node.Field(StudyTime, description="")
    week_day = SQLAlchemyConnectionField(WeekType, description="")
    lesson_type = SQLAlchemyConnectionField(LessonType, description="")
    day_type = SQLAlchemyConnectionField(DayType, description="")
    person = SQLAlchemyConnectionField(Personnel, description="")
    kurs_type = SQLAlchemyConnectionField(KursType, description="")
    wplan_kurs = SQLAlchemyConnectionField(WplanKurs, description="")
    block_type = SQLAlchemyConnectionField(BlockType, description="")
    teachers = SQLAlchemyConnectionField(Teachers, description="")
    corpus_type = SQLAlchemyConnectionField(CorpusType, description="")
    group = SQLAlchemyConnectionField(GroupSh, description="")
    wplangos = SQLAlchemyConnectionField(Wplangosexam, description="")

    def resolve_test(self, info, **args):
        day = args.get("day")
        facility = args.get("facility")
        now = args.get("now")

        res = Schedule.get_query(info).\
            join(StudytimeModel).\
            join(RoomsModel, CorpustypeModel).\
            filter(CorpustypeModel.id == facility).\
            filter(
                between(day, ScheduleModel.sem_beg, ScheduleModel.sem_end)
            ).\
            filter(
                between(now, StudytimeModel.time_start, StudytimeModel.time_end)
            ).\
            all()

        return res

    def resolve_rooms(self, info, **args):
        id = args.get("id")
        res = Rooms.get_query(info)

        if id:
            res = Rooms.get_query(info).\
                join(CorpustypeModel).\
                filter(CorpustypeModel.id == id)

        return res.all()

    def resolve_schedule(self, info, **args):
        room = args.get("room")
        last_day = args.get("day")

        first_day = last_day - timedelta(days=6)

        res = Schedule.get_query(info).\
            filter(ScheduleModel.id_rooms == room).\
            filter(
                or_(
                    between(last_day, ScheduleModel.sem_beg, ScheduleModel.sem_end),
                    between(first_day, ScheduleModel.sem_beg, ScheduleModel.sem_end),
                    between(ScheduleModel.sem_beg, first_day, last_day),
                    between(ScheduleModel.sem_end, first_day, last_day)
                )
            ).all()

        return res

    def resolve_filter_group(self, info, **args):
        last_day = args.get("day")
        group = args.get("group")

        first_day = last_day - timedelta(days=6)

        res = Schedule.get_query(info).\
            join(GroupshModel).\
            filter(GroupshModel.id == group).\
            filter(
                or_(
                    between(last_day, ScheduleModel.sem_beg, ScheduleModel.sem_end),
                    between(first_day, ScheduleModel.sem_beg, ScheduleModel.sem_end),
                    between(ScheduleModel.sem_beg, first_day, last_day),
                    between(ScheduleModel.sem_end, first_day, last_day)
                )
            ).all()

        return res

    def resolve_filter_teacher(self, info, **args):
        last_day = args.get("day")
        teacher = args.get("teacher")

        first_day = last_day - timedelta(days=6)

        res = Schedule.get_query(info).\
            join(PersonnelModel).\
            join(TeachersModel).\
            filter(TeachersModel.id == teacher).\
            filter(
                or_(
                    between(last_day, ScheduleModel.sem_beg, ScheduleModel.sem_end),
                    between(first_day, ScheduleModel.sem_beg, ScheduleModel.sem_end),
                    between(ScheduleModel.sem_beg, first_day, last_day),
                    between(ScheduleModel.sem_end, first_day, last_day)
                )
            ).all()

        return res

    def resolve_exams(self, info, **args):
        room = args.get("room")
        today = args.get("day")
        res = Exams.get_query(info).\
            filter(SchedulexamModel.id_room == room). \
            filter(SchedulexamModel.date_exam == today)
        return res.all()

    def resolve_gosses(self, info, **args):
        room = args.get("room")
        today = args.get("sdate")
        res = Gosses.get_query(info).\
            filter(SchedulegosexamModel.id_room == room). \
            filter(SchedulegosexamModel.date_exam == today)
        return res.all()
Ejemplo n.º 15
0
def convert_form_field_to_date(field):
    return Date(description=field.help_text, required=field.required)
Ejemplo n.º 16
0
class Query(object):
    tuitionRule = Field(TuitionRuleType, tuitionRule_id=ID())
    discount = Field(DiscountType, discount_id=ID())
    # multiCourseDiscount = Field(MultiCourseDiscountType, multiCourseDiscount_id=ID())
    # dateRangeDiscount = Field(DateRangeDiscountType, dateRangeDiscount_id=ID())
    # paymentMethodDiscount = Field(
    #     PaymentMethodDiscountType, paymentMethodDiscount_id=ID()
    # )

    tuitionRules = List(TuitionRuleType)
    discounts = List(DiscountType,
                     is_active=Boolean(),
                     start_date=Date(),
                     end_date=Date())
    # multiCourseDiscounts = List(MultiCourseDiscountType)
    # dateRangeDiscounts = List(DateRangeDiscountType)
    # paymentMethodDiscounts = List(PaymentMethodDiscountType)

    priceQuote = Field(
        PriceQuoteType,
        method=String(required=True),
        disabled_discounts=List(ID),
        price_adjustment=Float(),
        classes=List(ClassQuote),
        tutoring=List(TutoringQuote),
        parent=ID(name="parent", required=True),
    )

    def resolve_priceQuote(self, info, **kwargs):
        quote = price_quote_total(kwargs)

        return PriceQuoteType(
            subTotal=quote["sub_total"],
            priceAdjustment=quote["price_adjustment"],
            accountBalance=quote["account_balance"],
            total=quote["total"],
            discounts=quote["discounts"],
            parent=kwargs["parent"],
        )

    def resolve_tuitionRule(self, info, **kwargs):
        return TuitionRule.objects.get(id=kwargs.get("tuitionRule_id"))

    def resolve_tuitionRules(self, info, **kwargs):
        return TuitionRule.objects.all()

    def resolve_discount(self, info, **kwargs):
        return Discount.objects.get(id=kwargs.get("discount_id"))

    def resolve_discounts(self, info, **kwargs):
        startDate = kwargs.get("start_date")
        endDate = kwargs.get("end_date")
        isActive = kwargs.get("is_active")
        discounts = Discount.objects.all()

        # check if active status is a boolean. None is treated as all
        if isActive is not None:
            discounts = discounts.filter(active=isActive)
        if startDate and endDate:
            discounts = discounts.filter(start_date__gte=startDate,
                                         end_date__lte=endDate)
        return discounts
Ejemplo n.º 17
0
 class Input:
     id = graphene.ID(required=True)
     mrid = graphene.String()
     collected_at = Date()
     sample = PatientSampleInput(required=True)
     manually_approved = graphene.Boolean()
Ejemplo n.º 18
0
class WorkingDay(graphene.ObjectType):
    date = Date()
Ejemplo n.º 19
0
class AbsenceWorkingDaysType(ObjectType):
    end = Date()
    working_days = Int()
Ejemplo n.º 20
0
def convert_date_to_string(field, registry=None):
    return Date(description=field.help_text, required=not field.null)
Ejemplo n.º 21
0
class ReportHours(graphene.ObjectType):
    report_date = Date()
    sum = graphene.Float()
    projects = graphene.String()
    day_off = graphene.Boolean()
Ejemplo n.º 22
0
 class Input:
     lastname = graphene.String(required=True)
     firstname = graphene.String(required=True)
     birthday = Date(required=True)
     mrids = graphene.List(graphene.String, required=True)
Ejemplo n.º 23
0
def convert_column_to_datetime(type, column, registry=None):
    return Date(description=get_column_doc(column),
                required=not (is_column_nullable(column)))
Ejemplo n.º 24
0
 class Input:
     id = IntID(required=True)
     project_id = IntID()
     responsible_id = IntID()
     date = Date()
Ejemplo n.º 25
0
 class Input:
     ptnum = graphene.ID(required=True)
     mrid = graphene.String()
     collected_at = Date(required=True)
     sample = PatientSampleInput(required=True)
Ejemplo n.º 26
0
 class Input:
     projects = graphene.List(IntID, required=True)
     state = IntID(required=True)
     date_filter = Date(required=True)