Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Empty file added pythonpro/cohorts/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions pythonpro/cohorts/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin

from pythonpro.cohorts.models import Cohort


@admin.register(Cohort)
class ModuleAdmin(admin.ModelAdmin):
list_display = 'title start end'.split()
ordering = ('-start',)
5 changes: 5 additions & 0 deletions pythonpro/cohorts/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class CohortsConfig(AppConfig):
name = 'pythonpro.cohorts'
11 changes: 11 additions & 0 deletions pythonpro/cohorts/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pythonpro.cohorts.facade import get_all_cohorts_desc


def global_settings(request):
# return any necessary values
if not request.user.is_authenticated:
return {}

return {
'ALL_COHORTS': get_all_cohorts_desc(),
}
5 changes: 5 additions & 0 deletions pythonpro/cohorts/facade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pythonpro.cohorts.models import Cohort as _Cohort


def get_all_cohorts_desc():
return tuple(_Cohort.objects.order_by('-start'))
46 changes: 46 additions & 0 deletions pythonpro/cohorts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 2.0.6 on 2018-06-03 23:26

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Cohort',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('slug', models.SlugField()),
('image', models.ImageField(upload_to='cohorts/')),
('quote', models.TextField()),
('mail_list', models.URLField()),
('forum_post', models.URLField()),
('start', models.DateField()),
('end', models.DateField()),
],
),
migrations.CreateModel(
name='CohortStudent',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('cohort', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='cohorts.Cohort')),
(
'user',
models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)
),
],
),
migrations.AddField(
model_name='cohort',
name='students',
field=models.ManyToManyField(through='cohorts.CohortStudent', to=settings.AUTH_USER_MODEL),
),
]
Empty file.
25 changes: 25 additions & 0 deletions pythonpro/cohorts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.contrib.auth import get_user_model
from django.db import models

# Create your models here.
from django.urls import reverse


class Cohort(models.Model):
title = models.CharField(max_length=50)
slug = models.SlugField()
image = models.ImageField(upload_to='cohorts/')
quote = models.TextField()
mail_list = models.URLField()
forum_post = models.URLField()
start = models.DateField()
end = models.DateField()
students = models.ManyToManyField(get_user_model(), through='CohortStudent')

def get_absolute_url(self):
return reverse('cohorts:detail', kwargs={'slug': self.slug})


class CohortStudent(models.Model):
cohort = models.ForeignKey(Cohort, on_delete=models.DO_NOTHING)
user = models.ForeignKey(get_user_model(), on_delete=models.DO_NOTHING)
45 changes: 45 additions & 0 deletions pythonpro/cohorts/templates/cohorts/cohort_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends 'core/base.html' %}
{% load static %}

{% block title %}Turma {{ cohort.title }}{% endblock %}

{% block body %}
<div class="container">
<div class="row">
<div class="col">
<h1 class="mt-4 mb-3">Turma {{ cohort.title }}</h1>
<img src="{{ cohort.image.url }}" class="rounded float-left mr-3" alt="Foto de {{ cohort.title }}"
width="300px" height="300px">
<blockquote class="blockquote">
<p class="mb-0">"{{ cohort.quote }}"</p>
<footer class="blockquote-footer">{{ cohort.title }}
</footer>
</blockquote>
<dt>
Inicio:
</dt>
<dd>
{{ cohort.start }}
</dd>
<dt>
Fim:
</dt>
<dd>
{{ cohort.end }}
</dd>

</div>
</div>
<div class="row">
<div class="col">
<h2 class="mt-5">Intruções</h2>
<dt>Passo 1</dt>
<dd>Cadastre-se na <a href="{{ cohort.mail_list }}" target="_blank">lista de emails da turma</a></dd>
<dt>Passo 2</dt>
<dd>Se apresente no <a href="{{ cohort.forum_post }}" target="_blank">post do fórum</a></dd>
<dt>Passo 3</dt>
<dd>Entre no nosso <a href="https://t.me/joinchat/DZ2HMkC_wRSHCm5YwIM1UQ" target="_blank">grupo do Telegram</a> para tirar dúvidas e interagir!</dd>
</div>
</div>
</div>
{% endblock body %}
71 changes: 71 additions & 0 deletions pythonpro/cohorts/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from os import path

import pytest
from django.core.files.uploadedfile import SimpleUploadedFile
from django.template.defaultfilters import date
from django.urls import reverse
from model_mommy import mommy

from pythonpro import settings
from pythonpro.cohorts.models import Cohort
from pythonpro.django_assertions import dj_assert_contains, dj_assert_not_contains

_img_path = path.join(settings.BASE_DIR, 'pythonpro', 'core', 'static', 'img', 'instructors', 'renzo-nuccitelli.png')


@pytest.fixture
def cohort(client, django_user_model):
user = mommy.make(django_user_model)
client.force_login(user)
image = SimpleUploadedFile(name='renzo-nuccitelli.png', content=open(_img_path, 'rb').read(),
content_type='image/png')
cohort = mommy.make(Cohort, slug='guido-van-rossum', students=[user], image=image)
return cohort


@pytest.fixture
def resp(client, cohort):
resp = client.get(reverse('cohorts:detail', kwargs={'slug': cohort.slug}), secure=True)
return resp


def test_cohort_links_for_logged_user(client, django_user_model):
user = mommy.make(django_user_model)
client.force_login(user)
image = SimpleUploadedFile(name='renzo-nuccitelli.png', content=open(_img_path, 'rb').read(),
content_type='image/png')
cohorts = mommy.make(Cohort, 4, image=image)
resp = client.get('/', secure=True)
for c in cohorts:
dj_assert_contains(resp, c.get_absolute_url())


