diff --git a/myproject/debug.log b/myproject/debug.log index 7d212eb4830b7df24b73fa9475c768682a50255a..a6f4149e7c7f53d647ba6f9d5d1f43452bbeaff2 100644 --- a/myproject/debug.log +++ b/myproject/debug.log @@ -437,3 +437,639 @@ Watching for file changes with StatReloader Watching for file changes with StatReloader /usr/src/app/myapp/views.py changed, reloading. Watching for file changes with StatReloader +Watching for file changes with StatReloader +Watching for file changes with StatReloader +Watching for file changes with StatReloader +Not Found: /favicon.ico +/usr/src/app/myapp/urls.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/urls.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/urls.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/urls.py changed, reloading. +Watching for file changes with StatReloader +Internal Server Error: /admin_table/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 204, in _get_response + self.check_response(response, callback) + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 332, in check_response + raise ValueError( +ValueError: The view myapp.views.admin_table didn't return an HttpResponse object. It returned None instead. +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +Internal Server Error: /admin_table/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 54, in admin_table + data = [dict(row) for row in rows] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 54, in <listcomp> + data = [dict(row) for row in rows] + ^^^^^^^^^ +TypeError: cannot convert dictionary update sequence element #0 to a sequence +Internal Server Error: /admin_table/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 54, in admin_table + data = [dict(row) for row in rows] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 54, in <listcomp> + data = [dict(row) for row in rows] + ^^^^^^^^^ +TypeError: cannot convert dictionary update sequence element #0 to a sequence +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 76, in users + admin_table = admin_table() + ^^^^^^^^^^^ +UnboundLocalError: cannot access local variable 'admin_table' where it is not associated with a value +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 82, in users + return render(request, 'user_page.html', context) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/shortcuts.py", line 24, in render + content = loader.render_to_string(template_name, context, request, using=using) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader.py", line 61, in render_to_string + template = get_template(template_name, using=using) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader.py", line 15, in get_template + return engine.get_template(template_name) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/backends/django.py", line 33, in get_template + return Template(self.engine.get_template(template_name), self) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/engine.py", line 175, in get_template + template, origin = self.find_template(template_name) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/engine.py", line 157, in find_template + template = loader.get_template(name, skip=skip) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loaders/cached.py", line 57, in get_template + template = super().get_template(template_name, skip) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loaders/base.py", line 28, in get_template + return Template( + ^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 154, in __init__ + self.nodelist = self.compile_nodelist() + ^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 196, in compile_nodelist + return parser.parse() + ^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader_tags.py", line 295, in do_extends + nodelist = parser.parse() + ^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader_tags.py", line 234, in do_block + nodelist = parser.parse(("endblock",)) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/defaulttags.py", line 960, in do_if + nodelist = parser.parse(("elif", "else", "endif")) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/defaulttags.py", line 860, in do_for + nodelist_loop = parser.parse( + ^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 481, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 479, in parse + filter_expression = self.compile_filter(token.contents) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 597, in compile_filter + return FilterExpression(token, self) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 698, in __init__ + raise TemplateSyntaxError( +django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: '["action"]' from 'row.2["action"]' +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 82, in users + return render(request, 'user_page.html', context) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/shortcuts.py", line 24, in render + content = loader.render_to_string(template_name, context, request, using=using) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader.py", line 61, in render_to_string + template = get_template(template_name, using=using) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader.py", line 15, in get_template + return engine.get_template(template_name) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/backends/django.py", line 33, in get_template + return Template(self.engine.get_template(template_name), self) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/engine.py", line 175, in get_template + template, origin = self.find_template(template_name) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/engine.py", line 157, in find_template + template = loader.get_template(name, skip=skip) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loaders/cached.py", line 57, in get_template + template = super().get_template(template_name, skip) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loaders/base.py", line 28, in get_template + return Template( + ^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 154, in __init__ + self.nodelist = self.compile_nodelist() + ^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 196, in compile_nodelist + return parser.parse() + ^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader_tags.py", line 295, in do_extends + nodelist = parser.parse() + ^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader_tags.py", line 234, in do_block + nodelist = parser.parse(("endblock",)) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/defaulttags.py", line 960, in do_if + nodelist = parser.parse(("elif", "else", "endif")) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/defaulttags.py", line 860, in do_for + nodelist_loop = parser.parse( + ^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 481, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 479, in parse + filter_expression = self.compile_filter(token.contents) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 597, in compile_filter + return FilterExpression(token, self) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 698, in __init__ + raise TemplateSyntaxError( +django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: '["action"]' from 'row.2.["action"]' +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 82, in users + return render(request, 'user_page.html', context) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/shortcuts.py", line 24, in render + content = loader.render_to_string(template_name, context, request, using=using) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader.py", line 61, in render_to_string + template = get_template(template_name, using=using) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader.py", line 15, in get_template + return engine.get_template(template_name) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/backends/django.py", line 33, in get_template + return Template(self.engine.get_template(template_name), self) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/engine.py", line 175, in get_template + template, origin = self.find_template(template_name) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/engine.py", line 157, in find_template + template = loader.get_template(name, skip=skip) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loaders/cached.py", line 57, in get_template + template = super().get_template(template_name, skip) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loaders/base.py", line 28, in get_template + return Template( + ^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 154, in __init__ + self.nodelist = self.compile_nodelist() + ^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 196, in compile_nodelist + return parser.parse() + ^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader_tags.py", line 295, in do_extends + nodelist = parser.parse() + ^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/loader_tags.py", line 234, in do_block + nodelist = parser.parse(("endblock",)) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/defaulttags.py", line 960, in do_if + nodelist = parser.parse(("elif", "else", "endif")) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 510, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 508, in parse + compiled_result = compile_func(self, token) + ^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/defaulttags.py", line 860, in do_for + nodelist_loop = parser.parse( + ^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 481, in parse + raise self.error(token, e) + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 479, in parse + filter_expression = self.compile_filter(token.contents) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 597, in compile_filter + return FilterExpression(token, self) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/template/base.py", line 698, in __init__ + raise TemplateSyntaxError( +django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: '["action"]' from 'row.2.["action"]' +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 82, in users + data = admin_table(request) + ^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 57, in admin_table + log = json.loads(row[2]) + ^^^^ +NameError: name 'json' is not defined +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 85, in users + context = {'data': data['data']} + ~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/http/response.py", line 199, in __getitem__ + return self.headers[header] + ~~~~~~~~~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/utils/datastructures.py", line 308, in __getitem__ + return self._store[key.lower()][1] + ~~~~~~~~~~~^^^^^^^^^^^^^ +KeyError: 'data' +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 86, in users + context = {'data': data['data']} + ~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/http/response.py", line 199, in __getitem__ + return self.headers[header] + ~~~~~~~~~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/utils/datastructures.py", line 308, in __getitem__ + return self._store[key.lower()][1] + ~~~~~~~~~~~^^^^^^^^^^^^^ +KeyError: 'data' +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 84, in users + print(data['data']) + ~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/http/response.py", line 199, in __getitem__ + return self.headers[header] + ~~~~~~~~~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/utils/datastructures.py", line 308, in __getitem__ + return self._store[key.lower()][1] + ~~~~~~~~~~~^^^^^^^^^^^^^ +KeyError: 'data' +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 84, in users + print(data['data']) + ~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/http/response.py", line 199, in __getitem__ + return self.headers[header] + ~~~~~~~~~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/utils/datastructures.py", line 308, in __getitem__ + return self._store[key.lower()][1] + ~~~~~~~~~~~^^^^^^^^^^^^^ +KeyError: 'data' +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 84, in users + print(data['data']) + ~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/http/response.py", line 199, in __getitem__ + return self.headers[header] + ~~~~~~~~~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/utils/datastructures.py", line 308, in __getitem__ + return self._store[key.lower()][1] + ~~~~~~~~~~~^^^^^^^^^^^^^ +KeyError: 'data' +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 84, in users + print(data['data']) + ~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/http/response.py", line 199, in __getitem__ + return self.headers[header] + ~~~~~~~~~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/utils/datastructures.py", line 308, in __getitem__ + return self._store[key.lower()][1] + ~~~~~~~~~~~^^^^^^^^^^^^^ +KeyError: 'data' +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 84, in users + print(data['data']) + ~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/http/response.py", line 199, in __getitem__ + return self.headers[header] + ~~~~~~~~~~~~^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/utils/datastructures.py", line 308, in __getitem__ + return self._store[key.lower()][1] + ~~~~~~~~~~~^^^^^^^^^^^^^ +KeyError: 'data' +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 87, in users + data = admin_table(request) + ^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 61, in admin_table + dt = datetime.fromisoformat(row[0]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +TypeError: fromisoformat: argument must be str +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 87, in users + data = admin_table(request) + ^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 61, in admin_table + dt = datetime.fromisoformat(string(row[0])) + ^^^^^^ +NameError: name 'string' is not defined +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 87, in users + data = admin_table(request) + ^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 61, in admin_table + dt = datetime.fromisoformat(string(row[0])) + ^^^^^^ +NameError: name 'string' is not defined +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 87, in users + data = admin_table(request) + ^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 61, in admin_table + dt = datetime.fromisoformat(string(row[0])) + ^^^^^^ +NameError: name 'string' is not defined +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 87, in users + data = admin_table(request) + ^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 61, in admin_table + dt = datetime.fromisoformat(string(row[0])) + ^^^^^^ +NameError: name 'string' is not defined +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 87, in users + data = admin_table(request) + ^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 61, in admin_table + dt = datetime.fromisoformat(string(row[0])) + ^^^^^^ +NameError: name 'string' is not defined +Internal Server Error: /user/ +Traceback (most recent call last): + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner + response = get_response(request) + ^^^^^^^^^^^^^^^^^^^^^ + File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response + response = wrapped_callback(request, *callback_args, **callback_kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 87, in users + data = admin_table(request) + ^^^^^^^^^^^^^^^^^^^^ + File "/usr/src/app/myapp/views.py", line 61, in admin_table + dt = datetime.fromisoformat(string(row[0])) + ^^^^^^ +NameError: name 'string' is not defined +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/models.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/models.py changed, reloading. +Watching for file changes with StatReloader +/usr/src/app/myapp/views.py changed, reloading. +Watching for file changes with StatReloader diff --git a/myproject/myapp/models.py b/myproject/myapp/models.py index f61b35dc0b7786e576c90f0f5e481fc4991e0552..87e3ccbd78453e60a54fc7ac2318b7d6aa34c06e 100644 --- a/myproject/myapp/models.py +++ b/myproject/myapp/models.py @@ -1,6 +1,6 @@ from django.db import models from django.contrib.auth import get_user_model -from django.contrib.auth.models import User, Group, Permission +from django.contrib.auth.models import User, Group, Permission from django.contrib.contenttypes.models import ContentType from enum import Enum @@ -34,18 +34,18 @@ from enum import Enum class Action(Enum): - UPLOAD_FILE = 'upload_file' - LOGIN = 'login' - REGISTER = 'register' - PAYMENT = 'payment' - GENERATE_FINANCIAL_STATEMENT = 'generate_financial_statement' - CHANGE_MLA = 'change_MLA' - RUN_ALGORITHM = 'run_algorithm' - INVALID_FILE = 'invalid_file' - INVALID_PASSWORD = 'invalid_password' - USER_DOES_NOT_EXIST = 'user_does_not_exist' - DOWNLOAD_BREAKDOWN = 'download_breakdown' - UNKNOWN = 'unknown' + UPLOAD_FILE = "The user has successfully uploaded a file." + LOGIN = "The user has logged in to their account." + REGISTER = "The user has registered for a new account." + PAYMENT_SUCCESSFUL = "The user has successfully made a payment." + GENERATE_FINANCIAL_STATEMENT = "The user has generated a financial statement." + CHANGE_MLA = "The user has changed their maximum loss amount (MLA)." + RUN_ALGORITHM = "The user has run an algorithm." + INVALID_FILE = "The uploaded file is invalid and cannot be processed." + INVALID_PASSWORD = "The user has entered an invalid password." + USER_DOES_NOT_EXIST = "The user does not exist in the system." + DOWNLOAD_BREAKDOWN = "The user has downloaded a breakdown of their data." + UNKNOWN = "An unknown error has occurred." # class Logs(models.Model): # """ diff --git a/myproject/myapp/templates/user_page.html b/myproject/myapp/templates/user_page.html index c9f63dbd8618a5b8e38f4506c9cc0b2afcc3fe6d..5f6b6d677eb77c7c091625aea61fc2ac3dcf34d6 100644 --- a/myproject/myapp/templates/user_page.html +++ b/myproject/myapp/templates/user_page.html @@ -9,53 +9,7 @@ </div> <!-- Right Content --> <div class="col-span-full xl:col-auto"> - <div - class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800" - > - <div - class="items-center sm:flex xl:block 2xl:flex sm:space-x-4 xl:space-x-0 2xl:space-x-4" - > - <img - class="mb-4 rounded-full w-28 h-28 sm:mb-0 xl:mb-4 2xl:mb-0" - src="https://i.pravatar.cc/300 -" - alt="Jese picture" - /> - <div> - <h3 class="mb-1 text-xl font-bold text-grey-300 dark:text-white"> - Profile picture - </h3> - <div class="mb-4 text-sm text-gray-500 dark:text-gray-400"> - JPG, GIF or PNG. Max size of 800K - </div> - <div class="flex items-center space-x-4"> - <button - type="button" - class="inline-flex items-center px-3 py-2 text-sm font-medium text-center text-white rounded-lg bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" - > - <svg - class="w-4 h-4 mr-2 -ml-1" - fill="currentColor" - viewBox="0 0 20 20" - xmlns="http://www.w3.org/2000/svg" - > - <path - d="M5.5 13a3.5 3.5 0 01-.369-6.98 4 4 0 117.753-1.977A4.5 4.5 0 1113.5 13H11V9.413l1.293 1.293a1 1 0 001.414-1.414l-3-3a1 1 0 00-1.414 0l-3 3a1 1 0 001.414 1.414L9 9.414V13H5.5z" - ></path> - <path d="M9 13h2v5a1 1 0 11-2 0v-5z"></path> - </svg> - Upload picture - </button> - <button - type="button" - class="py-2 px-3 text-sm font-medium text-grey-300 focus:outline-none bg-white rounded-lg border border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700" - > - Delete - </button> - </div> - </div> - </div> - </div> + <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800" > @@ -337,87 +291,12 @@ > <tr> <th scope="col" class="px-6 py-3">Date</th> - <th scope="col" class="px-6 py-3">File name</th> <th scope="col" class="px-6 py-3">Action</th> + <th scope="col" class="px-6 py-3">Details</th> </tr> </thead> <tbody> - {% comment %} MOCK DATA REPLACE WITH REAL DATA {% endcomment %} - <tr - class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 border-b dark:border-gray-700" - > - <th - scope="row" - class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white" - > - 17:45 17.02.2024 - </th> - <td class="px-6 py-4">some_music_1.mp3</td> - <td class="px-6 py-4"> - <a - href="#" - class="font-medium text-blue-600 dark:text-blue-500 hover:underline" - >Download</a - > - </td> - </tr> - - <tr - class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 border-b dark:border-gray-700" - > - <th - scope="row" - class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white" - > - 18:30 18.02.2024 - </th> - <td class="px-6 py-4">some_music_2.mp3</td> - <td class="px-6 py-4"> - <a - href="#" - class="font-medium text-blue-600 dark:text-blue-500 hover:underline" - >Download</a - > - </td> - </tr> - - <tr - class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 border-b dark:border-gray-700" - > - <th - scope="row" - class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white" - > - 19:15 19.02.2024 - </th> - <td class="px-6 py-4">some_music_3.mp3</td> - <td class="px-6 py-4"> - <a - href="#" - class="font-medium text-blue-600 dark:text-blue-500 hover:underline" - >Download</a - > - </td> - </tr> - - <tr - class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 border-b dark:border-gray-700" - > - <th - scope="row" - class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white" - > - 20:00 20.02.2024 - </th> - <td class="px-6 py-4">some_music_4.mp3</td> - <td class="px-6 py-4"> - <a - href="#" - class="font-medium text-blue-600 dark:text-blue-500 hover:underline" - >Download</a - > - </td> - </tr> + {% for entry in user_data %} <tr class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 border-b dark:border-gray-700" @@ -426,17 +305,17 @@ scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white" > - 20:45 21.02.2024 - </th> - <td class="px-6 py-4">some_music_5.mp3</td> +{{entry.date}} </th> + <td class="px-6 py-4">{{entry.action}}</td> <td class="px-6 py-4"> <a href="#" class="font-medium text-blue-600 dark:text-blue-500 hover:underline" - >Download</a + >{{entry.file}}</a > </td> </tr> + {%endfor%} </tbody> </table> </div> @@ -459,51 +338,11 @@ <th scope="col" class="px-6 py-3">Date</th> <th scope="col" class="px-6 py-3">Action</th> <th scope="col" class="px-6 py-3">User ID</th> - <th scope="col" class="px-6 py-3">User Email</th> + <th scope="col" class="px-6 py-3">status</th> </tr> </thead> <tbody> - {% comment %} MOCK DATA REPLACE WITH REAL LOGS {% endcomment %} - <tr - class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 border-b dark:border-gray-700" - > - <td - scope="row" - class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white" - > - 17:45 17.02.2024 - </td> - <td class="px-6 py-4"> - <a - href="#" - class="font-medium text-blue-600 dark:text-blue-500 hover:underline" - >Download</a - > - </td> - <td class="px-6 py-4">123</td> - <td class="px-6 py-4">user1@example.com</td> - </tr> - - <tr - class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 border-b dark:border-gray-700" - > - <td - scope="row" - class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white" - > - 21:30 22.02.2024 - </td> - <td class="px-6 py-4"> - <a - href="#" - class="font-medium text-blue-600 dark:text-blue-500 hover:underline" - >Upload</a - > - </td> - <td class="px-6 py-4">456</td> - <td class="px-6 py-4">user2@example.com</td> - </tr> - + {% for entry in admin_data %} <tr class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 border-b dark:border-gray-700" > @@ -511,58 +350,19 @@ scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white" > - 22:15 23.02.2024 - </td> +{{entry.date}} </td> <td class="px-6 py-4"> <a href="#" class="font-medium text-blue-600 dark:text-blue-500 hover:underline" - >Delete</a + >{{entry.action}}</a > </td> - <td class="px-6 py-4">789</td> - <td class="px-6 py-4">user3@example.com</td> - </tr> - - <tr - class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 border-b dark:border-gray-700" - > - <td - scope="row" - class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white" - > - 23:00 24.02.2024 - </td> + <td class="px-6 py-4">{{entry.user}}</td> <td class="px-6 py-4"> - <a - href="#" - class="font-medium text-blue-600 dark:text-blue-500 hover:underline" - >Modify</a - > - </td> - <td class="px-6 py-4">101</td> - <td class="px-6 py-4">user4@example.com</td> - </tr> - - <tr - class="odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800 border-b dark:border-gray-700" - > - <td - scope="row" - class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white" - > - 23:45 25.02.2024 - </td> - <td class="px-6 py-4"> - <a - href="#" - class="font-medium text-blue-600 dark:text-blue-500 hover:underline" - >View</a - > - </td> - <td class="px-6 py-4">112</td> - <td class="px-6 py-4">user5@example.com</td> + {{entry.status}}</td> </tr> + {% endfor %} </tbody> </table> </div> diff --git a/myproject/myapp/urls.py b/myproject/myapp/urls.py index 3fe793b65837013171da33e2ba0e4734ffee994a..fa018dac5085c64ebe2156f03612a86f98e8952d 100644 --- a/myproject/myapp/urls.py +++ b/myproject/myapp/urls.py @@ -1,5 +1,5 @@ from django.urls import path -from .views import index, users, maintenance, handler404, handler500, register, user_login, terms_conditions, privacy_policy, handling_music_file, pricing, generate_pdf +from .views import index, users, maintenance, handler404, handler500, register, user_login, terms_conditions, privacy_policy, handling_music_file, pricing, generate_pdf, admin_table urlpatterns = [ @@ -17,5 +17,6 @@ urlpatterns = [ path('uploading_file/', handling_music_file, name='uploading_file'), path('generate_pdf/', generate_pdf, name='generate_pdf'), path('pricing/', pricing, name='pricing'), - path('generate_pdf/', generate_pdf, name='generate_pdf') + path('generate_pdf/', generate_pdf, name='generate_pdf'), + path('admin_table/', admin_table, name='admin_table') ] diff --git a/myproject/myapp/views.py b/myproject/myapp/views.py index 0c4fea8ed905f4a3cc49a0927463f7e7cdeff0de..555691f83d60c983dd9670bd3cd2978045a89f6a 100644 --- a/myproject/myapp/views.py +++ b/myproject/myapp/views.py @@ -1,5 +1,5 @@ from django.contrib.auth import authenticate, login, logout -from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User from django.contrib import messages from django.http import HttpResponse @@ -8,20 +8,24 @@ from django.shortcuts import render, redirect from django.template import RequestContext import logging from reportlab.pdfgen import canvas +import json +from datetime import datetime from .forms import InstrumentDetectionForm, CustomRegistrationForm, LoginForm from .models import Log, Action, User +from django.http import JsonResponse +from django.db import connection logger = logging.getLogger(__name__) -def get_log_data(action, status='success', file=None, **additional_fields): +def get_log_data(action, status='success', file=None, description=None): log_data = { 'action': action.value, 'status': status, 'file': file, + 'description': description, } - log_data.update(additional_fields) return log_data def create_log(user, log_data): @@ -35,13 +39,54 @@ def handling_music_file(request): 'file': request.FILES['audio_file'].name, } log_data = get_log_data(Action.UPLOAD_FILE, 'success', file=request.FILES['audio_file'].name) - # create_log(request.user if request.user.is_authenticated else None, log_data) + create_log(request.user if request.user.is_authenticated else None, log_data) return HttpResponse('File uploaded successfully!',log_data) log_data = get_log_data(Action.invalid_file, 'error') - # create_log(None, log_data) + create_log(None, log_data) return HttpResponse('File invalid',log_data) - +def admin_table(request): + # Execute the query and fetch all rows + query = """SELECT date, user, log FROM myapp_log ORDER BY date DESC""" + with connection.cursor() as cursor: + cursor.execute(query) + rows = cursor.fetchall() + + # Create a list of dictionaries from the query results + data = [] + for row in rows: + # Parse the JSON string into a dictionary + log = json.loads(row[2]) + # Create a dictionary with the date, user, and JSON fields + date = row[0].strftime('%Y-%m-%d %H:%M:%S') + entry = {'date': date, 'user': row[1], 'file': log['file'], 'action': log['action'], 'status': log['status']} + data.append(entry) + + # Return the data as a JSON response + return JsonResponse({'data': data}, safe=False) + + +def user_table(request): + # Execute the query and fetch all rows + query = """SELECT date, user, log FROM myapp_log ORDER BY date DESC""" + # Only display user logs code below + # query = """SELECT date, user, log FROM myapp_log WHERE user = '{}' ORDER BY date DESC""".format(request.user) + with connection.cursor() as cursor: + cursor.execute(query) + rows = cursor.fetchall() + + # Create a list of dictionaries from the query results + data = [] + for row in rows: + # Parse the JSON string into a dictionary + log = json.loads(row[2]) + # Create a dictionary with the date, user, and JSON fields + date = row[0].strftime('%Y-%m-%d %H:%M:%S') + entry = {'date': date, 'user': row[1], 'file': log['file'], 'action': log['action'], 'status': log['status']} + data.append(entry) + + # Return the data as a JSON response + return JsonResponse({'data': data}, safe=False) def index(request): #for now this authenication just returns the main view @@ -59,7 +104,18 @@ def index(request): return render(request, 'index1.html', {'form': audio_form}) def users(request): - return render(request, 'user_page.html') + # Make a request to the admin_table view to get the data + context = {} + data_admin = admin_table(request) + data_user = user_table(request) + admin_dict = json.loads(data_admin.content) + user_dict = json.loads(data_user.content) + # Pass the data as a context variable to the template + # !!! ADMIN DATA ONLY DISPLAYED AND GET IF USER IS ADMIN !!! + context['admin_data'] = admin_dict['data'] + context['user_data'] = user_dict['data'] + + return render(request, 'user_page.html', context) def handler404(request, *args, **kwargs): response = render(request, '404.html', {}) @@ -132,4 +188,3 @@ def generate_pdf(request): p.save() return response -