Skip to content

Commit

Permalink
Fix bug where selecting 'Remote' work type incorrectly sets 'Allows r…
Browse files Browse the repository at this point in the history
…emote work' to NO (issue #589) (#591)

* Add help text and fix URL validation to prepend https:// if missing

* Fix remote work issue (#589): Set 'allows remote work' flag to Yes when 'Remote' is selected
  • Loading branch information
JigyasuRajput authored Dec 24, 2024
1 parent 605e3f8 commit d00442a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions joboffers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ def save(self, *args, **kwargs):

super().save(*args, **kwargs)

@property
def allows_remote_work(self):
return self.remoteness == Remoteness.REMOTE

@classmethod
def get_options(cls):
"""
Expand Down
2 changes: 1 addition & 1 deletion joboffers/templates/joboffers/joboffer_overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h4 class="mt-0">
</dd>
{% endif %}
<dt>Permite trabajar remoto</dt>
<dd>{% if obj.remote_work %}Si{% else %}No{% endif %}</dd>
<dd>{% if obj.allows_remote_work %}{% else %}No{% endif %}</dd>

<dt>Experiencia Requerida</dt>
<dd>{{ obj.get_experience_display }}</dd>
Expand Down
10 changes: 10 additions & 0 deletions pycompanies/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Expand All @@ -12,6 +13,9 @@ 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,6 +32,12 @@ 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
Expand Down

0 comments on commit d00442a

Please sign in to comment.