# DIT Activity Stream
## Installation
Read the [Django Hawk installation](https://github.com/uktrade/django-hawk/#installation) documentation.
Add the package to your `urls.py` file.
```python
from django.urls import include, path
urlpatterns = [
...
path("dit-activity-stream/", include("dit_activity_stream.urls")),
...
]
```
## How to implement?
Write your custom client, here is an example client for returning all users:
```python
from typing import Any, Dict
from django.contrib.auth import get_user_model
from django.db.models import QuerySet
from django.http import HttpRequest
from dit_activity_stream.client import ActivityStreamClient
User = get_user_model()
class ActivityStreamUserClient(ActivityStreamClient):
object_uuid_field: str = "user_id"
object_last_modified_field: str = "last_modified"
def get_queryset(self, request: HttpRequest) -> QuerySet:
return User.objects.all()
def render_object(self, object: User) -> Dict:
return {
"id": object.id,
"username": object.username,
"first_name": object.first_name,
"last_name": object.last_name,
}
```
Where the following attributes:
- `object_uuid_field` is a field on the Object that is a Unique Identifier for the object.
- This will be output in the URL GET parameter so it should be a UUID.
- `object_last_modified_field` us a field on the Object that holds a datetime value of when the object was last modified.
- This will be output in the URL GET parameter.
Set `DIT_ACTIVITY_STREAM_CLIENT_CLASS` in your django settings file:
```python
DIT_ACTIVITY_STREAM_CLIENT_CLASS = "package.client.ActivityStreamUserClient"
```
## Pushing to PyPI
- [PyPI Package](https://pypi.org/project/dit-activity-stream/)
- [Test PyPI Package](https://test.pypi.org/project/dit-activity-stream/)
Running `make build` will build the package into the `dist/` directory.
Running `make push-pypi-test` will push the built package to Test PyPI.
Running `make push-pypi` will push the built package to PyPI.
### Setting up poetry for pushing to PyPI
First you will need to add the test pypy repository to your poetry config:
```
poetry config repositories.test-pypi https://test.pypi.org/legacy/
```
Then go to https://test.pypi.org/manage/account/token/ and generate a token.
Then add it to your poetry config:
```
poetry config pypi-token.test-pypi XXXXXXXX
```
Then you also need to go to https://pypi.org/manage/account/token/ to generate a token for the real PyPI.
Then add it to your poetry config:
```
poetry config pypi-token.pypi XXXXXXXX
```
Now the make commands should work as expected.
Raw data
{
"_id": null,
"home_page": "https://github.com/uktrade/dit-activity-stream",
"name": "dit-activity-stream",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "django",
"author": "Cameron Lamb",
"author_email": "live.services@digital.trade.gov.uk",
"download_url": "https://files.pythonhosted.org/packages/16/8b/7b7909fc8e892ea486ed8625dcd74ceb2942988f5995f2e58ff972d391df/dit_activity_stream-0.2.4.tar.gz",
"platform": null,
"description": "# DIT Activity Stream\n\n## Installation\n\nRead the [Django Hawk installation](https://github.com/uktrade/django-hawk/#installation) documentation.\n\nAdd the package to your `urls.py` file.\n\n```python\nfrom django.urls import include, path\n\nurlpatterns = [\n ...\n path(\"dit-activity-stream/\", include(\"dit_activity_stream.urls\")),\n ...\n]\n```\n\n## How to implement?\n\nWrite your custom client, here is an example client for returning all users:\n\n```python\nfrom typing import Any, Dict\n\nfrom django.contrib.auth import get_user_model\nfrom django.db.models import QuerySet\nfrom django.http import HttpRequest\n\nfrom dit_activity_stream.client import ActivityStreamClient\n\nUser = get_user_model()\n\n\nclass ActivityStreamUserClient(ActivityStreamClient):\n object_uuid_field: str = \"user_id\"\n object_last_modified_field: str = \"last_modified\"\n\n def get_queryset(self, request: HttpRequest) -> QuerySet:\n return User.objects.all()\n\n def render_object(self, object: User) -> Dict:\n return {\n \"id\": object.id,\n \"username\": object.username,\n \"first_name\": object.first_name,\n \"last_name\": object.last_name,\n }\n```\n\nWhere the following attributes:\n- `object_uuid_field` is a field on the Object that is a Unique Identifier for the object.\n - This will be output in the URL GET parameter so it should be a UUID.\n- `object_last_modified_field` us a field on the Object that holds a datetime value of when the object was last modified.\n - This will be output in the URL GET parameter.\n\nSet `DIT_ACTIVITY_STREAM_CLIENT_CLASS` in your django settings file:\n\n```python\nDIT_ACTIVITY_STREAM_CLIENT_CLASS = \"package.client.ActivityStreamUserClient\"\n```\n\n## Pushing to PyPI\n\n- [PyPI Package](https://pypi.org/project/dit-activity-stream/)\n- [Test PyPI Package](https://test.pypi.org/project/dit-activity-stream/)\n\nRunning `make build` will build the package into the `dist/` directory.\nRunning `make push-pypi-test` will push the built package to Test PyPI.\nRunning `make push-pypi` will push the built package to PyPI.\n\n### Setting up poetry for pushing to PyPI\n\nFirst you will need to add the test pypy repository to your poetry config:\n\n```\npoetry config repositories.test-pypi https://test.pypi.org/legacy/\n```\n\nThen go to https://test.pypi.org/manage/account/token/ and generate a token.\n\nThen add it to your poetry config:\n\n```\npoetry config pypi-token.test-pypi XXXXXXXX\n```\n\nThen you also need to go to https://pypi.org/manage/account/token/ to generate a token for the real PyPI.\n\nThen add it to your poetry config:\n\n```\npoetry config pypi-token.pypi XXXXXXXX\n```\n\nNow the make commands should work as expected.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "DIT Activity Stream",
"version": "0.2.4",
"project_urls": {
"Homepage": "https://github.com/uktrade/dit-activity-stream"
},
"split_keywords": [
"django"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "27a0a63eb9196fe52dd90c25b208dccc00e1be71750021ab460256d2bbe3ad1c",
"md5": "60f837247ab3c6ce555560faf31eb6a9",
"sha256": "dec294088a3c8b9420b571c1083d42e3aaae2ff70c0e1c53daf7bb5b3a601a08"
},
"downloads": -1,
"filename": "dit_activity_stream-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "60f837247ab3c6ce555560faf31eb6a9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 11362,
"upload_time": "2025-02-27T17:13:02",
"upload_time_iso_8601": "2025-02-27T17:13:02.904564Z",
"url": "https://files.pythonhosted.org/packages/27/a0/a63eb9196fe52dd90c25b208dccc00e1be71750021ab460256d2bbe3ad1c/dit_activity_stream-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "168b7b7909fc8e892ea486ed8625dcd74ceb2942988f5995f2e58ff972d391df",
"md5": "b73bfe8d86909f6263e846d13a1b02fb",
"sha256": "75b37db87672f740d3529f0b814876ea445698e2e48b3cb75786f75db41d7c56"
},
"downloads": -1,
"filename": "dit_activity_stream-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "b73bfe8d86909f6263e846d13a1b02fb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 8005,
"upload_time": "2025-02-27T17:13:04",
"upload_time_iso_8601": "2025-02-27T17:13:04.011230Z",
"url": "https://files.pythonhosted.org/packages/16/8b/7b7909fc8e892ea486ed8625dcd74ceb2942988f5995f2e58ff972d391df/dit_activity_stream-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-27 17:13:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "uktrade",
"github_project": "dit-activity-stream",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "dit-activity-stream"
}