Conversation
|
@Karrp Could you say what task activities should be default for all projects or maybe talk about it with Adrian ? :) |
For existing projects, in data migration. |
managers/apps.py
Outdated
| name = "managers" | ||
|
|
||
| def ready(self) -> None: | ||
| import managers.signals # noqa, flake8 F401 issue # pylint: disable=unused-import |
There was a problem hiding this comment.
Why do you need to import it this way?
There was a problem hiding this comment.
@rwrzesien , @kbeker I couldn't import TaskActivityType in manager app in models so I decided to refactor whole handlers to file signals.py. On this page, It is written that we have to do this because if I wouldn't my handlers will not catch signals.
https://simpleisbetterthancomplex.com/tutorial/2016/07/28/how-to-create-django-signals.html
There was a problem hiding this comment.
What was the exact problem with imports? Maybe it could be avoided by just importing inside the method/function, which would be easier than moving a lot of code around.
There was a problem hiding this comment.
I hade this exception
Traceback (most recent call last):
File "manage.py", line 19, in <module>
execute_from_command_line(sys.argv)
File "/home/szymi/virtualenv/sheetstorm-SgY9UmI-/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/szymi/virtualenv/sheetstorm-SgY9UmI-/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/szymi/virtualenv/sheetstorm-SgY9UmI-/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/szymi/virtualenv/sheetstorm-SgY9UmI-/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/szymi/virtualenv/sheetstorm-SgY9UmI-/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/home/szymi/virtualenv/sheetstorm-SgY9UmI-/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/szymi/Dokumenty/GitRepos/sheetstorm/sheetstorm/managers/models.py", line 9, in <module>
from employees.models import TaskActivityType
File "/home/szymi/Dokumenty/GitRepos/sheetstorm/sheetstorm/employees/models.py", line 14, in <module>
from managers.models import Project
ImportError: cannot import name 'Project' from 'managers.models' (/home/szymi/Dokumenty/GitRepos/sheetstorm/sheetstorm/managers/models.py)
I think it happen because We imported Project in employees app and in managers app models we want to import TaskActivityType which is needed to work with handlers.
There was a problem hiding this comment.
@rwrzesien When I make import locally it works fine but
sheriff pylint says employees/templatetags/data_structure_element_selectors.py:1:0: R0401: Cyclic import (employees.models -> managers.models) (cyclic-import)
There was a problem hiding this comment.
I see that you have resolved this by making import directly in function, so it works now right?
There was a problem hiding this comment.
@rwrzesien , Yes it works but pylint gives one warning about cycling import
| return super().get(request, args, kwargs) | ||
|
|
||
| def post(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: | ||
| self.object = self.get_object() # pylint: disable=attribute-defined-outside-init |
There was a problem hiding this comment.
Yes, FormView doesn't have self.object so I inherit from SingleObjectMixin and use all methods from there to work with object and queryset. What is more it give protection to this view only for manager of current project, because without SingleObjectMixin this mixin IsManagerOfCurrentProjectMixin doesn't work.
There was a problem hiding this comment.
What is more when I wanted to use self.object during post I have to init this variable because then in form_valid I don't have it .
There was a problem hiding this comment.
What if you combine FormView and DetailView instead SingleObjectMixin?
There was a problem hiding this comment.
Sure I will do this
There was a problem hiding this comment.
So is this still needed after that?
There was a problem hiding this comment.
Yes it is, because I am using self.object here -> _add_task_activities_to_relation
kbeker
left a comment
There was a problem hiding this comment.
There are some things to polish. But in overall good job :)
managers/apps.py
Outdated
| name = "managers" | ||
|
|
||
| def ready(self) -> None: | ||
| import managers.signals # noqa, flake8 F401 issue # pylint: disable=unused-import |
We can do 2 things i think.
@kbeker what you think? |
dybi
left a comment
There was a problem hiding this comment.
I see a lot of work, great deal of which is in a good direction. However, some parts need solid polishing.
| continue | ||
| CustomUser.objects.filter(pk__in=pk_set).exclude( | ||
| Q(user_type=CustomUser.UserType.ADMIN.name) | ~Q(manager_projects=None) | ||
| ).update(user_type=CustomUser.UserType.EMPLOYEE.name) |
|
@Szymiks Almost there, I think the one important thing left is passing |
kbeker
left a comment
There was a problem hiding this comment.
I think that generally everything is OK here :) before merge I will test it also manually, but now we waiting for all approves :)
73824e2 to
f9d4457
Compare
f9d4457 to
7bd31fb
Compare
Except refactor, I also added post_save receiver to add default tasks for new project
7bd31fb to
03281e7
Compare


Resolves: #204
This PR will be change because @Karrp want this feature in differemt way.
Related:#469
In this PR I just created few things:
Should be done
task_activite_models-projects - m2mandis_defaultTaskActivityTypein models in manager app and importProjectin models in employee app.Will be done in next PR
Question
I have never done something like this, so when I should make some script or something to set default task activity list for all existing projects?