Skip to content

Commit f24c92a

Browse files
committed
Merge branch 'main' of github.com:20c/django-handleref into main
Conflicts: poetry.lock
2 parents 82d6806 + 5484511 commit f24c92a

10 files changed

+148
-90
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

+3-83
Original file line numberDiff line numberDiff line change
@@ -1,98 +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)
7-
[![LGTM Grade](https://img.shields.io/lgtm/grade/python/github/20c/django-handleref)](https://lgtm.com/projects/g/20c/django-handleref/alerts/)
86
[![Codecov](https://img.shields.io/codecov/c/github/20c/django-handleref/master.svg?maxAge=3600)](https://codecov.io/github/20c/django-handleref)
97

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

9010
### License
9111

92-
Copyright 2015-2022 20C, LLC
12+
Copyright 2015-2023 20C, LLC
9313

9414
Licensed under the Apache License, Version 2.0 (the "License");
95-
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.
9616
You may obtain a copy of the License at
9717

9818
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

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 = "^3.1.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)