示例#1
0
文件: schema.py 项目: messa/ow2
class Alert(ObjectType):
    class Meta:
        interfaces = (Node, )

    @classmethod
    def get_node(cls, info, id):
        raise Exception('NIY')

    alert_id = String()
    stream_id = String()
    stream = Field(Stream)
    alert_type = String()
    item_path = List(String)
    first_snapshot_id = String()
    first_snapshot_date = DateTime()
    last_snapshot_id = String()
    last_snapshot_date = DateTime()
    first_item_value_json = JSONString(name='firstItemValueJSON')
    last_item_value_json = JSONString(name='lastItemValueJSON')
    first_item_unit = String()
    last_item_unit = String()

    def resolve_alert_id(alert, info):
        return alert.id

    async def resolve_stream(alert, info):
        return get_model(info).streams.get_by_id(alert.stream_id)

    def resolve_first_item_value_json(alert, info):
        return alert.first_item_value

    def resolve_last_item_value_json(alert, info):
        return alert.last_item_value
示例#2
0
class Query(ObjectType):
    data_sources = JSONString()
    scan_table = JSONString(tableName=String())

    @staticmethod
    def resolve_data_sources(parent, info):
        return json.dumps(scan('data_sources'))

    @staticmethod
    def resolve_scan_table(parent, info, tableName):
        return json.dumps(scan(tableName), default=json_serialize)
示例#3
0
class Query(ObjectType):
    dataset_item = DatasetItem()
    all_dataset_items = JSONString()

    @staticmethod
    def resolve_all_dataset_items(parent, info):
        return json.dumps(scan_table('census_datasets'), default=json_serialize)
def convert_postgres_field_to_string(
    field, registry=None, input_flag=None, nested_field=False
):
    return JSONString(
        description=field.help_text or field.verbose_name,
        required=is_required(field) and input_flag == "create",
    )
示例#5
0
class CheckResult(graphene.ObjectType):
    kind_key = graphene.String()
    is_found = graphene.Boolean()
    status = graphene.Field(CheckResultStatusEnum)
    severity = graphene.Field(IssueSeverityEnum)
    effort = graphene.Field(IssueEffortEnum)
    details = JSONString()
    title = graphene.String()
    description = graphene.String()

    @property
    def kind(self):
        return check_discovery.KINDS[self.kind_key]

    def resolve_severity(self, info):
        return self.kind.severity

    def resolve_effort(self, info):
        return self.kind.effort

    def resolve_title(self, info):
        return self.kind.title

    def resolve_description(self, info):
        return self.kind.format_description(self.details)
示例#6
0
class Issue(graphene.ObjectType):
    repository = graphene.Field(lambda: Repository)
    kind_key = graphene.String()
    status = graphene.String()
    details = JSONString()
    remote_issue_id = graphene.Int()
    comment = graphene.String()
    last_check = graphene.String()
    deleted = graphene.Boolean()

    class Meta:
        interfaces = (relay.Node,)

    @classmethod
    def from_db(cls, issue):
        return cls(
            id=issue.id,
            repository=issue.repository,
            kind_key=issue.kind_key,
            status=issue.status,
            details=issue.details,
            remote_issue_id=issue.remote_issue_id,
            comment=issue.comment,
            last_check=issue.last_check,
            deleted=issue.deleted,
        )

    @classmethod
    def get_node(cls, info, issue_id):
        try:
            issue = auditing_models.Issue.objects.get(id=issue_id)
            return cls.from_db(issue)
        except ObjectDoesNotExist:
            return None
