New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove a Language #100
base: master
Are you sure you want to change the base?
Remove a Language #100
Conversation
Codecov Report
@@ Coverage Diff @@
## master #100 +/- ##
==========================================
+ Coverage 89.5% 89.86% +0.36%
==========================================
Files 14 16 +2
Lines 505 523 +18
==========================================
+ Hits 452 470 +18
Misses 53 53
|
@@ -0,0 +1,41 @@ | |||
{% extends "wagtailadmin/base.html" %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extend from the existing delete.html
template. This way you only have to override content_main
and we keep the most of wagtails interface intact.
<p><a href="{{ view.index_url }}" class="button">{% trans 'Go back to listing' %}</a></p> | ||
{% else %} | ||
<p>{{ view.confirmation_message }}</p> | ||
{% with related_pages=view.get_linked_pages %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When removing a canonical_page
we list the related pages with a templatetag, imo it's better to have the same approach here.. The codebase stays more consistent that way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Also this way it'll be more reusable.
src/wagtailtrans/views/language.py
Outdated
translatable pages (if there is any) before we can delete a Language | ||
which are references through protected foreign key. | ||
""" | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First check if there are related pages, remove them and finally call the super method which will delete the language object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/wagtailtrans/views/language.py
Outdated
try: | ||
self.delete_instance() | ||
except models.ProtectedError: | ||
self.remove_related_pages() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is a one-liner, it's fine by me to just call the delete here
@@ -0,0 +1,24 @@ | |||
import django |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we try not to create too much templatetag files, I think having 2 files one: wagtailtrans_tags
to be used by project implementation the other: wagtailtrans_admin_tags
to store all the tags needed in the wagtail admin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
|
||
@assignment_tag | ||
def get_language_relate_pages(language): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better name would be get_related_pages_for_language
reviews are implemented! @mikedingjan |
Whats the update on this one? can this be merged now? |
Hi @arifin4web, |
I'm getting the following stacktrace when I click on delete language:
Can we fix this and add a test for that? Stacktrace
|
|
||
|
||
@assignment_tag | ||
def get_relate_pages_for_language(language): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in here: get_related_pages_for_language
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😳
Hi @arifin4web I took a moment to make the overview for deletion a little more appealing. Last thing I noticed when we would be deleting a canonical language it would also be relevant to show the impact of connected pages which are linked to the canonical language. For eg we have the following languages:
Deleting English will also delete Dutch. It is this something we can show accordingly in the list of pages we are about to delete? |
As I remember correctly the Because we have a So we can either disconnect the Thing to keep in mind, |
87bdd28
to
4c29263
Compare
I apologize for being so late with this MR. My opinion about removing a default language is that we should never allow them to be deleted. One of the reason being, after we delete a default language we wouldn't be able to create a translatable page. We have to create/set another language as default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arifin4web can you take a look at issue #10 it would be nice if we can check for the removal of the user groups too.
src/wagtailtrans/views/language.py
Outdated
Also we'll not allow to delete the default language. | ||
""" | ||
if self.instance.is_default: | ||
raise Exception("Can't delete a default language") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would raise a 403 here. instead of 500 error.
Also, maybe it might be nice to check if the language is default before actually doing the post.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Yes agreed. I'll throw a 403 instead.
-
Well, we don't have to, because in a normal template flow you'll never be in the
post
endpoint. we have different template so user will not be able to make apost
request via admin/dashboard in case of a default language. But this check ensure that even if it does able to make the request we won't be processing this.
src/wagtailtrans/views/language.py
Outdated
raise Exception("Can't delete a default language") | ||
|
||
if self.instance.pages.count(): | ||
self.instance.pages.all().delete() |
There was a problem hiding this comment.
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 change this, but why not make the foreign key in TranslatablePage a on_delete=models.CASCADE
? I'm curious about your thoughts on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As incase of sync=True
, on_delete=models.CASCADE
will make our tree unstable, I think it's better to handle it here.
0e79fa9
to
19a56bb
Compare
be558a6
to
e9c79cf
Compare
As suggested in the issue #10
pre_delete
signal couldn't be used. The signal doesn't Trigger before raising ProtectedError. Therefore Implemented a custom delete view forLanguageModelAdmin
which will: