class PassageSiblingsNode(ObjectType): # @@@ dry for resolving scalars all_siblings = generic.GenericScalar( name="all", description="Inclusive list of siblings for a passage") selected = generic.GenericScalar( description="Only the selected sibling objects for a given passage") previous = generic.GenericScalar( description="Siblings for the previous passage") next_siblings = generic.GenericScalar( name="next", description="Siblings for the next passage") class Meta: description = "Provides lists of sibling objects for a given passage" def resolve_all_siblings(obj, info, **kwargs): return obj.all def resolve_selected(obj, info, **kwargs): return obj.selected def resolve_previous(obj, info, **kwargs): return obj.previous def resolve_next_siblings(obj, info, **kwargs): return obj.next
class AbstractProfile(graphene.AbstractType): """V2 Abstract Schema Profile object for Graphene. Generic Scalars are used when the attribute value is not know before hand. The result is a dictionary of attributes with values. eg usernames: {'attribute1: value1, 'attribute2': value2} """ user_id = graphene.String() login_method = graphene.String() username = graphene.String() active = graphene.Boolean() last_modified = graphene.DateTime() created = graphene.DateTime() usernames = generic.GenericScalar() pronouns = graphene.String() first_name = graphene.String() last_name = graphene.String() alternative_name = graphene.String() primary_email = graphene.String() identities = graphene.Field(Identities) ssh_public_keys = generic.GenericScalar() pgp_public_keys = generic.GenericScalar() access_information = graphene.Field(AccessInformation) fun_title = graphene.String() description = graphene.String() location = graphene.String() timezone = graphene.String() languages = graphene.List(graphene.String) tags = graphene.List(graphene.String) picture = graphene.String() uris = generic.GenericScalar() phone_numbers = generic.GenericScalar() staff_information = graphene.Field(StaffInformation)
class ClientNode(DjangoObjectType): class Meta: model = ClientModel interfaces = (relay.Node, ) filter_fields = {"uid": ["exact"], "company": ["exact", "icontains"]} uid = graphene.UUID(source="pk") metadata = generic.GenericScalar() attachments = DjangoFilterConnectionField(AttachmentNode) image_url = graphene.String() invoice_counts = generic.GenericScalar() def resolve_image_url(self, info): if self.image: return self.image.url return "" def resolve_invoice_counts(self, info): return { "open": self.invoices.filter(state=1).count(), "paid_partial": self.invoices.filter(state=2).count(), "paid_full": self.invoices.filter(state=3).count(), "drafts": self.invoices.filter(state=0).count(), "closed": self.invoices.filter(state=4).count(), "void": self.invoices.filter(state=-1).count(), }
class AccessInformation(graphene.ObjectType): """V2 Schema AccessInformation object for Graphene.""" ldap = generic.GenericScalar() mozilliansorg = generic.GenericScalar() access_provider = generic.GenericScalar() hris = generic.GenericScalar() class Meta: default_resolver = dino_park_resolver
class PassageMetadataNode(ObjectType): human_reference = String() ancestors = generic.GenericScalar() overview = Field(PassageOverviewNode) siblings = Field(PassageSiblingsNode) children = generic.GenericScalar() next_passage = String(description="Next passage reference") previous_passage = String(description="Previous passage reference") healed_passage = String(description="Healed passage") def resolve_metadata(self, info, *args, **kwargs): # @@@ return {} def resolve_previous_passage(self, info, *args, **kwargs): passage = info.context.passage if passage.previous_objects: return self.generate_passage_urn(passage.version, passage.previous_objects) def resolve_next_passage(self, info, *args, **kwargs): passage = info.context.passage if passage.next_objects: return self.generate_passage_urn(passage.version, passage.next_objects) def resolve_overview(self, info, *args, **kwargs): passage = info.context.passage # TODO: Review overview / ancestors / siblings implementation passage = info.context.passage return PassageOverviewMetadata(passage) def resolve_ancestors(self, info, *args, **kwargs): passage = info.context.passage return self.get_ancestor_metadata(passage.version, passage.start) def resolve_siblings(self, info, *args, **kwargs): passage = info.context.passage return PassageSiblingMetadata(passage) def resolve_children(self, info, *args, **kwargs): passage = info.context.passage return self.get_children_metadata(passage.start) def resolve_human_reference(self, info, *args, **kwargs): passage = info.context.passage return passage.human_readable_reference def resolve_healed_passage(self, info, *args, **kwargs): return getattr(info.context, "healed_passage_reference", None)
class RenderedFormNode(DjangoObjectType): class Meta: model = RenderedFormModel interfaces = (relay.Node, ) filter_fields = {"uid": ["exact"]} metadata = generic.GenericScalar() rendering_data = generic.GenericScalar() url = graphene.String() def resolve_url(self, info): if not self.rendered_file: return "" return self.rendered_file.url
class FormTemplateNode(DjangoObjectType): class Meta: model = FormTemplateModel interfaces = (relay.Node, ) filter_fields = {"uid": ["exact"], "name": ["exact", "icontains"]} fields = generic.GenericScalar() metadata = generic.GenericScalar() url = graphene.String() annotations = generic.GenericScalar() def resolve_url(self, info): if not self.template_file: return "" return self.template_file.url
class TreebankNode(DjangoObjectType): metadata = generic.GenericScalar() class Meta: model = Treebank interfaces = (relay.Node, ) filter_fields = ["name", "urn"]
class Workflow(DjangoObjectType): start_tasks = graphene.List(Task, required=True) tasks = graphene.List(Task, required=True, description="List of tasks referenced in workflow") meta = generic.GenericScalar() def resolve_tasks(self, info, **args): flow_jexl = jexl.FlowJexl() next_jexls = self.flows.values_list("next", flat=True) jexl_tasks = itertools.chain( *[flow_jexl.extract_tasks(next_jexl) for next_jexl in next_jexls]) return models.Task.objects.filter( Q(pk__in=self.start_tasks.all()) | Q(pk__in=jexl_tasks)) def resolve_start_tasks(self, info, **args): return self.start_tasks.all() flows = DjangoFilterConnectionField(Flow, filterset_class=filters.FlowFilterSet) class Meta: model = models.Workflow exclude = ("cases", "task_flows") interfaces = (relay.Node, ) connection_class = CountableConnectionBase
class NamedEntityNode(DjangoObjectType): data = generic.GenericScalar() class Meta: model = NamedEntity interfaces = (relay.Node, ) filterset_class = NamedEntityFilterSet
class AudioAnnotationNode(DjangoObjectType): data = generic.GenericScalar() class Meta: model = AudioAnnotation interfaces = (relay.Node, ) filter_fields = ["urn"]
class Answer(Node, graphene.Interface): id = graphene.ID() created_at = graphene.DateTime(required=True) created_by_user = graphene.String() created_by_group = graphene.String() modified_at = graphene.DateTime(required=True) question = graphene.Field(Question, required=True) meta = generic.GenericScalar(required=True) @classmethod def resolve_type(cls, instance, info): ANSWER_TYPE = { list: ListAnswer, str: StringAnswer, float: FloatAnswer, int: IntegerAnswer, date: DateAnswer, } if instance.value is None: ANSWER_QUESTION_TYPE = { models.Question.TYPE_FORM: FormAnswer, models.Question.TYPE_TABLE: TableAnswer, } return ANSWER_QUESTION_TYPE[instance.question.type] return ANSWER_TYPE[type(instance.value)]
class Task(Node, graphene.Interface): id = graphene.ID(required=True) created_at = graphene.DateTime(required=True) modified_at = graphene.DateTime(required=True) created_by_user = graphene.String() created_by_group = graphene.String() slug = graphene.String(required=True) name = graphene.String(required=True) description = graphene.String() is_archived = graphene.Boolean(required=True) address_groups = GroupJexl() control_groups = GroupJexl() meta = generic.GenericScalar(required=True) is_multiple_instance = graphene.Boolean(required=True) continue_async = graphene.Boolean() @classmethod def resolve_type(cls, instance, info): TASK_TYPE = { models.Task.TYPE_SIMPLE: SimpleTask, models.Task.TYPE_COMPLETE_WORKFLOW_FORM: CompleteWorkflowFormTask, models.Task.TYPE_COMPLETE_TASK_FORM: CompleteTaskFormTask, } return TASK_TYPE[instance.type]
class Question(Node, graphene.Interface): id = graphene.ID(required=True) created_at = graphene.DateTime(required=True) modified_at = graphene.DateTime(required=True) created_by_user = graphene.String() created_by_group = graphene.String() slug = graphene.String(required=True) label = graphene.String(required=True) info_text = graphene.String() is_required = QuestionJexl( required=True, description= "Required expression is only evaluated when question is not hidden.", ) is_hidden = QuestionJexl(required=True) is_archived = graphene.Boolean(required=True) meta = generic.GenericScalar(required=True) forms = DjangoFilterConnectionField("caluma.form.schema.Form", filterset_class=filters.FormFilterSet) source = graphene.Field("caluma.form.schema.Question") @classmethod def get_queryset(cls, queryset, info): queryset = super().get_queryset(queryset, info) return queryset.select_related( "sub_form", "row_form").order_by("-formquestion__sort") @classmethod def resolve_type(cls, instance, info): return resolve_question(instance)
class HistoricalDocument(FormDjangoObjectType): historical_answers = ConnectionField( HistoricalAnswerConnection, as_of=graphene.types.datetime.DateTime(required=True), ) history_date = graphene.types.datetime.DateTime(required=True) history_user_id = graphene.String() history_type = graphene.String() meta = generic.GenericScalar() document_id = graphene.UUID() def resolve_document_id(self, info, *args): return self.id def resolve_historical_answers(self, info, as_of, *args): answers = [ a for a in historical_qs_as_of( models.Answer.history.filter(document_id=self.id), as_of, "id") ] return answers class Meta: model = models.Document.history.model exclude = ("family", "history_id", "history_change_reason") interfaces = (graphene.Node, ) connection_class = CountableConnectionBase
class SnapshotNode(DjangoObjectType): class Meta: model = Snapshot fields = [ 'is_showcase', 'title', 'topic', 'data', 'municipality', 'predecessor' ] filter_fields = [ 'municipality__id', 'municipality__canton', 'is_showcase' ] interfaces = [graphene.relay.Node] data = generic.GenericScalar(source='data') pk = graphene.String(source='id') thumbnail = graphene.String() screenshot = graphene.String() screenshot_facebook = graphene.String() screenshot_twitter = graphene.String() @classmethod def get_queryset(cls, queryset, info): return queryset.filter(Q_SNAPSHOT_WITH_NOT_LISTED) def resolve_screenshot(self, info): return self.screenshot def resolve_thumbnail(self, info): return self.thumbnail def resolve_screenshot_facebook(self, info): return self.image_facebook() def resolve_screenshot_twitter(self, info): return self.image_twitter()
class ModifyMetadataMutation(graphene.Mutation): class Arguments: uid = graphene.UUID(required=True) metadata = generic.GenericScalar(required=True) mode = graphene.String() metadata = generic.GenericScalar() uid = graphene.UUID() parent_type = graphene.String() mode = graphene.String() @classmethod def mutate(cls, root, info, uid, metadata, mode="update"): for m in METADATA_MODELS: try: o = m.objects.get(pk=uid) break except m.DoesNotExist: pass else: raise Exception(f"Object with UUID {uid} not found") initial = o.metadata if mode == "update": initial.update(metadata) o.metadata = initial elif mode == "replace": o.metadata = metadata o.save() final = o.metadata return ModifyMetadataMutation(uid=uid, metadata=final, parent_type=o.__class__.__name__, mode=mode)
class ImageAnnotationNode(DjangoObjectType): text_parts = LimitedConnectionField(lambda: TextPartNode) data = generic.GenericScalar() class Meta: model = ImageAnnotation interfaces = (relay.Node, ) filterset_class = ImageAnnotationFilterSet
class JobNode(DjangoObjectType): class Meta: model = JobModel interfaces = (relay.Node, ) filter_fields = {"uid": ["exact"]} metadata = generic.GenericScalar() attachments = DjangoFilterConnectionField(AttachmentNode)
class MetricalAnnotationNode(DjangoObjectType): data = generic.GenericScalar() metrical_pattern = String() class Meta: model = MetricalAnnotation interfaces = (relay.Node, ) filter_fields = ["urn"]
class AnalyticsField(DjangoObjectType): meta = generic.GenericScalar() filters = graphene.List(String, required=False) class Meta: model = models.AnalyticsField interfaces = (relay.Node,) connection_class = CountableConnectionBase
class WorkItem(DjangoObjectType): task = graphene.Field(Task, required=True) meta = generic.GenericScalar() class Meta: model = models.WorkItem interfaces = (relay.Node, ) connection_class = CountableConnectionBase
class InvoiceNode(DjangoObjectType): class Meta: model = InvoiceModel interfaces = (relay.Node, ) filterset_class = InvoiceFilterSet uid = graphene.UUID(source="pk") metadata = generic.GenericScalar() attachments = DjangoFilterConnectionField(AttachmentNode)
class Case(DjangoObjectType): work_items = DjangoFilterConnectionField( WorkItem, filterset_class=filters.WorkItemFilterSet) meta = generic.GenericScalar() class Meta: model = models.Case interfaces = (relay.Node, ) connection_class = CountableConnectionBase
class Form(DjangoObjectType): questions = DjangoFilterSetConnectionField( QuestionConnection, filterset_class=filters.QuestionFilterSet) meta = generic.GenericScalar() class Meta: model = models.Form interfaces = (relay.Node, ) exclude_fields = ("workflows", "tasks")
class File(FormDjangoObjectType): name = graphene.String(required=True) upload_url = graphene.String() download_url = graphene.String() metadata = generic.GenericScalar() answer = graphene.Field("caluma.form.schema.FileAnswer") class Meta: model = models.File interfaces = (relay.Node, )
class Document(FormDjangoObjectType): answers = DjangoFilterSetConnectionField( AnswerConnection, filterset_class=filters.AnswerFilterSet) meta = generic.GenericScalar() class Meta: model = models.Document exclude = ("family", ) interfaces = (graphene.Node, ) connection_class = CountableConnectionBase
class PassageOverviewNode(ObjectType): all_top_level = generic.GenericScalar( name="all", description="Inclusive list of top-level text parts for a passage") selected = generic.GenericScalar( description="Only the selected top-level objects for a given passage") class Meta: description = ( "Provides lists of top-level text part objects for a given passage" ) @staticmethod def resolve_all_top_level(obj, info, **kwargs): return obj.all @staticmethod def resolve_selected(obj, info, **kwargs): return obj.selected
class SKUInput(graphene.InputObjectType): metadata = generic.GenericScalar() name = graphene.String() default_price = graphene.Float() default_quantity = graphene.Float() minimum_price = graphene.Float() minimum_quantity = graphene.Float() maximum_price = graphene.Float() maximum_quantity = graphene.Float() units = graphene.String()
class ContactInput(graphene.InputObjectType): first_name = graphene.String() last_name = graphene.String() title = graphene.String() role = graphene.String() primary_email = graphene.String() phone_number = graphene.String() mailing_address = graphene.String() billing_address = graphene.String() metadata = generic.GenericScalar()