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 403 Error Page Aesthetics #592

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 3 additions & 4 deletions joboffers/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
JigyasuRajput marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.django_db
Expand Down
6 changes: 4 additions & 2 deletions joboffers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -399,7 +401,7 @@ def get_queryset(self):
queryset = super().get_queryset()
search = self.request.GET.get('search')

if search:
if (search):
eduzen marked this conversation as resolved.
Show resolved Hide resolved
search_filter = Q(title__icontains=search) | Q(description__icontains=search)
else:
search_filter = Q()
Expand Down
12 changes: 10 additions & 2 deletions pycompanies/forms.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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."""

Expand Down
6 changes: 6 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ...existing code...

# Add the custom 403 error handler
handler403 = 'django.views.defaults.permission_denied'

# ...existing code...
17 changes: 17 additions & 0 deletions templates/403.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "base_site.html" %}
{% load i18n %}

{% block title %}403 - {{ block.super }}{% endblock %}

{% block content %}
<section>
<div class="row">
<div class="col-md-12" style="margin-top: 20px">
<div class="alert alert-danger">
<h4>{% trans "Access Denied" %}</h4>
<p>{% trans "You are not authorized to view this page." %}</p>
</div>
</div>
</div>
</section>
{% endblock %}