Skip to content

Commit

Permalink
Merge pull request #691 from euphorie/company-model-customizable
Browse files Browse the repository at this point in the history
Allow the company model to be customized by other packages
  • Loading branch information
ale-rt authored Jan 25, 2024
2 parents 37521ed + 66b9cef commit 3e0da7f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
5 changes: 4 additions & 1 deletion docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ Changelog
15.2.1 (unreleased)
-------------------

- Update nl translations.
- Allow the company model to be customized by other packages.
[ale-rt]

- Update nl translations.
[ale-rt, angeldasangel]


15.2.0 (2024-01-08)
-------------------
Expand Down
36 changes: 29 additions & 7 deletions src/euphorie/client/browser/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from z3c.form import form
from z3c.form.form import applyChanges
from zope import schema
from zope.deprecation import deprecate
from zope.interface import directlyProvides
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary
Expand Down Expand Up @@ -188,19 +189,40 @@ class Company(AutoExtensibleForm, form.Form):
schema = CompanySchema
company = None
template = ViewPageTemplateFile("templates/report_company.pt")
company_class = model.Company

@property
def session(self):
return self.context.session

@property
def default_company_values(self):
"""The values we use to create a new company."""
return {"session": self.session}

@property
@memoize
def company(self):
"""Get or create the company object for this session."""
company = (
model.Session.query(self.company_class)
.filter(self.company_class.session == self.session)
.first()
)
if not company:
company = self.company_class(**self.default_company_values)

# This is used to make the company object the context of the form
directlyProvides(company, self.schema)
return company

@deprecate(
"Deprecated in version 15.2.1.dev0. "
"This was a trick to add the company attribute to the instance. "
"Now company is a property."
)
def _assertCompany(self):
if self.company is not None:
return
session = self.session
if session.company is None:
session.company = model.Company()
directlyProvides(session.company, CompanySchema)
self.company = session.company
return

def countries(self):
names = [
Expand Down

0 comments on commit 3e0da7f

Please sign in to comment.