Skip to content

Feature project should have customisable task activity list#460

Merged
kbeker merged 4 commits intomasterfrom
feature-project-should-have-custamisavle-task-activity-list
Aug 7, 2019
Merged

Feature project should have customisable task activity list#460
kbeker merged 4 commits intomasterfrom
feature-project-should-have-custamisavle-task-activity-list

Conversation

@Szymiks
Copy link
Contributor

@Szymiks Szymiks commented Jul 29, 2019

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

  • create fields in task_activite_models - projects - m2m and is_default
  • refactor singals to signals.py in manager app because I had problems with import TaskActivityType in models in manager app and import Project in models in employee app.
  • view when Admin and manager could manage project task activities or create new one.

Will be done in next PR

  • add view for Admin to manage all task activities
  • add dynamic filter during filling report

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?

@Szymiks Szymiks added feature New feature priority low Tasks with low priority labels Jul 29, 2019
@Szymiks Szymiks self-assigned this Jul 29, 2019
@Szymiks
Copy link
Contributor Author

Szymiks commented Jul 29, 2019

@Karrp Could you say what task activities should be default for all projects or maybe talk about it with Adrian ? :)

@rwrzesien
Copy link
Contributor

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?

For existing projects, in data migration.
For new ones, in function connected to post_save signal to Project model.

managers/apps.py Outdated
name = "managers"

def ready(self) -> None:
import managers.signals # noqa, flake8 F401 issue # pylint: disable=unused-import
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to import it this way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱 ⛔ 🚫 🙀

Copy link
Contributor Author

@Szymiks Szymiks Jul 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Contributor

@rwrzesien rwrzesien Jul 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@Szymiks Szymiks Aug 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you have resolved this by making import directly in function, so it works now right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you combine FormView and DetailView instead SingleObjectMixin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I will do this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is this still needed after that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is, because I am using self.object here -> _add_task_activities_to_relation

Copy link
Contributor

@rwrzesien rwrzesien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not bad in general, but some stuff has to be improved.
Also, it would be good to compare this pull request with actual requirements to see if it fits them, but I couldn't find them anywhere described.

@Karrp Karrp changed the title Feature project should have custamisavle task activity list Feature project should have customisable task activity list Jul 30, 2019
@Karrp
Copy link
Contributor

Karrp commented Jul 30, 2019

@Karrp Could you say what task activities should be default for all projects or maybe talk about it with Adrian ? :)

@Szymiks
If you create new project task activities should be None as default. Consequently when creating report employee should be able to chose every possible activity from list.

Copy link
Contributor

@kbeker kbeker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱 ⛔ 🚫 🙀

@Karrp
Copy link
Contributor

Karrp commented Jul 30, 2019

Hmm it is quite edge case but we still need to handle this. What to do with reports which have activity which can be deleted by manager from list of project_activities?

We can do 2 things i think.

  1. Not delete just inactive (not to choose in new reports -> edition? ) - more changes, need discussion
  2. Delete and change to Other - easier but changes history

@kbeker what you think?

Copy link
Contributor

@dybi dybi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of work, great deal of which is in a good direction. However, some parts need solid polishing.

@Szymiks Szymiks requested review from dybi and kbeker July 30, 2019 18:38
Copy link
Contributor

@dybi dybi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some clarifications are still needed.
baba_jaga_mysli

Copy link
Contributor

@dybi dybi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old-spice-guy-head-nod

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution 👍

@rwrzesien
Copy link
Contributor

@Szymiks Almost there, I think the one important thing left is passing task_activity_id in url and make proper html in the table.

Copy link
Contributor

@kbeker kbeker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that generally everything is OK here :) before merge I will test it also manually, but now we waiting for all approves :)

@Szymiks Szymiks force-pushed the feature-project-should-have-custamisavle-task-activity-list branch from 73824e2 to f9d4457 Compare August 5, 2019 10:26
@Szymiks Szymiks changed the title Feature project should have customisable task activity list Feature project should have customisable task activity list - will be change Aug 6, 2019
@Szymiks Szymiks changed the title Feature project should have customisable task activity list - will be change Feature project should have customisable task activity list Aug 6, 2019
@kbeker kbeker added this to the v1.0.0 milestone Aug 6, 2019
@Szymiks Szymiks requested a review from rwrzesien August 6, 2019 10:40
@Szymiks Szymiks force-pushed the feature-project-should-have-custamisavle-task-activity-list branch from f9d4457 to 7bd31fb Compare August 6, 2019 11:41
@kbeker kbeker force-pushed the feature-project-should-have-custamisavle-task-activity-list branch from 7bd31fb to 03281e7 Compare August 7, 2019 17:14
@kbeker kbeker merged commit 03281e7 into master Aug 7, 2019
@kbeker kbeker deleted the feature-project-should-have-custamisavle-task-activity-list branch August 7, 2019 17:48
@kbeker kbeker modified the milestones: v1.0.0, v0.9.0 Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature priority low Tasks with low priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Project should have customisable task activity list

5 participants