Skip to content

Commit

Permalink
bug fix; minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
indepndnt committed Nov 6, 2024
1 parent 0cdd260 commit 12a30fc
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- 'main'
tags:
- '*'
- '[0-9]+.[0-9]+.[0-9]+'

permissions:
contents: read
Expand All @@ -16,10 +16,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up latest Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "*"

Expand All @@ -31,7 +31,7 @@ jobs:
run: python -m build

- name: Upload sdist as workflow artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: dist/

Expand All @@ -42,7 +42,7 @@ jobs:

steps:
- name: Download workflow artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: artifact
path: dist
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

- Drop deprecated model methods

### 0.0.4 November 6, 2024

- Fix build bug introduced in 0.0.3
- Update Contact find methods
- Add `get` and `save` methods to Query

### 0.0.3 May 14, 2024

- Add CiviCRM v4 API usage and make it the default
Expand Down
12 changes: 8 additions & 4 deletions civipy/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ class CiviContact(CiviNotable):

@classmethod
def find_by_email(cls, email_address: str, select: list[str] | None = None):
email_obj = CiviEmail.find(select=["contact_id"], email=email_address)
return cls.find(select=select, id=email_obj.civi["contact_id"])
if select is None:
select = []
email_obj = CiviEmail.objects.filter(email=email_address).values("contact_id")[0]
return cls.objects.filter(id=email_obj.civi["contact_id"]).values(*select)[0]

@classmethod
def find_all_by_email(cls, email_address: str, select: list[str] | None = None):
if select is None:
select = []
return [
cls.find(select=select, id=email_obj.civi["contact_id"])
for email_obj in CiviEmail.find_all(select=["contact_id"], email=email_address)
cls.objects.filter(id=email_obj.civi["contact_id"]).values(*select)[0]
for email_obj in CiviEmail.objects.filter(email=email_address).values("contact_id").all()
]

@classmethod
Expand Down
21 changes: 15 additions & 6 deletions civipy/financial.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ def cancel(cls, **kwargs):
@classmethod
def find_by_transaction_id(cls, trxn_id: str, entity_table: str) -> "CiviEntityFinancialTrxn | None":
"""Find a Contribution Payment by payment transaction ID"""
kwargs = {
"select": ["*", "financial_trxn_id.*"],
"entity_table": entity_table,
"financial_trxn_id.trxn_id": trxn_id,
}
found = cls.find_all(**kwargs)
found = cls.objects.filter(
entity_table=entity_table, financial_trxn_id__trxn_id=trxn_id
).select(["*", "financial_trxn_id.*"]).all()
return next(filter(lambda c: bool(c.civi.get("entity_id")), found), None)


class CiviFinancialTrxn(CiviCRMBase):
...


class CiviFinancialItem(CiviCRMBase):
...


class CiviLineItem(CiviCRMBase):
...
12 changes: 12 additions & 0 deletions civipy/interface/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def all(self):
self._fetch_all()
return self._result_cache

def get(self, **kwargs):
return self.filter(**kwargs)[0]

def filter(self, **kwargs):
query = self._chain()
if query._filter:
Expand Down Expand Up @@ -163,6 +166,15 @@ def create(self, **kwargs):
response = self._interface().execute("create", self._entity, query)
return response

def save(self, records: list[dict[str, str]], defaults: dict[str, str] | None = None, match: list[str] | None = None):
query = {"records": records}
if defaults is not None:
query["defaults"] = defaults
if match is not None:
query["match"] = match
response = self._interface().execute("save", self._entity, query)
return response

def delete(self):
query = self._compose()
response = self._interface().execute("delete", self._entity, query)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ optional-dependencies.dev = [
]

[tool.setuptools]
packages = ["civipy"]
packages = {find = {include = ["civipy*"]}}
dynamic.version = {file = "VERSION"}

[tool.cibuildwheel]
Expand Down

0 comments on commit 12a30fc

Please sign in to comment.