Обсуждение: pglister: bug: Can't add moderators (and create lists)
Hello, I'm still in the process of writing an install script for pglister. I'm at the point where auth is working and I'm testinglists. In the interface (in /admin/lists/list/1/change/), I cannot create a list because the "Moderators" field is always empty,and django won't let me create a list without moderators. As a workaround, I removed the necessity to have a moderator to test if I can add subscribers after list creation, but Istill cannot add any after list creation. See migration attached (I added both patch and migration, I'm not sure how you'resupposed to properly edit django apps) I'm a bit confused because django has "staff" and "superuser", but none of that is the same as moderators, and I can't seemto find the way to promote a user into one. Am I missing something? Cheers, -- Célestin Matte
Вложения
On Sat, Sep 18, 2021 at 11:53 AM Célestin Matte <celestin.matte@cmatte.me> wrote: > > Hello, > > I'm still in the process of writing an install script for pglister. I'm at the point where auth is working and I'm testinglists. > > In the interface (in /admin/lists/list/1/change/), I cannot create a list because the "Moderators" field is always empty,and django won't let me create a list without moderators. The reason the moderators field is mandatory, is that it's what's used to populate the list ownership alias. I think there may have been other reasons as well, see the commit message in 78dc0eea, but I don't recall exactly what they are. But that is definitely one reason for it being there now, so we can't remove that. You should be able to add any Subscriber as a moderator, they don't have to be a member of the particular list. The Subscriber entry is created the first time the user logged in, see web/pglister/lists/migration.py. Did you somehow manage to log in without this happening? > As a workaround, I removed the necessity to have a moderator to test if I can add subscribers after list creation, butI still cannot add any after list creation. See migration attached (I added both patch and migration, I'm not sure howyou're supposed to properly edit django apps) > I'm a bit confused because django has "staff" and "superuser", but none of that is the same as moderators, and I can'tseem to find the way to promote a user into one. Staff and Superuser are django functions and have nothing to do with the pglister "application level" features. They are both required to access /admin/ though, but they don't affect the rest of the application. -- Magnus Hagander Me: https://www.hagander.net/ Work: https://www.redpill-linpro.com/
Hello, >> In the interface (in /admin/lists/list/1/change/), I cannot create a list because the "Moderators" field is always empty,and django won't let me create a list without moderators. > > The reason the moderators field is mandatory, is that it's what's used > to populate the list ownership alias. I think there may have been > other reasons as well, see the commit message in 78dc0eea, but I don't > recall exactly what they are. But that is definitely one reason for it > being there now, so we can't remove that. > > You should be able to add any Subscriber as a moderator, they don't > have to be a member of the particular list. The Subscriber entry is > created the first time the user logged in, see > web/pglister/lists/migration.py. Did you somehow manage to log in > without this happening? It turns out the issue was not in Django, but client-side: JS files for admin were missing, so the moderator field was notfilled. I already noticed that CSS files were missing from /admin/, and made a PR back then: https://gitlab.com/pglister/pglister/-/merge_requests/24(Should I rather make PRs on gitlab or send patches on this list?) Are CSS, JS and font files supposed to be somehow generated, or should I make a patch adding them all manually? Unrelated issue I encountered when debugging: when activating logging in django, the log file get spammed with exceptionsevery time django is hitting a {%if somevariable %} syntax, even though that's the correct django way to test variableexistence [1]. Any idea what could be causing that? [1] https://docs.djangoproject.com/en/2.2/ref/templates/builtins/#if -- Célestin Matte
On Mon, Sep 20, 2021 at 6:15 PM Célestin Matte <celestin.matte@cmatte.me> wrote: > > Hello, > > >> In the interface (in /admin/lists/list/1/change/), I cannot create a list because the "Moderators" field is always empty,and django won't let me create a list without moderators. > > > > The reason the moderators field is mandatory, is that it's what's used > > to populate the list ownership alias. I think there may have been > > other reasons as well, see the commit message in 78dc0eea, but I don't > > recall exactly what they are. But that is definitely one reason for it > > being there now, so we can't remove that. > > > > You should be able to add any Subscriber as a moderator, they don't > > have to be a member of the particular list. The Subscriber entry is > > created the first time the user logged in, see > > web/pglister/lists/migration.py. Did you somehow manage to log in > > without this happening? > > It turns out the issue was not in Django, but client-side: JS files for admin were missing, so the moderator field wasnot filled. Oh. Oops :) > I already noticed that CSS files were missing from /admin/, and made a PR back then: https://gitlab.com/pglister/pglister/-/merge_requests/24(Should I rather make PRs on gitlab or send patches on this list?) MR/PR on gitlab is perfectly fine -- I had just missed it this time. That said, the MR is incorrect and we should not be importing a select part of django into our repository -- we should only have our own CSS there -- just like we don't import the python code. We link to it in wherever it is installed. For example, for my local pglister installation I have a mapping for static files of: /media/admin -> /home/mha/django/django22-py3/lib/python3.7/site-packages/django/contrib/admin/static/admin (this being in my virtualenv that holds the django installation) > Are CSS, JS and font files supposed to be somehow generated, or should I make a patch adding them all manually? *Our* CSS and JS files are all in the repo and should just be served up under /media. The django ones should be served up from django. There are no CSS or JS files being generated at this time. > Unrelated issue I encountered when debugging: when activating logging in django, the log file get spammed with exceptionsevery time django is hitting a {%if somevariable %} syntax, even though that's the correct django way to test variableexistence [1]. Any idea what could be causing that? > [1] https://docs.djangoproject.com/en/2.2/ref/templates/builtins/#if That's strange. I don't see any of that. Exactly what does the exception look like? -- Magnus Hagander Me: https://www.hagander.net/ Work: https://www.redpill-linpro.com/
> For example, for my local pglister installation I have a mapping for > static files of: > /media/admin -> > /home/mha/django/django22-py3/lib/python3.7/site-packages/django/contrib/admin/static/admin > > (this being in my virtualenv that holds the django installation) Oh, so these files are all shipped with django. Thanks, that solves the issue >> Unrelated issue I encountered when debugging: when activating logging in django, the log file get spammed with exceptionsevery time django is hitting a {%if somevariable %} syntax, even though that's the correct django way to test variableexistence [1]. Any idea what could be causing that? >> [1] https://docs.djangoproject.com/en/2.2/ref/templates/builtins/#if > > That's strange. I don't see any of that. Exactly what does the > exception look like? > Example on the main page, with a DEBUG-level logger activated: Exception while resolving variable 'title' in template 'home.html'. Traceback (most recent call last): File "/srv/pglister/local/web/pglister/lib/python3.7/site-packages/django/template/base.py", line 829, in _resolve_lookup current = current[bit] File "/srv/pglister/local/web/pglister/lib/python3.7/site-packages/django/template/context.py", line 83, in __getitem__ raise KeyError(key) KeyError: 'title' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/srv/pglister/local/web/pglister/lib/python3.7/site-packages/django/template/base.py", line 835, in _resolve_lookup if isinstance(current, BaseContext) and getattr(type(current), bit): AttributeError: type object 'RequestContext' has no attribute 'title' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/srv/pglister/local/web/pglister/lib/python3.7/site-packages/django/template/base.py", line 843, in _resolve_lookup current = current[int(bit)] ValueError: invalid literal for int() with base 10: 'title' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/srv/pglister/local/web/pglister/lib/python3.7/site-packages/django/template/base.py", line 850, in _resolve_lookup (bit, current)) # missing attribute django.template.base.VariableDoesNotExist: Failed lookup for key [title] in [{'True': True, 'False': False, 'None': None},{'csrf_token': <SimpleLazyObject: <function csrf.<locals>._get_val at 0x7fa5737bdea0>>, 'request': <WSGIRequest: GET'/'>, 'user': <SimpleLazyObject: <function AuthenticationMiddleware.process_request.<locals>.<lambda> at 0x7fa573832488>>,'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x7fa5737fc518>, 'messages': <django.contrib.messages.storage.fallback.FallbackStorageobject at 0x7fa573800a58>, 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10,'INFO': 20, 'SUCCESS': 25, 'WARNING': 30, 'ERROR': 40}}, {}, {'view': <pglister.lists.views.Home object at 0x7fa573800b70>}] This line triggering this is in templates/base.html: <title>{%if title%}{{title}} - {%endif%}PostgreSQL mailing lists</title> -- Célestin Matte
On Tue, Sep 21, 2021 at 12:01 PM Célestin Matte <celestin.matte@cmatte.me> wrote: > > > For example, for my local pglister installation I have a mapping for > > static files of: > > /media/admin -> > > /home/mha/django/django22-py3/lib/python3.7/site-packages/django/contrib/admin/static/admin > > > > (this being in my virtualenv that holds the django installation) > > Oh, so these files are all shipped with django. Thanks, that solves the issue Yup. > >> Unrelated issue I encountered when debugging: when activating logging in django, the log file get spammed with exceptionsevery time django is hitting a {%if somevariable %} syntax, even though that's the correct django way to test variableexistence [1]. Any idea what could be causing that? > >> [1] https://docs.djangoproject.com/en/2.2/ref/templates/builtins/#if > > > > That's strange. I don't see any of that. Exactly what does the > > exception look like? > > > > Example on the main page, with a DEBUG-level logger activated: > Exception while resolving variable 'title' in template 'home.html'. > Traceback (most recent call last): > File "/srv/pglister/local/web/pglister/lib/python3.7/site-packages/django/template/base.py", line 829, in _resolve_lookup > current = current[bit] > File "/srv/pglister/local/web/pglister/lib/python3.7/site-packages/django/template/context.py", line 83, in __getitem__ > raise KeyError(key) > KeyError: 'title' > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "/srv/pglister/local/web/pglister/lib/python3.7/site-packages/django/template/base.py", line 835, in _resolve_lookup > if isinstance(current, BaseContext) and getattr(type(current), bit): > AttributeError: type object 'RequestContext' has no attribute 'title' > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "/srv/pglister/local/web/pglister/lib/python3.7/site-packages/django/template/base.py", line 843, in _resolve_lookup > current = current[int(bit)] > ValueError: invalid literal for int() with base 10: 'title' > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "/srv/pglister/local/web/pglister/lib/python3.7/site-packages/django/template/base.py", line 850, in _resolve_lookup > (bit, current)) # missing attribute > django.template.base.VariableDoesNotExist: Failed lookup for key [title] in [{'True': True, 'False': False, 'None': None},{'csrf_token': <SimpleLazyObject: <function csrf.<locals>._get_val at 0x7fa5737bdea0>>, 'request': <WSGIRequest: GET'/'>, 'user': <SimpleLazyObject: <function AuthenticationMiddleware.process_request.<locals>.<lambda> at 0x7fa573832488>>,'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x7fa5737fc518>, 'messages': <django.contrib.messages.storage.fallback.FallbackStorageobject at 0x7fa573800a58>, 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10,'INFO': 20, 'SUCCESS': 25, 'WARNING': 30, 'ERROR': 40}}, {}, {'view': <pglister.lists.views.Home object at 0x7fa573800b70>}] > > > This line triggering this is in templates/base.html: > <title>{%if title%}{{title}} - {%endif%}PostgreSQL mailing lists</title> Huh, strange. I'm not seeing this on my local dev, and we're obviously also not seeing in production or nothing would work. These are both Debian environments though, python 3.7.3 and django 2.2.24. -- Magnus Hagander Me: https://www.hagander.net/ Work: https://www.redpill-linpro.com/