Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/django-3.2.20
Browse files Browse the repository at this point in the history
  • Loading branch information
eduzen authored Jan 20, 2025
2 parents 7d7e6da + 83032be commit 97d9437
Show file tree
Hide file tree
Showing 112 changed files with 786 additions and 1,415 deletions.
31 changes: 24 additions & 7 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,50 @@ jobs:
matrix:
python-version: [3.9]
env:
DJANGO: 3.0
DJANGO: 3.0
SECRET_KEY: supersecret
DB_PORT: 5432
DB_PORT: 5432
POSTGRES_HOST: localhost
POSTGRES_PASSWORD: somepassword
POSTGRES_USER: postgres
POSTGRES_DB: testing_db
DJANGO_SETTINGS_MODULE: pyarweb.settings.development
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install system libraries
run: |
sudo apt-get install -y libpq-dev libxml2-dev libxslt1-dev
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/dev_requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r dev_requirements.txt
- name: Lint with flake8
- name: Check Code Style
uses: pre-commit/action@v3.0.1

- name: Check for Django migrations
run: |
flake8
python manage.py makemigrations --dry-run --check
- name: Run migrations
run: |
python manage.py migrate
python manage.py migrate
- name: Run tests
run: |
pytest -v
6 changes: 3 additions & 3 deletions .github/workflows/upload_to_dockerhub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ jobs:
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: my-docker-hub-namespace/my-docker-hub-repository

- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
Expand Down
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: check-merge-conflict
- id: debug-statements

- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
args:
- '--config=.flake8'
- '--exclude=.venv,**/migrations/*.py'

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py39-plus]

- repo: https://github.com/adamchainz/django-upgrade
rev: "1.22.2"
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM python:3.9
ENV PYTHONUNBUFFERED 1
ENV PYTHONPATH /code:$PYTHONPATH
RUN apt-get update && apt-get -y install flite=2.2-5
RUN mkdir /code
WORKDIR /code
COPY dev_requirements.txt /code
Expand Down
2 changes: 1 addition & 1 deletion INSTALLATION.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Guia de instalación
## Guia de instalación

Seguí los pasos en nuestra wiki: https://github.com/PyAr/pyarweb/wiki/Instalacion-con-Docker
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ only_test:
pep8:
docker-compose run --rm web flake8

format:
pre-commit run -a

test: pep8 only_test

dockershell:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ instrucciones generales en [esta página de la wiki](https://github.com/PyAr/pya

podés ver las instrucciones en [esta página de la wiki](https://github.com/PyAr/pyarweb/wiki/Instalacion-con-Docker)

## Lint & Format

Para correr el linter y el formateador de código, podés correr:

```bash
make format
```

## Más info

Expand Down
6 changes: 3 additions & 3 deletions community/templates/_tags_filtering_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</div>
<div class="ma-5" style="margin-top:15px;">
<label>
<input name="active" type="hidden" value="{{ active|yesno:'false,true' }}">
<input id="show-active" type="checkbox" {% if not active %}checked{% endif %} />
<input name="active" type="hidden" value="{{ active|yesno:'true,false' }}">
<input id="show-active" type="checkbox" {% if active %}checked{% endif %} />
{% trans 'Mostrar solo ofertas activas' %}
</label>
</div>
Expand All @@ -25,7 +25,7 @@ <h4 class="list-group-item-heading">{% trans 'Filtrar por etiqueta' %} <button t
</header>
<article class="list-group-item" style="padding:30px;">
<div class="row">
{% for tag in tags %}
{% for tag in usefultags %}
<select name="tag_{{ tag.slug }}" id="tag_{{ tag.slug }}" class="hidden">
<option value=""></option>
<option value="1" {% if tag.slug in included %}selected{% endif %}></option>
Expand Down
23 changes: 23 additions & 0 deletions community/templates/account/custom_captcha.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% load i18n %}
{% spaceless %}
<div class="form-group">
<label class="control-label">{{ label }}</label>
<div class="form-group">
<div class="input-group mb-3">
<div class="input-group-prepend">
<img src="{{ image }}" alt="captcha" class="captcha" />
{% if audio %}
<audio
title="{% trans "Play CAPTCHA as audio file" %}"
src="{{ audio }}"
alt="captcha audio"
controls
style="display: block; padding-bottom: 1rem;"
>
{% endif %}
</div>
{% include "django/forms/widgets/multiwidget.html" %}
</div>
</div>
</div>
{% endspaceless %}
8 changes: 4 additions & 4 deletions community/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<link rel="icon" href="{% static 'img/icons/pyar.ico' %}" type="image/ico">

{% block extra_head %}{% endblock %}

{% if GOOGLE_TRACKING_ID %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-169755710-1"></script>
Expand All @@ -48,9 +48,9 @@
background-image: url({% static "img/pyar-footer.png" %});
}

#footer li.usla {
background-image: url({% static "img/usla-footer.png" %});
padding-right: 80px;
#footer li.azure {
background-image: url({% static "img/azure-footer.png" %});
padding-right: 50px;
}