示例#7
0
class User(graphene.ObjectType):
    openid_uid = graphene.String()
    first_name = graphene.String()
    last_name = graphene.String()
    has_colliding_name = graphene.Boolean()
    email = graphene.String()
    is_author = graphene.Boolean()
    extra = JSONString()

    class Meta:
        interfaces = (relay.Node, )

    @classmethod
    def from_db(cls, user):
        return cls(
            id=user.id,
            openid_uid=user.openid_uid,
            first_name=user.first_name,
            last_name=user.last_name,
            has_colliding_name=user.has_colliding_name,
            email=user.email,
            is_author=user.is_author,
            extra=user.extra,
        )

    @classmethod
    def get_node(cls, info, id):
        if not info.context.user.is_authenticated:
            return None
        if int(id) != info.context.user.id:
            return None
        return cls.from_db(info.context.user)
示例#8
0
def convert_posgres_field_to_string(field,
                                    registry=None,
                                    required=None,
                                    field_many_to_many_extras=None,
                                    field_foreign_key_extras=None):
    return JSONString(description=field.help_text,
                      required=is_required(field, required))
示例#9
0
class Query(ObjectType):
    acs1_variable = JSONString(tableName=String(required=True),
                               variableName=String(required=True),
                               year=Int(required=True))

    @staticmethod
    def resolve_acs1_variable(parent, info, tableName, variableName, year):
        item = get_item(tableName, variableName, year)
        return json.dumps(item, default=json_serialize) if (item) else None
示例#10
0
class InvitationNode(InvitationMixin, DjangoObjectType):
    extra_data = JSONString()
    inv_status = graphene.String()
    inv_type = graphene.String()

    class Meta:
        model = Invitation
        interfaces = (CustomNode, )
        exclude_fields = ['status', 'type']
示例#11
0
class Author(graphene.ObjectType):
    first_name = graphene.String()
    last_name = graphene.String()
    has_colliding_name = graphene.Boolean()
    total_reports = graphene.Int()
    extra = JSONString()
    reports = relay.ConnectionField(ReportConnection)

    class Meta:
        interfaces = (relay.Node, )

    @classmethod
    def from_db(cls, user):
        return cls(
            id=user.id,
            first_name=user.first_name,
            last_name=user.last_name,
            has_colliding_name=user.has_colliding_name,
            extra=user.extra,
            total_reports=user.total_reports,
        )

    @classmethod
    def get_node(cls, info, id):
        try:
            author = models.User.objects.annotate(
                total_reports=Count("report", filter=Q(
                    report__is_draft=False))).get(id=id, is_author=True)
            return cls.from_db(author)
        except models.User.DoesNotExist:
            return None

    def resolve_reports(self, info, **kwargs):
        paginator = Paginator(**kwargs)
        response = search.reports_by_author(self.id, paginator)
        total = response.hits.total
        page_info = paginator.get_page_info(total)

        edges = []
        for i, report in enumerate(response):
            cursor = paginator.get_edge_cursor(i + 1)
            node = Report.from_es(report, author=self)
            edges.append(ReportConnection.Edge(node=node, cursor=cursor))

        return ReportConnection(page_info=page_info,
                                edges=edges,
                                total_count=total)

    def resolve_total_reports(self, info, **kwargs):
        return models.Report.objects.filter(author_id=self.id,
                                            is_draft=False).count()
示例#12
0
class SiteStructure(graphene.ObjectType):
    value = GenericScalar()
    structure_json = JSONString()

    # json isn't a great way to do this, we should
    # figure out how to make it queryable
    def resolve_structure_json(self, resolve_info, *args, **kwargs):
        # our structure here can be id: page dict
        site_structure = []
        topic_collections = TopicCollectionPage.objects.all()
        for topic_collection in topic_collections:
            if not topic_collection.theme:
                continue

            topic_collection_global_id = graphene.Node.to_global_id('TopicCollectionNode', topic_collection.id)
            site_structure.append({'url': f'/{topic_collection.theme.slug}/{topic_collection.slug}/', 'type': 'topic collection', 'id': topic_collection_global_id})

        topics = TopicPage.objects.all()
        for topic in topics:
            topic_global_id = graphene.Node.to_global_id('TopicNode', topic.id)
            topic_tcs = topic.topiccollections.all()
            for tc in topic_tcs:
                if not tc.topiccollection.theme:
                    continue

                topic_tc_global_id = graphene.Node.to_global_id('TopicCollectionNode', tc.topiccollection.id)
                site_structure.append({'url': f'/{tc.topiccollection.theme.slug}/{tc.topiccollection.slug}/{topic.slug}/', 'type': 'topic', 'id': topic_global_id, 'parent_topic_collection': topic_tc_global_id})

        departments = DepartmentPage.objects.all()
        for department in departments:
            department_global_id = graphene.Node.to_global_id('DepartmentNode', department.id)
            site_structure.append({'url': f'/{department.slug}/', 'type': 'department', 'id': department_global_id})

        site_structure.extend(get_structure_for_content_type('service page'))
        site_structure.extend(get_structure_for_content_type('information page'))
        site_structure.extend(get_structure_for_content_type('official document page'))
        site_structure.extend(get_structure_for_content_type('guide page'))
        site_structure.extend(get_structure_for_content_type('form container'))

        return site_structure
