Exemplo n.º 1
0
def handle():
    data = json.loads(request.data)
    # handle only "list" change event
    if "listAfter" in data["action"]["data"]:
        board_list_id = data["action"]["data"]["listAfter"]["id"]
        card_id = data["model"]["id"]
        associations = AssociationsRepository.find_by_card_id(card_id)
        hubspot = create_client()
        for association in associations:
            deal_id = association.deal_id
            deal = hubspot.crm.deals.basic_api.get_by_id(deal_id)
            mapping = (session.query(Mapping).filter_by(
                board_list_id=board_list_id,
                pipeline_id=deal.properties["pipeline"],
            ).first())
            session.commit()
            if mapping is not None:
                simple_public_object_input = SimplePublicObjectInput(
                    properties={"dealstage": mapping.pipeline_stage_id}, )
                hubspot.crm.deals.basic_api.update(
                    deal_id=deal_id,
                    simple_public_object_input=simple_public_object_input,
                )

    return "", HTTPStatus.OK
Exemplo n.º 2
0
def list():
    events = session.query(Event).order_by(
        Event.occurred_at.desc()).limit(50).all()
    session.commit()
    hubspot = create_client()

    inputs = [SimplePublicObjectId(id=e.object_id) for e in events]
    batch_read_input_simple_public_object_id = BatchReadInputSimplePublicObjectId(
        inputs=inputs, )
    contacts = hubspot.crm.contacts.batch_api.read(
        batch_read_input_simple_public_object_id=
        batch_read_input_simple_public_object_id, ).results
    contacts_dict = {
        int(contact.id): {
            "fullname": (contact.properties["firstname"] or "") + " " +
            (contact.properties["lastname"] or "")
        }
        for contact in contacts
    }

    return render_template(
        "events/list.html",
        events=events,
        contacts_dict=contacts_dict,
        now=datetime.datetime.now(),
    )
Exemplo n.º 3
0
    def find_one(cls):
        settings = session.query(Settings).first()
        if settings is None:
            settings = Settings()
            session.add(settings)

        return settings
Exemplo n.º 4
0
def updates():
    after = datetime.datetime.fromisoformat(request.args.get("after"))
    updates_count = session.query(Event).filter(
        Event.created_at > after).count()
    session.commit()

    return jsonify({
        "updatesCount": updates_count,
    })
Exemplo n.º 5
0
 def delete_by_id(cls, mapping_id):
     session.delete(session.query(Mapping).get(mapping_id))
Exemplo n.º 6
0
 def get(cls, mapping_id):
     return session.query(Mapping).get(mapping_id)
Exemplo n.º 7
0
 def find_by(cls, **kwargs):
     return session.query(Mapping).filter_by(**kwargs).all()
Exemplo n.º 8
0
 def is_deal_associated(cls, deal_id):
     count = session.query(Association).filter_by(deal_id=deal_id).count()
     return count > 0
Exemplo n.º 9
0
 def delete_by_deal_id(cls, deal_id):
     session.query(Association).filter_by(deal_id=deal_id).delete()
Exemplo n.º 10
0
 def find_by_card_id(cls, card_id):
     associations = session.query(Association).filter_by(
         card_id=card_id).all()
     return associations
Exemplo n.º 11
0
 def find_one_by_deal_id(cls, deal_id):
     association = session.query(Association).filter_by(
         deal_id=deal_id).first()
     return association
Exemplo n.º 12
0
 def get(cls, webhooks_id):
     return session.query(Webhook).get(webhooks_id)
Exemplo n.º 13
0
 def find_outdated(cls, url):
     print(url, flush=True)
     return session.query(Webhook).filter(Webhook.url != url).all()
Exemplo n.º 14
0
 def find_by(cls, **kwargs):
     return session.query(Webhook).filter_by(**kwargs).all()