#footer li.python {
Expand Down
2 changes: 1 addition & 1 deletion community/templates/confirm_delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2>{% block page_title %}{% endblock %}</h2>
<form action="" method="POST">{% csrf_token %}
<p>{% blocktrans %}¿Está seguro de que desear eliminar "{{ object }}"?{% endblocktrans %}</p>
<input class="btn btn-primary" type="submit" value="{% trans 'Confirmar' %}" />
<a href="{% block return_url %}{% endblock %}" class="btn btn-default">{% trans 'Cancelar' %}</a>
<a href="{% block return_url %}{% endblock %}" class="btn btn-default">{% trans 'Cancelar' %}</a>
</form>
</div>
</main>
Expand Down
2 changes: 1 addition & 1 deletion community/templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
<div class="col-xs-6">
<ul class="list-inline right">
<li class="usla"><a href="http://drupal.usla.org.ar/">Sitio hosteado por USLA<br>Usuarios de Software libre de Argentina</a></li>
<li class="azure"><a href="https://azure.microsoft.com/es-es">Sitio hosteado en Azure<br>por cortesía de Microsoft</a></li>
<li class="python"><a href="https://github.com/PyAr/pyarweb">Python<br>Powered</a></li>
</ul>
</div>
Expand Down
4 changes: 2 additions & 2 deletions community/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
<a href="{% url 'events:events_list_all' %}"><span class="eventos"></span>{% trans 'Eventos' %}</a>
</li>
<li>
<a href="http://planeta.python.org.ar"><span class="pyar"></span>{% trans 'Planeta' %}</a>
<a href="{% url 'joboffers:list' %}"><span class="jobs"></span>{% trans 'Trabajos' %}</a>
</li>
<li>
<a href="{% url 'joboffers:list' %}"><span class="jobs"></span>{% trans 'Trabajos' %}</a>
<a href="https://ac.python.org.ar"><span class="quienes_somos"></span>{% trans 'Asoc. Civil' %}</a>
</li>
</ul>
</nav>
Expand Down
11 changes: 6 additions & 5 deletions community/tests/test_homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

from community.views import HomePageView, RECENT_ITEMS_LEN
from events.tests.factories import EventFactory
from jobs.tests.factories import JobFactory
from joboffers.models import OfferState
from joboffers.tests.factories import JobOfferFactory
from news.tests.factories import NewsArticleFactory


Expand All @@ -32,11 +33,11 @@ def test_included_events_have_correct_fields(self):
# Events already have a description field

def test_jobs_are_included_in_recent(self):
job = JobFactory()
job = JobOfferFactory(state=OfferState.ACTIVE)
self.assertEqual([job], self.get_context_data()['recent'])

def test_included_jobs_have_correct_fields(self):
JobFactory()
JobOfferFactory(state=OfferState.ACTIVE)
job = self.get_context_data()['recent'][0]
self.assertEqual(job.category, 'Trabajos')
# jobs already have 'created', 'title' and 'description' fields
Expand All @@ -55,7 +56,7 @@ def test_included_news_have_correct_fields(self):

# Independent of the Model type, all list items are sorted by their 'created' field
def test_items_are_sorted_by_the_created_field(self):
job = JobFactory(set_created='1985-10-26 09:00Z') # Middle-age ;-)
job = JobOfferFactory(state=OfferState.ACTIVE, set_created='1985-10-26 09:00Z') # Middle
event = EventFactory(start_at='1955-11-12 06:38Z') # Oldest
article = NewsArticleFactory(set_created='2015-10-21 09:00Z') # Most recent
# Assert the models are in chronological order
Expand All @@ -64,7 +65,7 @@ def test_items_are_sorted_by_the_created_field(self):
def test_recent_is_a_list_with_at_most_10_items(self):
# Create more than RECENT_ITEMS_LEN models and assert that only 10 are kept as recent
for i in range(RECENT_ITEMS_LEN):
JobFactory()
JobOfferFactory(state=OfferState.ACTIVE)
EventFactory()
NewsArticleFactory()
# The loop above creates RECENT_ITEMS_LEN * 3 items
Expand Down
7 changes: 3 additions & 4 deletions community/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-

from django.conf.urls import patterns, url
from django.urls import re_path
from django.conf.urls import patterns


urlpatterns = patterns(
'',
url(r'^', 'community.views.homepage', name='homepage'),
re_path(r'^', 'community.views.homepage', name='homepage'),
)
29 changes: 14 additions & 15 deletions community/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


"""Handle the Views of the Homepage and others."""

from django.db.models import F, Value, CharField
Expand All @@ -10,7 +7,7 @@
from django.views.generic.list import MultipleObjectMixin
from django.utils.timezone import now
from events.models import Event
from jobs.models import Job
from joboffers.models import JobOffer, OfferState
from news.models import NewsArticle

RECENT_ITEMS_LEN = 10
Expand All @@ -26,23 +23,25 @@ class HomePageView(TemplateView):
template_name = "community/index.html"

def get_events_for_context(self):
"""Ensure events have 'category', created' and 'title' fields"""
"""Get events annotated for proper usage."""
events = Event.objects.filter(start_at__lt=now())
events = events.order_by('-start_at')
events = events.annotate(
created=F('start_at'),
title=F('name'),
category=Value('Eventos', output_field=CharField()))
return aux_qs_to_list_for_context(events)

def get_jobs_for_context(self):
"""Ensure jobs have a 'category' field"""
jobs = Job.objects.order_by('-created')
jobs = jobs.annotate(category=Value('Trabajos', output_field=CharField()))
"""Get jobs annotated for proper usage."""
jobs = JobOffer.objects.filter(state=OfferState.ACTIVE)
jobs = jobs.annotate(
category=Value('Trabajos', output_field=CharField()),
created=F('created_at'),
)
return aux_qs_to_list_for_context(jobs)

def get_news_for_context(self):
"""Ensure news have 'category' and 'description' fields"""
"""Get news annotated for proper usage."""
news = NewsArticle.objects.order_by('-created')
news = news.annotate(
description=F('body'),
Expand All @@ -57,7 +56,7 @@ def get_context_data(self, **kwargs):
# Sort the last news, jobs and events to define the definitive 'recent' list
recent = sorted(news + jobs + events, key=lambda r: r.created, reverse=True)

context = super(HomePageView, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['recent'] = recent[:RECENT_ITEMS_LEN]
return context

Expand All @@ -82,7 +81,7 @@ class OwnedObject(SingleObjectMixin):
before allowing manipulation. """

def get_object(self, *args, **kwargs):
obj = super(OwnedObject, self).get_object(*args, **kwargs)
obj = super().get_object(*args, **kwargs)
return validate_obj_owner(obj, self.request.user)


Expand All @@ -100,7 +99,7 @@ def dispatch(self, request, *args, **kwargs):
self.included_tags.append(k[4:])
elif v == '2':
self.excluded_tags.append(k[4:])
return super(FilterableList, self).dispatch(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)

def filter_queryset_tags(self, obj_list):
included = self.included_tags
Expand All @@ -112,10 +111,10 @@ def filter_queryset_tags(self, obj_list):
return obj_list

def get_queryset(self):
return self.filter_queryset_tags(super(FilterableList, self).get_queryset())
return self.filter_queryset_tags(super().get_queryset())

def get_context_data(self, **kwargs):
context = super(FilterableList, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['tags'] = self.model.tags.all()
context['included'] = self.included_tags
context['excluded'] = self.excluded_tags
Expand Down
3 changes: 2 additions & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ factory-boy==3.2.1
requests-mock==1.9.3
ipython==8.10.0
ipdb==0.13.9
flake8==4.0.1
flake8==4.0.1
pre-commit==4.0.1
Loading

0 comments on commit 97d9437

Please sign in to comment.