示例#13
0
def convert_pg_and_json_field_to_string(field, registry=None):
    return JSONString(description=field.help_text, required=not field.null)
示例#14
0
def convert_dict_to_jsonstring(field, registry=None):
    return JSONString(description=field.db_field, required=not field.null)
示例#15
0
def convert_json_field_to_string(field, registry=None):
    return JSONString(description=field.help_text)
def convert_field_to_jsonstring(field, registry=None):
    """ Converts Mongoengine fields to Graphene JSONString type """
    return JSONString(**get_data_from_field(field))
def convert_field_to_jsonstring(field, registry=None):
    """ Converts Mongoengine fields to Graphene JSONString type.
    Generic fields can have any document type, so the best that can be done is
    to convert them to JSONString
    """
    return JSONString(**get_data_from_field(field))
示例#18
0
def convert_field_to_jsonstring(field, registry=None):
    return JSONString(description=get_field_description(field, registry),
                      required=field.required)
示例#19
0
def convert_pg_and_json_field_to_string(field, registry=None):
    return JSONString(description=get_django_field_description(field),
                      required=not field.null)
示例#20
0
class Report(graphene.ObjectType):
    author = graphene.Field(lambda: Author)
    date = graphene.String()
    published = graphene.String()
    title = graphene.String()
    body = graphene.String()
    received_benefit = graphene.String()
    provided_benefit = graphene.String()
    our_participants = graphene.String()
    other_participants = graphene.String()
    is_draft = graphene.Boolean()
    extra = JSONString()

    class Meta:
        interfaces = (relay.Node, )

    @classmethod
    def from_es(cls, report, author=None):
        return cls(
            id=report.meta.id,
            author=author,
            date=report.date,
            published=report.published,
            title=get_higlighted(report, 'title'),
            body=get_higlighted(report, 'body'),
            received_benefit=get_higlighted(report, 'received_benefit'),
            provided_benefit=get_higlighted(report, 'provided_benefit'),
            our_participants=get_higlighted(report, 'our_participants'),
            other_participants=get_higlighted(report, 'other_participants'),
            is_draft=report.is_draft,
            extra=report.extra,
        )

    @classmethod
    def from_db(cls, report):
        return cls(
            id=report.id,
            author=report.author,
            date=report.date,
            published=report.published,
            title=report.title,
            body=report.body,
            received_benefit=report.received_benefit,
            provided_benefit=report.provided_benefit,
            our_participants=report.our_participants,
            other_participants=report.other_participants,
            is_draft=report.is_draft,
            extra=report.extra,
        )

    @classmethod
    def get_node(cls, info, id):
        try:
            report = ReportDoc.get(id)
        except NotFoundError:
            return None

        if report.is_draft:
            if not info.context.user.is_authenticated:
                return None
            if report.author_id != info.context.user.id:
                return None

        author_type = cls._meta.fields['author'].type
        author = author_type.get_node(info, report.author_id)
        return cls.from_es(report, author)
