Skip to content

Feature employees interface#18

Merged
kbeker merged 10 commits intomasterfrom
feature-employees-interface
Mar 28, 2019
Merged

Feature employees interface#18
kbeker merged 10 commits intomasterfrom
feature-employees-interface

Conversation

@maciejSamerdak
Copy link
Copy Markdown
Collaborator

@maciejSamerdak maciejSamerdak commented Jan 28, 2019

Resolves #39, resolves #48

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.

Few parts of this code needs improvement
tenor 4
.

$('#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.

Please move this javascript 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

</tr>
{% for date, reports in reports_dict.items %}
<tr>
<td style="width:128px" rowspan={{ reports|length }}>
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 move all inline styling to .css 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


<h1>{{ UI_text.PAGE_TITLE.value }}{{ report.project }} ({{ report.date }})</h1>
</br>
<div class="modal-dialog" style="margin-bottom:0">
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.

If you have any styling please move it to .css 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

def test_queryset_as_dict_should_return_dictionary_where_keys_are_dates_and_values_are_lists_of_reports(self):
queryset = Report.objects.all()
dictionary = query_as_dict(queryset)
self.assertEqual(len(dictionary.items()), 2)
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.

You don't have to convert it into list. len() function works also with dicts :)

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

self.assertTrue(isinstance(list(dictionary.keys())[1], datetime.date))
self.assertTrue(isinstance(list(dictionary.values())[0][0], Report))
self.assertTrue(isinstance(list(dictionary.values())[0][1], Report))
self.assertTrue(isinstance(list(dictionary.values())[1][0], Report))
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.

You don't have to use self.assertTrue to all of them. It is enough to have only self.isinstance(). Also you don't have to use list converting as well, as I wrote above.

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.

List conversion was required for indexing, because neither dictionary.values() nor dictionary.keys() return an indexable type.

Comment thread employees/views.py
key = record.date
dictionary.setdefault(key, [])
dictionary[key].append(record)
return dictionary
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.

I saw this function in @MartynaAnnaGottschling PR. It should be in utils and be reusable for more than one app.

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.

I can tell you right now, that it will change it's functionality later on to be more specific. It's used to return specific set of data, designed for rendering lists of reports in requested format. Granted such method might be potentially useful in other places, but in reality we store all report related views in employees app (because that's were report model and serializer are stored in the first place).

And @MartynaAnnaGottschling won't be using it anymore, because it was useless for her anyway. It also actually performed different action than mine.

Do you still want me to move it to utils? Like I said, it's a specific tool meant to be used with employees app only.

Comment thread employees/views.py Outdated
'reports_dict': reports_dict,
'UI_text': ReportListStrings,
}, 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.

I think that we will need to think about it how to do database verification. If any error occurs will save() method raise exception? Please investigate it.

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.

image

So after my thorough investigation, it turns out that Django in fact throws an AssertionError if serializer.save() is called without serializer.is_valid() preceding it. Thus it forces you to perform validation check on serializer before saving it's data in database.
So I sabotaged the serializer to have it pass incomplete data to model. In such case an IntegrityError is thrown if model receives bad data.

Comment thread employees/views.py
serializer = ReportSerializer(
report, data=request.data,
context={'request': request}
)
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:

serializer = ReportSerializer(
    report,
    data=request.data,
    context={'request': request}
)

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 users/templates/base.html Outdated
<td style="padding:0 15px 0 15px;"><a href="{% url 'custom-projects-list' %}">{% trans 'Projects list' %}</a></td>
{% endif %}
<td style="padding:0 15px 0 15px;"><a href="{% url 'custom-report-list' %}">{% trans 'Reports' %}</a></td>
<td style="padding:0 15px 0 15px;"><a href="{% url 'logout' %}">{% trans 'Logout' %}</a></td>
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 move style to .css file

Comment thread utils/decorators.py
@@ -0,0 +1,3 @@
def notCallable(cls):
cls.do_not_call_in_templates = True
return cls
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 this decorator necessary?

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.

Yes, it is absolutely necessary in order to make enums accessible in templates. Otherwise no value is displayed after render.
I forgot what was exactly the issue, but it has something to do with calls in Django.

@MartynaAnnaGottschling MartynaAnnaGottschling force-pushed the feature-managers-app branch 3 times, most recently from b172f97 to d6924dd Compare February 21, 2019 10:13
@maciejSamerdak maciejSamerdak force-pushed the feature-employees-interface branch 2 times, most recently from 68c67fd to a38ed81 Compare February 26, 2019 13:33
@rwrzesien
Copy link
Copy Markdown
Contributor

@maciejSamerdak After some digging I see this is the starting pull request for the three following up :) But why it is being compared to feature-managers-app branch for which there is no pull request currently?

@maciejSamerdak maciejSamerdak added this to the tag 0.1.0 milestone Mar 4, 2019
@MartynaAnnaGottschling MartynaAnnaGottschling force-pushed the feature-managers-app branch 2 times, most recently from 0a10086 to 9e1a6e3 Compare March 8, 2019 13:41
@maciejSamerdak maciejSamerdak force-pushed the feature-employees-interface branch from 79e6049 to de9086a Compare March 22, 2019 14:33
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.

Just one thing to clarify and ready to merge.

Comment thread employees/templates/employees/report_list.html
@maciejSamerdak maciejSamerdak changed the base branch from feature-managers-app to master March 28, 2019 13:36
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 b3ac00d into master Mar 28, 2019
@kbeker kbeker deleted the feature-employees-interface branch March 28, 2019 14:48
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.

Add pop-ups for deleting objects Employee Base Interface

4 participants