From 179cf580b6e2ce196aefe1069d00c0532c832d5e Mon Sep 17 00:00:00 2001 From: Jigyasu Rajput Date: Sat, 14 Dec 2024 14:03:18 +0530 Subject: [PATCH 1/4] Add help text and fix URL validation to prepend https:// if missing --- pycompanies/forms.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pycompanies/forms.py b/pycompanies/forms.py index 6fb8054..19bd5c2 100644 --- a/pycompanies/forms.py +++ b/pycompanies/forms.py @@ -1,17 +1,20 @@ from django import forms from django_summernote.widgets import SummernoteInplaceWidget from django.utils.translation import gettext_lazy as _ +from urllib.parse import urlparse from crispy_forms.helper import FormHelper from crispy_forms.layout import Div, ButtonHolder, Layout, Submit from .models import Company, UserCompanyProfile - class CompanyForm(forms.ModelForm): """A PyAr companies form.""" description = forms.CharField(widget=SummernoteInplaceWidget()) + link = forms.CharField( + help_text=_('Por favor, ingrese una URL válida con esquema (por ejemplo, https://).') + ) def __init__(self, *args, **kwargs): super(CompanyForm, self).__init__(*args, **kwargs) @@ -28,11 +31,16 @@ def __init__(self, *args, **kwargs): ) ) + def clean_link(self): + link = self.cleaned_data.get('link') + if link and not urlparse(link).scheme: + link = f'https://{link}' + return link + class Meta: fields = ['name', 'photo', 'link', 'description'] model = Company - class UserCompanyForm(forms.ModelForm): """A PyAr user companies form.""" From 202294c5105fd8b1aea6f621f867056a81414cda Mon Sep 17 00:00:00 2001 From: Jigyasu Rajput Date: Tue, 17 Dec 2024 08:59:43 +0530 Subject: [PATCH 2/4] Fix 403 error page aesthetics and ensure consistent URL generation --- joboffers/tests/test_models.py | 7 +++---- joboffers/views.py | 6 ++++-- settings.py | 6 ++++++ templates/403.html | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 settings.py create mode 100644 templates/403.html diff --git a/joboffers/tests/test_models.py b/joboffers/tests/test_models.py index dd0be5b..30c4479 100644 --- a/joboffers/tests/test_models.py +++ b/joboffers/tests/test_models.py @@ -512,16 +512,15 @@ def test_joboffer_get_publisher_mail_addresses_without_users(): def test_joboffer_get_full_url(settings): - """Test that the url being crafted has the correct BASE_URL and the right format.""" - dummy_url = 'example.com' dummy_job_slug = 'python-job' - settings.BASE_URL = dummy_url + settings.BASE_URL = 'example.com' joboffer_url = reverse('joboffers:view', kwargs={'slug': dummy_job_slug}) expected_url = "".join(('https://example.com', joboffer_url)) joboffer = JobOffer(slug=dummy_job_slug) result = joboffer.get_full_url() - assert expected_url == result + + assert result == expected_url @pytest.mark.django_db diff --git a/joboffers/views.py b/joboffers/views.py index 6c7772d..9f3566c 100644 --- a/joboffers/views.py +++ b/joboffers/views.py @@ -359,7 +359,9 @@ def update_object(self, offer): offer.state = OfferState.MODERATION offer.save() - moderators_message = TELEGRAM_MODERATION_MESSAGE.format(offer_url=offer.get_full_url()) + moderators_message = TELEGRAM_MODERATION_MESSAGE.format( + offer_url=offer.get_full_url() + ) send_notification_to_moderators(moderators_message) @@ -399,7 +401,7 @@ def get_queryset(self): queryset = super().get_queryset() search = self.request.GET.get('search') - if search: + if (search): search_filter = Q(title__icontains=search) | Q(description__icontains=search) else: search_filter = Q() diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..7feee99 --- /dev/null +++ b/settings.py @@ -0,0 +1,6 @@ +# ...existing code... + +# Add the custom 403 error handler +handler403 = 'django.views.defaults.permission_denied' + +# ...existing code... diff --git a/templates/403.html b/templates/403.html new file mode 100644 index 0000000..b3ade47 --- /dev/null +++ b/templates/403.html @@ -0,0 +1,17 @@ +{% extends "base_site.html" %} +{% load i18n %} + +{% block title %}403 - {{ block.super }}{% endblock %} + +{% block content %} +
+
+
+
+

