Skip to content
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

[fix] Fixed ignore notification widget JS loading on add view #128 #129

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions openwisp_notifications/templates/admin/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@

{% block admin_change_form_document_ready %}
{{ block.super }}
<script>
const owNotifyAppLabel = '{{ opts.app_label }}',
owNotifyModelName = '{{ opts.model_name }}',
uuidRegex = /\/((\w{4,12}-?)){5}\//,
owIsChangeForm = true;
let objectId;
try{
objectId = uuidRegex.exec(window.location)[0];
}
catch(error){
{% if change %}
<script>
const owNotifyAppLabel = '{{ opts.app_label }}',
owNotifyModelName = '{{ opts.model_name }}',
uuidRegex = /\/((\w{4,12}-?)){5}\//,
owIsChangeForm = true;
let objectId;
try{
objectId = /\/(\d+)\//.exec(window.location)[0];
objectId = uuidRegex.exec(window.location)[0];
}
catch(error){
throw error;
try{
objectId = /\/(\d+)\//.exec(window.location)[0];
}
catch(error){
throw error;
}
}
}
const owNotifyObjectId = objectId.replace(/\//g,'');
</script>
const owNotifyObjectId = objectId.replace(/\//g,'');
</script>
{% endif %}
{% endblock %}
5 changes: 5 additions & 0 deletions openwisp_notifications/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,8 @@ def test_object_notification_setting_configured(self):
reverse('admin:openwisp_users_user_change', args=(self.admin.pk,))
)
UserAdmin.Media = None

def test_ignore_notification_widget_add_view(self):
url = reverse('admin:openwisp_users_organization_add')
response = self.client.get(url)
self.assertNotContains(response, 'owIsChangeForm')