Skip to content

Commit

Permalink
new release (#427)
Browse files Browse the repository at this point in the history
* add flake8 to tests.

* pep8 police

* move flake8 config to .flake8

* fix pep8 args

* add python3.5 and 3.6 to travis-ci

* speed up tests

* Add a general word-wrap style rule

* Use docker image from dockerhub. Makefile with command alias

* Adds gender field to EventRegistration model

* Adds migration related to new gender field

* Adds gender field to corresponding forms

* Show the gender in registered list and CSV.

* fix pep8

* Change the homepage context

* Replaces Ultimas Noticias and Últmos Trabajos with a new section

* Refactor the homepage as a class-based view

* Added factories for testing

* Added tests for the new homepage

* Sanitize html inputs on Events and Jobs (#412)

* fix autosuggest js on jobs form

* refs #409 #410 add html_sanitizer to description field of Job and Event

* refs #409 410 add tests to Job and Event views

* remove duplicate requeriment

* adjust code to pycodestyle

* fix wrong exception class

* Update job_form.html

* added normalize_tags function on job utils (#418)

* 407 migration to fix tags (#419)

* Arreglo error de linter

* Added new makemigrations shortcut

* added missing migration

* Adds a migration to clean the tags

* split function to use ir

* Use tag normalization function in migration

* #346 autoslug (#420)

* added autoslug fields to events

* fixed url position

* Fixed migrations (#423)

* Resolviendo issue #383 (#425)

* Resolviendo issue #383

Agregue el EMAIL_CONFIRMATION_LA_DOMAIN con el valor "python.org.ar". Probado en un servidor debug funciona correctamente el link.

* arreglando error de flake8

* 417 sponsored jobs (#424)

* Added rank for pycompanies, updated joblist view with sponsored jobs, added ac.civil badget to pycompanies

* Changes after code review

* moved css styles and other html stuff

* Fixed typo and added one test with rank==0
  • Loading branch information
gilgamezh authored Jun 2, 2018
1 parent d904197 commit 3bfb12c
Show file tree
Hide file tree
Showing 46 changed files with 846 additions and 97 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length=99
exclude=migrations, .git, build.sh
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sudo: false

python:
- "3.4"
- "3.5"
- "3.6"

service:
- postgresql
Expand All @@ -15,7 +17,9 @@ env:
- DJANGO=1.8 SECRET_KEY=supersecret DB_PORT=5432 DB_SERVICE=localhost DB_PASS="" DB_USER=postgres DB_NAME=postgres

install:
- pip install pip -U
- pip install -r dev_requirements.txt

script:
- python manage.py test
- flake8
- python3 manage.py test -v2 --noinput
44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
help:
@echo "help -- print this help"
@echo "start -- start docker stack"
@echo "stop -- stop docker stack"
@echo "ps -- show status"
@echo "clean -- clean all artifacts"
@echo "test -- run tests using docker"
@echo "dockershell -- run bash inside docker"
@echo "shell_plus -- run django shell_plus inside docker"
@echo "bootstrap --build containers, run django migrations, load fixtures and create the a superuser"

start:
docker-compose up

stop:
docker-compose stop

ps:
docker-compose ps

clean: stop
docker-compose rm --force -v

only_test:
docker-compose run --rm web python3 ./manage.py test -v2 --noinput

pep8:
docker-compose run --rm web flake8

test: pep8 only_test

dockershell:
docker-compose run --rm web /bin/bash

migrations:
docker-compose run --rm web python3 manage.py makemigrations

migrate:
docker-compose run --rm web python3 manage.py migrate

shell_plus:
docker-compose run --rm web python3 manage.py shell_plus

.PHONY: help start stop ps clean test dockershell shell_plus only_test pep8
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ Decenas de personas han colaborado de [diversas maneras](https://github.com/PyAr

## ¿Cómo arranco / instalo el proyecto en mi máquina?

### Vía virtualenv (recomendado)
### Vía virtualenv:

Si querés podés instalar todo el entorno en tu propia maquina, podés ver
instrucciones generales en [esta página de la wiki](https://github.com/PyAr/pyarweb/wiki/Instalaci%C3%B3n-manual)

### Via [Docker](http://docker.com) (No soportada por el momento):
### Via [Docker](http://docker.com):

Estamos trabajando para soportar docker, mientras tanto podés ver las
instrucciones en [esta página de la wiki](https://github.com/PyAr/pyarweb/wiki/Instalacion-con-Docker)
podés ver las instrucciones en [esta página de la wiki](https://github.com/PyAr/pyarweb/wiki/Instalacion-con-Docker)


## Más info
Expand Down
85 changes: 33 additions & 52 deletions community/templates/community/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,59 +60,40 @@ <h3 class="text-center"><a href="/wiki/Proyectos">Proyectos de la comunidad</a><
</div>
</section>

<div class="row" style="margin-top: 20px;">
<div class="col-md-12">

<div class="panel panel-default panel-primary">
<div class="panel-heading"><strong><a class="white" href="{% url 'news_list_all' %}">Últimas noticias</a></strong>
<div class="pull-right">
<span class="badge">
<a href="{% url 'news_feed' %}">
<i class="fa fa-rss"></i> RSS
</a>
</span>
</div>
</div>
<div class="panel-body">
{% for article in news %}
<article class="list-group-item">
<time class="published" datetime="{{ article.created.isoformat }}" itemprop="datePublished" title="{{ "Fecha de publicación" }}">{{ article.created|date:"d/m/Y" }}</time>
<h4 class="list-group-item-heading"><a href="{{ article.get_absolute_url }}">{{ article.title }}</a></h4>
<p class="list-group-item-text">{{ article.introduction|default:article.body|html2text|truncatewords:30 }}</p>
</article>
{% endfor %}
</div>
</div>
</div>

<div class="col-md-12">

<div class="panel panel-default panel-primary">
<div class="panel-heading"><strong><a class="white" href="{% url 'jobs_list_all' %}">Últimos avisos de trabajo publicados</a></strong>

<div class="pull-right">
<span class="badge">
<a href="{% url 'jobs_feed' %}">
<i class="fa fa-rss"></i> RSS
</a>
</span>
</div>


</div>
<div class="panel-body">
{% for job in jobs %}
<article class="list-group-item">
<time class="published" datetime="{{ job.created.isoformat }}" itemprop="datePublished" title="{{ "Fecha de publicación" }}">{{ job.created|date:"d/m/Y" }}</time>
<h4 class="list-group-item-heading"><a href="{{ job.get_absolute_url }}">{{ job.title }}</a></h4>
<p class="list-group-item-text">{{ job.description|html2text|truncatewords:30 }}</p>
</article>
{% endfor %}
</div>
<section>
<div class="row" style="margin-top: 20px;">
<div class="col-md-12">
<div class="panel panel-default panel-primary">
<div class="panel-heading">
<strong>Novedades</strong>
</div>
<div class="panel-body">
{% for article in recent %}
<article class="list-group-item">
<time
class="published"
datetime="{{ article.created.isoformat }}"
itemprop="datePublished"
title="{{ "Fecha de publicación" }}"
>
{{ article.created|date:"d/m/Y" }}
</time>
<small class="text-muted">
- en {{ article.category }}
</small>
<h4 class="list-group-item-heading">
<a href="{{ article.get_absolute_url }}">{{ article.title }}</a>
</h4>
<p class="list-group-item-text">
{{ article.description|html2text|truncatewords:30 }}
</p>
</article>
{% endfor %}
</div>
</div>
</div>
</div>

</div>
</div>
</section>


{# IMPLEMENTAR #}
Expand Down
Empty file added community/tests/__init__.py
Empty file.
71 changes: 71 additions & 0 deletions community/tests/test_homepage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
Tests for the community.views.HomePageView class
"""
from django.test import TestCase

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


class GetContextDataRecentKeyTests(TestCase):
def setUp(self):
# shortcut
self.get_context_data = HomePageView().get_context_data

def test_a_recent_key_is_added_to_the_return_value(self):
self.assertIn('recent', self.get_context_data())

def test_events_are_included_in_recent(self):
event = EventFactory()
self.assertEqual([event], self.get_context_data()['recent'])

def test_included_events_have_correct_fields(self):
# Correct fields include 'category', 'created', 'title' and 'description'
EventFactory()
event = self.get_context_data()['recent'][0]
self.assertEqual(event.category, 'Eventos')
self.assertEqual(event.title, event.name)
self.assertEqual(event.created, event.start_at)
# Events already have a description field

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

def test_included_jobs_have_correct_fields(self):
JobFactory()
job = self.get_context_data()['recent'][0]
self.assertEqual(job.category, 'Trabajos')
# jobs already have 'created', 'title' and 'description' fields

def test_news_are_included_in_recent(self):
article = NewsArticleFactory()
self.assertEqual([article], self.get_context_data()['recent'])

def test_included_news_have_correct_fields(self):
# Correct fields include 'category', 'created', 'title' and 'description'
NewsArticleFactory()
article = self.get_context_data()['recent'][0]
self.assertEqual(article.category, 'Noticias')
self.assertEqual(article.description, article.body)
# NewsArticle already have a created and title fields

# 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 ;-)
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
self.assertListEqual([article, job, event], self.get_context_data()['recent'])

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()
EventFactory()
NewsArticleFactory()
# The loop above creates RECENT_ITEMS_LEN * 3 items
self.assertEqual(len(self.get_context_data()['recent']), RECENT_ITEMS_LEN)
59 changes: 53 additions & 6 deletions community/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,68 @@

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


from django.db.models import F, Value, CharField
from django.http import Http404
from django.shortcuts import render
from django.views.generic.base import TemplateView
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.list import MultipleObjectMixin
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import now
from events.models import Event
from jobs.models import Job
from news.models import NewsArticle

RECENT_ITEMS_LEN = 10


# Auxiliary function for the homepage context
def aux_qs_to_list_for_context(qs):
"""Cast the given QuerySet to a list with at most RECENT_ITEMS_LEN elements"""
return list(qs[:RECENT_ITEMS_LEN])


class HomePageView(TemplateView):
template_name = "community/index.html"

def get_events_for_context(self):
"""Ensure events have 'category', created' and 'title' fields"""
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()))
return aux_qs_to_list_for_context(jobs)

def get_news_for_context(self):
"""Ensure news have 'category' and 'description' fields"""
news = NewsArticle.objects.order_by('-created')
news = news.annotate(
description=F('body'),
category=Value('Noticias', output_field=CharField()))
return aux_qs_to_list_for_context(news)

def get_context_data(self, **kwargs):
"""Add to the template context a list of the most recent events, jobs and news"""
news = self.get_news_for_context()
jobs = self.get_jobs_for_context()
events = self.get_events_for_context()
# 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['recent'] = recent[:RECENT_ITEMS_LEN]
return context


def homepage(request):
news = NewsArticle.objects.order_by('-created')[:3]
jobs = Job.objects.order_by('-created')[:3]
return render(request, 'community/index.html',
{'news': news, 'jobs': jobs})
homepage = HomePageView.as_view()


def learning(request):
Expand Down
3 changes: 2 additions & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-r requirements.txt
factory-boy==2.8.1
ipython==5.3.0
ipdb==0.10.2
ipdb==0.10.2
flake8==3.5.0
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
- POSTGRES_PASSWORD=secret

web:
build: .
image: pyar/pyarweb:dev
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
Expand Down
Loading

0 comments on commit 3bfb12c

Please sign in to comment.