@pytest.mark.django_db
def test_cohort_links_not_avaliable_for_no_user(client):
image = SimpleUploadedFile(name='renzo-nuccitelli.png', content=open(_img_path, 'rb').read(),
content_type='image/png')
cohorts = mommy.make(Cohort, 4, image=image)
resp = client.get('/', secure=True)
for c in cohorts:
dj_assert_not_contains(resp, c.get_absolute_url())


def test_status_code(resp):
assert 200 == resp.status_code


@pytest.mark.parametrize('property_name', 'title mail_list forum_post'.split())
def test_cohort_propeties(cohort, resp, property_name):
dj_assert_contains(resp, getattr(cohort, property_name))


def test_cohort_img(cohort: Cohort, resp):
dj_assert_contains(resp, cohort.image.url)


def test_cohort_start(cohort: Cohort, resp):
dj_assert_contains(resp, date(cohort.start))


def test_cohort_end(cohort: Cohort, resp):
dj_assert_contains(resp, date(cohort.end))
8 changes: 8 additions & 0 deletions pythonpro/cohorts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path

from pythonpro.cohorts import views

app_name = 'cohorts'
urlpatterns = [
path('<slug:slug>/', views.detail, name='detail'),
]
8 changes: 8 additions & 0 deletions pythonpro/cohorts/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.shortcuts import render

# Create your views here.
from pythonpro.cohorts.models import Cohort


def detail(request, slug):
return render(request, 'cohorts/cohort_detail.html', {'cohort': Cohort.objects.get(slug=slug)})
18 changes: 18 additions & 0 deletions pythonpro/core/migrations/0005_auto_20180603_2026.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.6 on 2018-06-03 23:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0004_auto_20180601_1108'),
]

operations = [
migrations.AlterField(
model_name='user',
name='first_name',
field=models.CharField(max_length=30, verbose_name='first name'),
),
]
3 changes: 1 addition & 2 deletions pythonpro/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def get_full_name(self):
"""
Return the first_name plus the last_name, with a space in between.
"""
full_name = '%s %s' % (self.first_name, self.last_name)
return full_name.strip()
return self.get_short_name()

def get_short_name(self):
"""Return the short name for the user."""
Expand Down
17 changes: 16 additions & 1 deletion pythonpro/core/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script type="application/javascript" src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
<link href='//fonts.googleapis.com/css?family=Ubuntu:400,500' rel='stylesheet' type='text/css'/>
</head>
<body>
<body >
<nav class="navbar navbar-dark bg-dark navbar-expand-md">
<a class="navbar-brand" href="/">Python Pro</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
Expand All @@ -22,6 +22,21 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
{% if user.is_authenticated %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarCohorts" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Turmas
</a>
<div class="dropdown-menu bg-dark border-light" aria-labelledby="navbarCohorts">
{% for cohort in ALL_COHORTS %}
<a class="dropdown-item text-light"
href="{{ cohort.get_absolute_url }}">{{ cohort.title }}</a>
{% if not forloop.last %}
<div class="dropdown-divider"></div>
{% endif %}
{% endfor %}
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarCourses" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Expand Down
4 changes: 3 additions & 1 deletion pythonpro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
'pythonpro.modules',
'pythonpro.promos',
'pythonpro.payments',
'pythonpro.cohorts',
'ordered_model',
'django.contrib.admin',
'django.contrib.auth',
Expand Down Expand Up @@ -96,6 +97,7 @@
'django.contrib.messages.context_processors.messages',
'pythonpro.core.context_processors.global_settings',
'pythonpro.modules.context_processors.global_settings',
'pythonpro.cohorts.context_processors.global_settings',
'pythonpro.payments.context_processors.global_settings',
],
},
Expand Down Expand Up @@ -145,7 +147,7 @@
USE_TZ = True

# Configuration for dev environment
MEDIA_URL = f'/media/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Expand Down
2 changes: 1 addition & 1 deletion pythonpro/tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_urls_len():
assert 15 == len(urlpatterns)
assert 17 == len(urlpatterns)
14 changes: 11 additions & 3 deletions pythonpro/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.auth.views import LoginView, LogoutView, PasswordResetView, PasswordResetConfirmView, \
PasswordResetDoneView, PasswordResetCompleteView
from django.urls import path, include
from django.contrib.auth.views import (
LoginView, LogoutView, PasswordResetCompleteView, PasswordResetConfirmView, PasswordResetDoneView,
PasswordResetView
)
from django.urls import include, path

urlpatterns = [
path('admin/', admin.site.urls),
Expand All @@ -33,6 +37,10 @@
path('capitulos/', include('pythonpro.modules.chapters_urls')),
path('topicos/', include('pythonpro.modules.topics_urls')),
path('pagamento/', include('pythonpro.payments.urls')),
path('turmas/', include('pythonpro.cohorts.urls')),
path('', include('pythonpro.core.urls')),

]

if not settings.AWS_ACCESS_KEY_ID:
urlpatterns.extend(static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT))
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Faker==0.8.15
flake8==3.5.0
mccabe==0.6.1
py==1.5.3
pycodestyle==2.4.0
pycodestyle==2.3.1
pyflakes==2.0.0
pytest==3.6.0
pytest-cov==2.5.1
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ psycopg2==2.7.4
python-decouple==3.1
raven==6.9.0

pillow==5.1.0

#Amazon S3 Stuff
boto3==1.7.31
Collectfast==0.6.2
Expand Down