Skip to content

Commit eb265db

Browse files
jason20cvegu
andauthoredJun 5, 2023
Documentation pass (#18)
* initial commit * fix examples, formatting * formatting * add documentation * add api docs * update README.md * poetry relock --------- Co-authored-by: Stefan Pratter <stefan@20c.com>
1 parent 6c92607 commit eb265db

11 files changed

+178
-103
lines changed
 

‎.github/workflows/ci.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: ci
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check out repository
11+
uses: actions/checkout@v2
12+
- name: Install virtualenv from poetry
13+
uses: 20c/workflows/poetry@v1
14+
- name: deploy mkdocs gh-pages site
15+
run: |
16+
poetry run mkdocs gh-deploy --force

‎README.md

+2-81
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,18 @@
1-
21
# django-handleref
32

43
[![PyPI](https://img.shields.io/pypi/v/django-handleref.svg?maxAge=3600)](https://pypi.python.org/pypi/django-handleref)
54
[![PyPI](https://img.shields.io/pypi/pyversions/django-handleref.svg?maxAge=600)](https://pypi.python.org/pypi/django-handleref)
65
[![Tests](https://github.com/20c/django-handleref/workflows/tests/badge.svg)](https://github.com/20c/django-handleref)
76
[![Codecov](https://img.shields.io/codecov/c/github/20c/django-handleref/master.svg?maxAge=3600)](https://codecov.io/github/20c/django-handleref)
87

9-
track when an object was created or changed and allow querying based on time and versioning (w/ django-reversion support)
10-
11-
## HandleRefModel as a base for all your models
12-
13-
from django.db import models
14-
from django_handleref.models import HandleRefModel
15-
16-
class Test(HandleRefModel):
17-
name = models.CharField(max_length=255)
18-
19-
## Querying for modification since
20-
21-
It is now possible for you to see which instances of a model have been created or modified
22-
since a specific time or version
23-
24-
import time
25-
26-
# create instance
27-
test = Test.objects.create(name="This is a test")
28-
29-
# keep track of time, we need this later
30-
t = time.time()
31-
32-
# modifying and saving it
33-
test.name = "Changed my mind"
34-
test.save()
35-
36-
# now we can use the handleref manager to retrieve it
37-
Test.handleref.since(timestamp=t).count() # 1
38-
Test.handleref.since(timestamp=time.time().count() #0
39-
40-
41-
## Soft delete
42-
43-
By default all models extending HandleRefModel will softdelete when their delete() method is called.
44-
Note that this currently wont work for batch deletes - as this does not call the delete() method.
45-
46-
test = Test.objects.get(id=1)
47-
test.delete()
48-
49-
# querying handleref undeleted will not contain the deleted object
50-
Test.handleref.undeleted().filter(id=1).count() #0
51-
52-
# querying handleref since will not contain the deleted object
53-
Test.handleref.since(timestamp=t).filter(id=1).count() #0
54-
55-
# passing deleted=True to handleref since will contain the deleted object
56-
Test.handleref.since(timestamp=t, deleted=True).filter(id=1).count() #1
57-
58-
# querying using the standard objects manager will contain the deleted object
59-
Test.objects.filter(id=1).count() #1
60-
61-
# You may also still hard-delete by passing hard=True to delete
62-
test.delete(hard=True)
63-
Test.objects.filter(id=1).count() #0
64-
65-
## Versioning (with django-reversion)
66-
67-
Requires
68-
69-
django-reversion==1.8.7
70-
71-
When django-reversion is installed all your HandleRefModels will be valid for versioning.
72-
73-
import reversion
74-
75-
with reversion.create_revision():
76-
obj = Test.objects.create(name="This is a test")
77-
obj.save()
78-
79-
obj.version #1
80-
81-
obj.name = "Changed my mind"
82-
obj.save()
83-
84-
obj.version #2
85-
86-
Test.handleref.since(version=1).count() #1
87-
8+
Track when an object was created or changed and allow querying based on time and versioning (w/ `django-reversion` support)
889

8910
### License
9011

9112
Copyright 2015-2022 20C, LLC
9213

9314
Licensed under the Apache License, Version 2.0 (the "License");
94-
you may not use this softare except in compliance with the License.
15+
you may not use this software except in compliance with the License.
9516
You may obtain a copy of the License at
9617

9718
http://www.apache.org/licenses/LICENSE-2.0

‎docs/api/django_handleref.admin.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{pymdgen:django_handleref.admin}

‎docs/api/django_handleref.manager.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{pymdgen:django_handleref.manager}

‎docs/api/django_handleref.util.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{pymdgen:django_handleref.util}

‎docs/api/django_handleref.version.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{pymdgen:django_handleref.version}

‎docs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{!README.md!}

‎docs/quickstart.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Quickstart
2+
3+
## Installation
4+
5+
You can install using pip:
6+
```
7+
pip install django-handleref
8+
```
9+
Optionally install `django-reversions` if you want versioning support.
10+
```
11+
pip install django-reversion
12+
```
13+
Include them in your `INSTALLED_APPS`
14+
```python
15+
INSTALLED_APPS=[
16+
...
17+
"django_handleref",
18+
"reversion",
19+
...
20+
],
21+
```
22+
23+
## HandleRefModel as a base for all your models
24+
25+
from django.db import models
26+
from django_handleref.models import HandleRefModel
27+
28+
class Test(HandleRefModel):
29+
name = models.CharField(max_length=255)
30+
31+
## Querying for modification since
32+
33+
It is now possible for you to see which instances of a model have been created or modified
34+
since a specific time or version:
35+
36+
import time
37+
38+
# create instance
39+
test = Test.objects.create(name="This is a test")
40+
41+
# keep track of time, we need this later
42+
t = time.time()
43+
44+
# modifying and saving it
45+
test.name = "Changed my mind"
46+
test.save()
47+
48+
# now we can use the handleref manager to retrieve it
49+
Test.handleref.since(timestamp=t).count() #1
50+
Test.handleref.since(timestamp=time.time()).count() #0
51+
52+
53+
## Soft delete
54+
55+
By default, all models extending `HandleRefModel` will softdelete when their delete() method is called.
56+
Note that this currently won't work for batch deletes - as this does not call the delete() method.
57+
58+
test = Test.objects.get(id=1)
59+
test.delete()
60+
61+
# querying handleref undeleted will not contain the deleted object
62+
Test.handleref.undeleted().filter(id=1).count() #0
63+
64+
# querying handleref since will not contain the deleted object
65+
Test.handleref.since(timestamp=t).filter(id=1).count() #0
66+
67+
# passing deleted=True to handleref since will contain the deleted object
68+
Test.handleref.since(timestamp=t, deleted=True).filter(id=1).count() #1
69+
70+
# querying using the standard objects manager will contain the deleted object
71+
Test.objects.filter(id=1).count() #1
72+
73+
# You may also still hard-delete by passing hard=True to delete
74+
test.delete(hard=True)
75+
Test.objects.filter(id=1).count() #0
76+
77+
## Versioning (with django-reversion)
78+
79+
Requires
80+
81+
django-reversion>=3.0.0
82+
83+
When `django-reversion` is installed all your `HandleRefModel`s will be valid for versioning.
84+
85+
import reversion
86+
87+
with reversion.create_revision():
88+
obj = Test.objects.create(name="This is a test")
89+
obj.save()
90+
91+
obj.version #1
92+
93+
obj.name = "Changed my mind"
94+
obj.save()
95+
96+
obj.version #2
97+
98+
Test.handleref.since(version=1).count() #1
99+

‎mkdocs.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
site_name: django-handleref
2+
site_url: https://github.com/20c/django-handleref
3+
4+
theme: readthedocs
5+
6+
nav:
7+
- Home: index.md
8+
- Quickstart: quickstart.md
9+
- API:
10+
- django_handleref.admin: api/django_handleref.admin.md
11+
- django_handleref.manager: api/django_handleref.manager.md
12+
- django_handleref.util: api/django_handleref.util.md
13+
- django_handleref.version: api/django_handleref.version.md
14+
15+
markdown_extensions:
16+
- markdown_include.include
17+
- admonition
18+
- pymdgen

‎poetry.lock

+31-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ mypy = ">=0.950"
4141
pre-commit = "^2.13"
4242
pyupgrade = "^2.19.4"
4343

44-
# docs
45-
markdown = "*"
46-
markdown-include = ">=0.5,<1"
47-
mkdocs = "^1"
48-
4944
# ctl
5045
ctl = "^1"
5146
jinja2 = "^2.11.2"
5247
tmpl = "^1"
5348
twine = "^3.3.0"
5449

55-
[tool.poetry.plugins."markdown.extensions"]
56-
pymdgen = "pymdgen.md:Extension"
50+
# docs
51+
markdown-include = ">=0.5"
52+
mkdocs = "^1.2.3"
53+
pymdgen = "^1.0.0"
54+
55+
[tool.poetry.extras]
56+
docs = ["markdown-include", "mkdocs", "pymdgen"]
5757

5858
[build-system]
5959
requires = ["poetry>=0.12"]

0 commit comments

Comments
 (0)
Please sign in to comment.