Skip to content

Feature allow employee to join project#21

Merged
kbeker merged 7 commits intomasterfrom
feature-allow-employee-to-join-project
Apr 1, 2019
Merged

Feature allow employee to join project#21
kbeker merged 7 commits intomasterfrom
feature-allow-employee-to-join-project

Conversation

@maciejSamerdak
Copy link
Copy Markdown
Collaborator

@maciejSamerdak maciejSamerdak commented Jan 28, 2019

Resolves #42
Resolves #105

@maciejSamerdak maciejSamerdak force-pushed the feature-accurate-hour-display branch from 1b8b92a to 4bf6d9e Compare February 5, 2019 13:05
@maciejSamerdak maciejSamerdak force-pushed the feature-allow-employee-to-join-project branch from 5c8805c to 4c22d16 Compare February 5, 2019 13:07
Copy link
Copy Markdown
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'm tired of reviewing all this PR's but this is the last one :D Please apply my changes

Comment thread employees/forms.py Outdated
def __init__(self, queryset, *args, **kwargs):
super().__init__(*args, **kwargs)
assert isinstance(queryset, QuerySet)
# assert isinstance(queryset.model, Project) No exception message supplied
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Delete this comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment thread employees/views.py Outdated
project.members.add(self.request.user)
project.full_clean()
project.save()
project.refresh_from_db()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it necessary here? I think it should work without refreshing database.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment thread employees/views.py
reports_serializer = ReportSerializer(data=request.data, context={'request': request})
reports_dict = query_as_dict(self.get_queryset())

if 'join' in request.POST:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could be changed to some kind of Enum and reused in place where it is assigned to request. Thanks to this will not stop working if it will be changed in another place

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You mean the 'join' string? It's an id from HTML template, so I'd say it's name is rather irrelevant, but I could supply some sort of constant for it. The question is whether it's worth the extra effort?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yea, you're right. It won't be necessary :)

Comment thread employees/views.py Outdated
'project_form': self.project_form,
})

if not reports_serializer.is_valid():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also please change it into elif

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

What are the benefits of it?

Comment thread employees/views.py Outdated
'UI_text': ReportListStrings,
'project_form': self.project_form,
}, status=201)
# QUESTION: Should I use some sort of database verification prior to returning Response with status 201?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be deleted in previous PR. What save() method returns if something goes wrong should be investigated.

$('#dialog').dialog('open');
});
});
</script>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move this function to .js file

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

queryset_length = 10
for i in range(queryset_length):
self.project = Project(
name="Test Project %d" % i,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please change it into f-string

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

@maciejSamerdak maciejSamerdak force-pushed the feature-accurate-hour-display branch from 802317d to 620bd5b Compare February 25, 2019 15:35
@maciejSamerdak maciejSamerdak force-pushed the feature-allow-employee-to-join-project branch from ba63f8b to b899baa Compare February 25, 2019 15:37
@maciejSamerdak maciejSamerdak force-pushed the feature-accurate-hour-display branch from 942cd4b to 3386a7d Compare February 26, 2019 13:35
@maciejSamerdak maciejSamerdak force-pushed the feature-allow-employee-to-join-project branch from 2823264 to 328f7b0 Compare February 26, 2019 13:35
@rwrzesien
Copy link
Copy Markdown
Contributor

@maciejSamerdak It would be good to create an issue for what you are adding with this pull request, or link to an existing one.

@maciejSamerdak maciejSamerdak added this to the tag 0.1.0 milestone Mar 4, 2019
@maciejSamerdak maciejSamerdak force-pushed the feature-allow-employee-to-join-project branch from d32b90a to c0e9652 Compare March 20, 2019 16:21
@maciejSamerdak maciejSamerdak force-pushed the feature-accurate-hour-display branch from 3386a7d to 78535dd Compare March 20, 2019 16:22
@maciejSamerdak maciejSamerdak force-pushed the feature-allow-employee-to-join-project branch from 93f13c4 to 805e3a5 Compare March 22, 2019 13:28
@maciejSamerdak maciejSamerdak force-pushed the feature-accurate-hour-display branch from 78535dd to 693846b Compare March 22, 2019 14:33
@maciejSamerdak maciejSamerdak force-pushed the feature-allow-employee-to-join-project branch from 805e3a5 to d52c409 Compare March 22, 2019 14:34
@maciejSamerdak maciejSamerdak force-pushed the feature-accurate-hour-display branch from 693846b to 1af60a5 Compare March 28, 2019 14:58
@maciejSamerdak maciejSamerdak force-pushed the feature-allow-employee-to-join-project branch from f2ef2ef to 2470564 Compare March 28, 2019 14:59
@maciejSamerdak maciejSamerdak changed the base branch from feature-accurate-hour-display to master March 28, 2019 15:38
@maciejSamerdak maciejSamerdak force-pushed the feature-allow-employee-to-join-project branch from 2470564 to 239157f Compare March 28, 2019 16:36
kbeker
kbeker previously approved these changes Mar 28, 2019
Copy link
Copy Markdown
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.

Generally OK. Please squash fixups and apply one thing which I mentioned in comment

response = ReportDetail.as_view()(request, pk=self.report.pk)
self.report.refresh_from_db()
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.data['errors'])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please change this assert that you check exactly what error is in this dict

Copy link
Copy Markdown
Collaborator Author

@maciejSamerdak maciejSamerdak Mar 28, 2019

Choose a reason for hiding this comment

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

In order to get to the ErrorDetail object, I have to do this:
response.data['errors']['project'][0]

Then I can either get to the code
response.data['errors']['project'][0].code = 'does_not_exist'
or to the (very specific) message
str(response.data['errors']['project'][0]) = 'Object with name=Other Project does not exist.'

Which one should I use? Or should just narrow it down to checking if field specific errors exist? self.assertIsNotNone(response.data['errors']['project'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@maciejSamerdak I would prefer to check response.data['errors']['project'][0].code = 'does_not_exist' but I know that to change it everywhere is very big effort, so please just apply this to this PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment thread employees/views.py
reports_serializer = ReportSerializer(data=request.data, context={'request': request})
reports_dict = query_as_dict(self.get_queryset())

if 'join' in request.POST:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yea, you're right. It won't be necessary :)

@maciejSamerdak maciejSamerdak force-pushed the feature-allow-employee-to-join-project branch from ba8ccc0 to 083c20c Compare April 1, 2019 11:49
Adds form with singular `ChoiceField` which is supposed to contain a
list of projects the user can join to.
Due to increased complexity of its' functionality, the class' structure
has been heavily modified, introducing helper methods and additional
fields.

Most important of all, an `initial` method, which contains actions to be
performed before each HTTP call, has been overridden to include
initiation of aforementioned fields.
Added javascript and HTML code for pop-up functionality
Limits projects displayed in project field in report detail view to only
those which author is a member of.
Adds tests for project join form and extends tests in custom views,
regarding applied changes to code.
@kbeker kbeker force-pushed the feature-allow-employee-to-join-project branch from 083c20c to dbc9487 Compare April 1, 2019 15:18
Copy link
Copy Markdown
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.

Ready to merge

@kbeker kbeker merged commit dbc9487 into master Apr 1, 2019
@kbeker kbeker deleted the feature-allow-employee-to-join-project branch April 1, 2019 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants