Store simple notes linked to Django(-cms) pages. Supports apphooks (but not custom apps)!
Reason this release was yanked:
bugs
Project description
django_simple_notes
Add private (available only to logged in users) notes to different pages of your Django-CMS site, through generic foreign keys (using content types).
Requirements
- Python 3.10+
- Django 2.2+
Install
- run
python3 -m pip install django_simple_notes
- add
django_simple_notes
to yourINSTALLED_APPS
- run
python manage.py migrate django_simple_notes
- that's all folks!
Features
- Add private notes on nearly each page of your site
- supports djangocms pages & djangocms-blog posts out of the box!
- you can add your own function to support even more type of pages (in apphooks)!
- Supports adding different notes for same page in different languages
How it works?
The main logic is in cms_toolbars.py
, in the get_content_type_and_id
function.
This function will try to retrieve the content type and the id of the object (CMS Page, DjangoCMS-blog Post...). If it find the object, another function will create an empty SimpleNote for this object, and will save it. This way, we don't need to differentiate the create and the edit link of the note in the toolbar (I don't know if it's possible to refresh only the toolbar to return the right link (create/edit)).
Another cool function is the get_queryset
in admin.py
. It will return the full queryset if we're on a change
page (edit the object in the admin). It will however only returns the "non-empty" objects in the list
view (in order to not clutter the list view too much).
Customize it!
You can define your own function that find object_ct
and object_id
in your settings!
Django simple notes will try to get a function from your site settings, named SIMPLE_NOTES_CUSTOM_CONTENT_TYPE_AND_ID
. It will then execute it, and if it returns None, None
it will launch its own get_content_type_and_id
function (in order to retrieve cms/djangocms-blog ct/id).
Here's an example to get you started:
Just copy/paste this file in your site settings, and update it to suits your needs.
def SIMPLE_NOTES_CUSTOM_CONTENT_TYPE_AND_ID(request):
# init parameters
object_ct = None
object_id = None
# condition from request (use this to find the object/page type)
if request.resolver_match.view_name in (
"my_app_view",
):
# necessary imports, be sure to include them in your function or you might stumble accross an import loop
from my_app.models import MyModel
slug = (
request.resolver_match.kwargs["slug"]
if "slug" in request.resolver_match.kwargs
else ""
)
# a condition (if we have a slug, then retrieve the object using its slug)
if slug:
my_object = MyModel.objects.get(slug=slug)
object_ct = my_object
object_id = my_object.id
else:
# another condition (for if we have its id)
id = (
request.resolver_match.kwargs["pk"]
if "pk" in request.resolver_match.kwargs
else ""
)
if id:
my_object = MyModel.objects.get(id=id)
object_ct = MyModel
object_id = my_object.id
# return found ct/id or None/None
# None/None will allow the regular `get_content_type_and_id` to proceed, searching for cms or blog pages
return object_ct, object_id
In order to get the object url, you will need to add another function
This function is named SIMPLE_NOTES_ADMIN_URLS
, and is called in admin.py
if it exists.
It's goal is to return an url for the current object, in order to add a direct link to the page in the admin list view.
If the returned url is None
, then simple notes will try to get the url of a CMS page or a djangocms-blog Post.
If no link is found, the object name will be displayed without a link.
Here's an example to get you started:
def SIMPLE_NOTES_ADMIN_URLS(obj):
if obj.content_type.model == "mymodel": # an object from a model with get_absolute_url()
from my_app.models import MyModel
return MyModel.objects.get(id=obj.object_id).get_absolute_url()
if obj.content_type.model == "myothermodel": # another model, which don't have get_absolute_url()
from django.urls import reverse
return reverse("view-name", kwargs={"pk": obj.object_id})
return None
Oh, and you can customize this too:
SIMPLE_NOTES_TOOLBAR_MENU_TEXT
(Default to_("Simple notes")
): The toolbar menu text.SIMPLE_NOTES_TOOLBAR_EDIT_TEXT
(Default to_("Edit note for current page")
): The toolbar edit button text.SIMPLE_NOTES_TOOLBAR_LIST_TEXT
(Default to_("Notes list")
): The toolbar "show list notes" text.
Toolbar screenshot with default values.
Todo?
Here's a sneak peak of the (maybe) future features:
- compatible not only with djangocms-text-ckeditor but with django-ckeditor too (no dependency to djangocms anymore!)
- supports simple django apps!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-simple-notes-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc0fc013f8b7635653f4415de778d2407e3ca28f0eacb61b94630c3908a10866 |
|
MD5 | 82ca9b76ba651f36a18de0a48b511aac |
|
BLAKE2b-256 | caad08797c81832f45b74bc262a987443c5b7dc3e2111e8cb1ab323eac5cbeda |
Hashes for django_simple_notes-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a59077c774be6b5bc57b2953a8fd9f5bdbe448af75903ce8f52a3969b0cc22c |
|
MD5 | 82cd99005577e9915c4ec77777c7a75c |
|
BLAKE2b-256 | ef9e1d7e566f2aafabb9f753239cc981cab46d65e6cc5f80065a1865314d6101 |