示例#21
0
class ProjectNode(DjangoObjectType):
    uuid = graphene.String()
    first_day = graphene.String()
    last_day = graphene.String()
    timezone = graphene.String()
    type_project = graphene.String()
    lapse_type = graphene.String()
    project_incidences = JSONString()
    resources = DjangoFilterConnectionField(
        ResourceNode,
        filterset_class=ResourceFilterSet)
    count_resources = graphene.Int()
    my_teams = DjangoFilterConnectionField(TeamNode, filterset_class=TeamFilter)
    teams = DjangoFilterConnectionField(TeamNode, filterset_class=TeamFilter)
    next_url = JSONString()
    admin_url = graphene.String()
    allowed_access = graphene.Boolean()
    settings = JSONString()
    has_swarm_session = graphene.Boolean()

    class Meta:
        model = Project
        interfaces = (CustomNode, )
        filter_fields = ['name', 'status']

    def resolve_timezone(self, info):
        return self.timezone.zone if self.timezone else None

    def resolve_my_teams(self, info, **kwargs):
        queryset = self.teams \
            .filter_by_project(self) \
            .filter_by_user(self, info.context.user)

        filter = TeamFilter(queryset=queryset, **kwargs)
        return filter.queryset

    def resolve_teams(self, info, **kwargs):
        queryset = self.teams.filter_by_project(self)
        filter = TeamFilter(queryset=queryset, **kwargs)
        return filter.queryset

    def resolve_count_resources(self, info):
        return self.resources.count()

    def resolve_next_url(self, info):
        url, zone = next_project_url(self, info.context.user)
        return {'url': url, 'zone': zone}

    def resolve_admin_url(self, info):
        url = ''
        if has_project_perms(
            self,
            settings.PROJECT_PERMS_PROJECT_MANAGER,
            info.context.user,
        ):
            url = reverse('project:project:dashboard', kwargs={'project_id': self.pk})

        return url

    def resolve_project_incidences(self, info):
        project_incidences = {}
        type_incidence = None
        number_incidences = 0

        if has_project_perms(
            self,
            settings.PROJECT_PERMS_PROJECT_MANAGER,
            info.context.user,
        ):
            errors_incidences = self.validations \
                .filter_by_validation_type_error() \
                .filter_by_status_pending().count()
            warnings_incidences = self.validations \
                .filter_by_validation_type_warning() \
                .filter_by_status_pending().count()

            if errors_incidences:
                type_incidence = self.validations \
                    .filter_by_validation_type_error() \
                    .first().validation_type
                number_incidences = errors_incidences

            elif warnings_incidences:
                type_incidence = self.validations \
                    .filter_by_validation_type_warning() \
                    .first().validation_type
                number_incidences = warnings_incidences

            project_incidences = {'type': type_incidence, 'number': number_incidences}

        return project_incidences

    def resolve_allowed_access(self, info):
        return self.real_type.allowed_access

    def resolve_type_project(self, info):
        return self.type_verbose_name

    def resolve_settings(self, info):
        return ProjectSettingsSerializer(self.settings).data

    def resolve_has_swarm_session(self, info):
        return self.qa_sessions.exists()
示例#22
0
def convert_json_to_string(type, attribute, registry=None):
    return JSONString(description=attribute.attr_name,
                      required=not attribute.null)
示例#23
0
def convert_json_type_to_string(type, column, registry=None):
    return JSONString(description=get_column_doc(column),
                      required=not (is_column_nullable(column)))
示例#24
0
 class Arguments:
     name = graphene.String()
     hobbies = JSONString()
     results = JSONString()
     department_id = graphene.Int()
示例#25
0
文件: schema.py 项目: messa/ow2
class SnapshotItem(ObjectType):
    class Meta:
        interfaces = (Node, )

    path = List(String)
    path_str = String(name='pathStr')
    key = String()
    value_json = JSONString(name='valueJSON')
    check_json = JSONString(name='checkJSON')
    check_state = String()
    watchdog_json = JSONString(name='watchdogJSON')
    watchdog_expired = Boolean()
    is_counter = Boolean()
    unit = String()
    stream_id = String()
    stream = Field(lambda: Stream)
    snapshot_id = String()
    snapshot_date = DateTime()
    snapshot = Field(lambda: StreamSnapshot)

    def resolve_id(item, info):
        return f'{item.snapshot_id}:{item.path_str}'

    def resolve_path(item, info):
        return item.path

    def resolve_path_str(item, info):
        return ' > '.join(item['path'])

    def resolve_key(item, info):
        return item.key

    def resolve_value_json(item, info):
        return item.value

    def resolve_is_counter(item, info):
        return item.is_counter

    def resolve_check_json(item, info):
        return item.raw_check

    def resolve_watchdog_json(item, info):
        return item.raw_watchdog

    def resolve_stream_id(item, info):
        return item.stream_id

    async def resolve_stream(item, info):
        model = get_model(info)
        return await model.streams.get_by_id(item.stream_id)

    def resolve_snapshot_id(item, info):
        assert item.snapshot_id
        return item.snapshot_id

    def resolve_snapshot_date(item, info):
        assert item.snapshot_date
        return item.snapshot_date

    async def resolve_snapshot(item, info):
        model = get_model(info)
        return await model.stream_snapshots.get_by_id(item.snapshot_id)
示例#26
0
class Report(graphene.ObjectType):
    author = graphene.Field(lambda: Author)
    date = graphene.String()
    published = graphene.String()
    title = graphene.String()
    body = graphene.String()
    received_benefit = graphene.String()
    provided_benefit = graphene.String()
    our_participants = graphene.String()
    other_participants = graphene.String()
    is_draft = graphene.Boolean()
    extra = JSONString()
    edited = graphene.String()
    has_revisions = graphene.Boolean()
    revisions = graphene.List(lambda: Report)

    class Meta:
        interfaces = (relay.Node, )

    @classmethod
    def from_es(cls, report, author=None):
        return cls(
            id=int(report.meta.id),
            author=author,
            date=report.date,
            published=report.published,
            title=get_higlighted(report, "title"),
            body=get_higlighted(report, "body"),
            received_benefit=get_higlighted(report, "received_benefit"),
            provided_benefit=get_higlighted(report, "provided_benefit"),
            our_participants=get_higlighted(report, "our_participants"),
            other_participants=get_higlighted(report, "other_participants"),
            is_draft=report.is_draft,
            extra=report.extra,
            edited=report.edited,
        )

    @classmethod
    def from_db(cls, report):
        return cls(
            id=report.id,
            author=report.author,
            date=report.date,
            published=report.published,
            title=report.title,
            body=report.body,
            received_benefit=report.received_benefit,
            provided_benefit=report.provided_benefit,
            our_participants=report.our_participants,
            other_participants=report.other_participants,
            is_draft=report.is_draft,
            extra=report.extra,
            edited=report.edited,
        )

    @classmethod
    def get_node(cls, info, id):
        try:
            report = ReportDoc.get(id)
        except NotFoundError:
            return None

        if report.is_draft:
            if not info.context.user.is_authenticated:
                return None
            if report.author_id != info.context.user.id:
                return None

        author_type = cls._meta.fields["author"].type
        author = author_type.get_node(info, report.author_id)
        return cls.from_es(report, author)

    def resolve_has_revisions(self, info, **kwargs):
        return models.Report.objects.filter(
            superseded_by_id=self.id).count() > 0

    def resolve_revisions(self, info, **kwargs):
        revisions = models.Report.objects.filter(
            superseded_by_id=self.id).order_by("-edited")
        return [Report.from_db(r) for r in revisions]
示例#27
0
def convert_json_type_to_string(type, column, registry=None):
    return JSONString(description=column.doc, required=not (column.nullable))
示例#28
0
def convert_posgres_field_to_string(field, registry=None):
    return JSONString(description=field.help_text, required=not field.blank)