{% trans "Access Denied" %}

+

{% trans "You are not authorized to view this page." %}

+
+
+
+
+{% endblock %} From 43739a497b0cb9971e380403689737eda628e1c2 Mon Sep 17 00:00:00 2001 From: Jigyasu Rajput Date: Sun, 5 Jan 2025 01:32:22 +0530 Subject: [PATCH 3/4] reverted unnecessary changes --- joboffers/tests/test_models.py | 7 ++++--- joboffers/views.py | 6 ++---- pycompanies/forms.py | 12 ++---------- settings.py | 6 ------ 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/joboffers/tests/test_models.py b/joboffers/tests/test_models.py index 30c4479..dd0be5b 100644 --- a/joboffers/tests/test_models.py +++ b/joboffers/tests/test_models.py @@ -512,15 +512,16 @@ def test_joboffer_get_publisher_mail_addresses_without_users(): def test_joboffer_get_full_url(settings): + """Test that the url being crafted has the correct BASE_URL and the right format.""" + dummy_url = 'example.com' dummy_job_slug = 'python-job' - settings.BASE_URL = 'example.com' + settings.BASE_URL = dummy_url joboffer_url = reverse('joboffers:view', kwargs={'slug': dummy_job_slug}) expected_url = "".join(('https://example.com', joboffer_url)) joboffer = JobOffer(slug=dummy_job_slug) result = joboffer.get_full_url() - - assert result == expected_url + assert expected_url == result @pytest.mark.django_db diff --git a/joboffers/views.py b/joboffers/views.py index 9f3566c..6c7772d 100644 --- a/joboffers/views.py +++ b/joboffers/views.py @@ -359,9 +359,7 @@ def update_object(self, offer): offer.state = OfferState.MODERATION offer.save() - moderators_message = TELEGRAM_MODERATION_MESSAGE.format( - offer_url=offer.get_full_url() - ) + moderators_message = TELEGRAM_MODERATION_MESSAGE.format(offer_url=offer.get_full_url()) send_notification_to_moderators(moderators_message) @@ -401,7 +399,7 @@ def get_queryset(self): queryset = super().get_queryset() search = self.request.GET.get('search') - if (search): + if search: search_filter = Q(title__icontains=search) | Q(description__icontains=search) else: search_filter = Q() diff --git a/pycompanies/forms.py b/pycompanies/forms.py index 19bd5c2..6fb8054 100644 --- a/pycompanies/forms.py +++ b/pycompanies/forms.py @@ -1,20 +1,17 @@ from django import forms from django_summernote.widgets import SummernoteInplaceWidget from django.utils.translation import gettext_lazy as _ -from urllib.parse import urlparse from crispy_forms.helper import FormHelper from crispy_forms.layout import Div, ButtonHolder, Layout, Submit from .models import Company, UserCompanyProfile + class CompanyForm(forms.ModelForm): """A PyAr companies form.""" description = forms.CharField(widget=SummernoteInplaceWidget()) - link = forms.CharField( - help_text=_('Por favor, ingrese una URL válida con esquema (por ejemplo, https://).') - ) def __init__(self, *args, **kwargs): super(CompanyForm, self).__init__(*args, **kwargs) @@ -31,16 +28,11 @@ def __init__(self, *args, **kwargs): ) ) - def clean_link(self): - link = self.cleaned_data.get('link') - if link and not urlparse(link).scheme: - link = f'https://{link}' - return link - class Meta: fields = ['name', 'photo', 'link', 'description'] model = Company + class UserCompanyForm(forms.ModelForm): """A PyAr user companies form.""" diff --git a/settings.py b/settings.py index 7feee99..e69de29 100644 --- a/settings.py +++ b/settings.py @@ -1,6 +0,0 @@ -# ...existing code... - -# Add the custom 403 error handler -handler403 = 'django.views.defaults.permission_denied' - -# ...existing code... From 57d9f912705ae2ab5271a691388f2d26d84794c9 Mon Sep 17 00:00:00 2001 From: Jigyasu Rajput <137029921+JigyasuRajput@users.noreply.github.com> Date: Sun, 5 Jan 2025 01:36:55 +0530 Subject: [PATCH 4/4] Delete settings.py --- settings.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 settings.py diff --git a/settings.py b/settings.py deleted file mode 100644 index e69de29..0000000