Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
47bd9f7 to
21d0b85
Compare
|
@AdrianDAlessandro I've rewritten this to us django data endpoint as we discussed instead of using javascript. This approach doesn't work so well with the shared page so I've disabled the download buttons on that page and added an issue to follow up here: #788 I think this should be ready to merge now but let me know what you think. |
24215c7 to
ff20ac5
Compare
AdrianDAlessandro
left a comment
There was a problem hiding this comment.
This is close. I am happy with the architecture approach. Just a few small details in the views themselves
There was a problem hiding this comment.
(Not for this PR) I wonder if these snippets of JS scripts should be in a separate folder, or sub folder? They seem like they should be considered a separate category from the HTML snippets that are intended to be in this folder. Perhaps in main/templates/main/snippets/scripts or main/templates/main/scripts?
| class DownloadUserSkillDataJSONView(View): | ||
| """A view that returns the user skill data as a JSON file.""" | ||
|
|
||
| def get(self, request: HttpRequest) -> JsonResponse: |
There was a problem hiding this comment.
The business logic (of building the dictionary) in this method is the same as for the CSV get method. The difference between them is in how user_skills_data is used later. Can that part of the code be abstracted into a standalone function?
There was a problem hiding this comment.
I've updated the views to use a mixin and base view. See code comments.
|
|
||
|
|
||
| @pytest.fixture | ||
| def client_logged_in(client, user): |
There was a problem hiding this comment.
Didn't realise we didn't have one of these!
There was a problem hiding this comment.
Let me know if you want me to pull out to another PR or just slide in with this one.
There was a problem hiding this comment.
No, it's fine to be in this PR. Adding these kinds of thing as and when they're needed makes the most sense to me
| from ..models import User as UserType | ||
|
|
||
|
|
||
| class _AuthenticatedHttpRequest(HttpRequest): |
There was a problem hiding this comment.
@AdrianDAlessandro I added "_" at the start of these so they are not imported into views/init.py which was causing type errors.
There was a problem hiding this comment.
These shouldn't be necessary at all (with importing strategy I mentioned elsewhere). But out of curiosity, what were the type errors?
There was a problem hiding this comment.
The type error was something to do with request.user cannot be assigned to User from models
|
|
||
| from ..models import User, UserSkill | ||
|
|
||
| logger = logging.getLogger(__name__) |
There was a problem hiding this comment.
@AdrianDAlessandro Some of this is duplicated in account_views.py
There was a problem hiding this comment.
Duplication shouldn't be required if we just import the TermsAcceptedMixin
340ffd5 to
912bc19
Compare
| return super().dispatch(request, *args, **kwargs) # type: ignore | ||
|
|
||
|
|
||
| class AuthenticatedDataView(_TermsAcceptedMixin, View): |
There was a problem hiding this comment.
@AdrianDAlessandro previously these endpoints were not requiring authentication so I've corrected this with a base class
There was a problem hiding this comment.
I don't think this base class adds anything, just use the TermsAcceptedMixin directly in the view.
| request: _AuthenticatedHttpRequest | ||
|
|
||
|
|
||
| class DownloadUserSkillDataMixin: |
There was a problem hiding this comment.
@AdrianDAlessandro I've used a mixin for this but we could have just as easily used a standalone function. Let me know what you think.
There was a problem hiding this comment.
I think a standalone function is more appropriate here. Mixins are for adding web-specific functionality, but this is just a database accessor
|
About to start reviewing this but worth noting there are some merge conflicts to resolve. So get to those ASAP |
Added the csv and json download data views that can be accessed from: - http://localhost:8000/accounts/download-skills-data/csv - http://localhost:8000/accounts/download-skills-data/json Also included an optional parameter to the json download to export anonymous json
Also made this togglable as they are no longer valid for the shared skills data view
Changed from category - competency_domain subcategory - competency
912bc19 to
cc3824c
Compare
Rebased to resolve conflicts |
AdrianDAlessandro
left a comment
There was a problem hiding this comment.
I've made a few suggestions, mainly to just pare back the extra boilerplate added. We really just need that _format_user_skill_data_for_download method as a function to be used in the views as they were structured before. If you want to add the authentication required element, then just import the existing mixin
There was a problem hiding this comment.
I don't think we need this file. You should be able to import the AuthenticatedHttpRequest and TermsAcceptedMixin straight into data_views.py and make these views require authentication by using that directly as a mixin.
There was a problem hiding this comment.
I partly agree except for two points:
- Importing between views doesn't seem right so perhaps we need a separate shared utils file?
- We have a separate file for account views so it seemed to make sense to have a separate one for account data views too.
I wasn't sure about having the dataview endpoints redirect to the login page which is what the TermsAcceptedMixin does. This would only actually happen if someone tried to go to the download link directly. I can revert to using the existing mixins.
|
|
||
| from ..models import User, UserSkill | ||
|
|
||
| logger = logging.getLogger(__name__) |
There was a problem hiding this comment.
Duplication shouldn't be required if we just import the TermsAcceptedMixin
| from ..models import User as UserType | ||
|
|
||
|
|
||
| class _AuthenticatedHttpRequest(HttpRequest): |
There was a problem hiding this comment.
These shouldn't be necessary at all (with importing strategy I mentioned elsewhere). But out of curiosity, what were the type errors?
| return super().dispatch(request, *args, **kwargs) # type: ignore | ||
|
|
||
|
|
||
| class AuthenticatedDataView(_TermsAcceptedMixin, View): |
There was a problem hiding this comment.
I don't think this base class adds anything, just use the TermsAcceptedMixin directly in the view.
| request: _AuthenticatedHttpRequest | ||
|
|
||
|
|
||
| class DownloadUserSkillDataMixin: |
There was a problem hiding this comment.
I think a standalone function is more appropriate here. Mixins are for adding web-specific functionality, but this is just a database accessor
| from django.urls import reverse | ||
|
|
||
|
|
||
| class ViewRequiresAuthenticationMixin: |
There was a problem hiding this comment.
Should be able to use the LoginRequiredMixin here instead
There was a problem hiding this comment.
As in the account_data_views.py comments should we extract this class to a separate util file?
a99b2da to
ac3b908
Compare
|
@AdrianDAlessandro I've used the mixins from the account views instead of recreating for the data account views. I've kept the separate file for now but I think some thought needs to go into how these files are arranged. Currenlty we have a separate |
3441c43 to
ff557fb
Compare
for more information, see https://pre-commit.ci
AdrianDAlessandro
left a comment
There was a problem hiding this comment.
Great! This is looking good. Just some failing listing checks in pre-commit to fix up and then feel free to merge!
Also, I agree about the overall structure needing some thought / improvement. And definitely we need to improve the consistency between the main folder and the tests folder.
Description
Implements a json download link in addition to the csv download link added previously.
Also improved the share button docs
Fixes #742
Fixes: #770
Type of change
Key checklist
python -m pytest)mkdocs serve)pre-commit run --all-files)Further checks