Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Resint
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Resint
Commits
afc000e9
Verified
Commit
afc000e9
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[Docs] Add dev docs on live documents
parent
a947aa1c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!34
Add docs
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/dev/01_live_document_types.rst
+48
-0
48 additions, 0 deletions
docs/dev/01_live_document_types.rst
with
48 additions
and
0 deletions
docs/dev/01_live_document_types.rst
0 → 100644
+
48
−
0
View file @
afc000e9
Providing live document types from other apps
=============================================
AlekSIS apps can provide live document types that
are then managed by Resint. Live document types are
Django models sub-classing the ``LiveDocument`` model,
and providing fields and some methods that define how
the live document is generated.
The following stripped-down example shows how to
provide a live document type.
.. code-block:: python
from aleksis.apps.resint.models import LiveDocument
class AutomaticPlan(LiveDocument):
# Template name to render
template = "my_app/pdf_template.html"
# A field to be rendered in the edit form
number_of_days = models.PositiveIntegerField(
default=1,
)
def get_context_data(self) -> Dict[str, Any]:
"""Get context data to pass to the PDF template."""
context = {}
# Do something ehre to construct the context data
return context
This basic example generates a PDF by defining an HTML template
and overriding the ``get_context_data`` method. This method has
to return a context dictionary, which will then be passed to
the template.
If you need more control over how the PDF is generated, you
can instead override the ``update`` methodd:
.. code-block:: python
class AutomaticPlan(LiveDocument):
def update(self, triggered_manually: bool = True):
"""Re-generate PDF for this live document."""
# Do whatever is necessary to get file contents
self.current_file.save(self.filename, content)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment