Skip to content

Commit 3f6dc37

Browse files
authored
Merge pull request #48 from moscowpython/tech/hello_ci
Tech/hello ci
2 parents 3b8b6e7 + 7210244 commit 3f6dc37

File tree

9 files changed

+105
-25
lines changed

9 files changed

+105
-25
lines changed

.github/workflows/pr.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: [ master ]
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-python@v3
13+
with:
14+
python-version: "3.8"
15+
- name: Install requirements
16+
run: pip install -r requirements-dev.txt
17+
- name: Run lint
18+
run: make check

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
isort:
2+
isort .
3+
style:
4+
flake8 .
5+
types:
6+
mypy .
7+
test:
8+
cd landing_page; pytest .
9+
check:
10+
make isort style types test

landing_page/mainpage/admin.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
from django.contrib import admin
22

33
from .models import (
4-
MoscowPythonMeetup, LearnPythonCourse, Curators, Feedback, GraduateProjects, GraduateStories,
5-
LearnPythonCoursePrices, GraduateProjectsVideos, Podcasts, LearnPythonMultiCityCourses
4+
Curators,
5+
Feedback,
6+
GraduateProjects,
7+
GraduateProjectsVideos,
8+
GraduateStories,
9+
LearnPythonCourse,
10+
LearnPythonCoursePrices,
11+
LearnPythonMultiCityCourses,
12+
MoscowPythonMeetup,
13+
Podcasts,
614
)
715

816
admin.site.register(MoscowPythonMeetup)
@@ -14,4 +22,4 @@
1422
admin.site.register(LearnPythonCoursePrices)
1523
admin.site.register(GraduateProjectsVideos)
1624
admin.site.register(Podcasts)
17-
admin.site.register(LearnPythonMultiCityCourses)
25+
admin.site.register(LearnPythonMultiCityCourses)

landing_page/mainpage/models.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
from django.db import models
1+
import datetime
22
from datetime import date, timedelta
33

4+
from django.db import models
5+
46

57
class MoscowPythonMeetup(models.Model):
68
class Meta:
79
verbose_name_plural = "MoscowPython Митапы"
810

9-
def __str__(self):
11+
def __str__(self) -> str:
1012
return f'MoscowPython Meetup № {self.meetup_number}'
1113

1214
meetup_number = models.IntegerField(
@@ -30,7 +32,7 @@ class LearnPythonCourse(models.Model):
3032
class Meta:
3133
verbose_name_plural = "LearnPython Наборы"
3234

33-
def __str__(self):
35+
def __str__(self) -> str:
3436
return f'LearnPython Набор № {self.course_index}'
3537

3638
course_index = models.IntegerField(
@@ -162,18 +164,18 @@ def __str__(self):
162164
default=False,
163165
)
164166

165-
def get_date_after_first_lesson(self):
167+
def get_date_after_first_lesson(self) -> datetime.date:
166168
return self.course_start_date + timedelta(days=1)
167169

168-
def get_day_before_last_lesson(self):
170+
def get_day_before_last_lesson(self) -> datetime.date:
169171
return self.course_end_date - timedelta(days=1)
170172

171173

172174
class LearnPythonCoursePrices(models.Model):
173175
class Meta:
174176
verbose_name_plural = 'LearnPython Цены на курсы'
175177

176-
def __str__(self):
178+
def __str__(self) -> str:
177179
return f'Интервал {self.price_range} на {self.course_type}'
178180

179181
price_range = models.IntegerField(
@@ -215,18 +217,19 @@ def __str__(self):
215217
)
216218

217219
@property
218-
def within_price_range(self):
220+
def within_price_range(self) -> bool:
219221
return self.price_range_start_date <= date.today() <= self.price_range_end_date
220222

221223
@property
222-
def past_due_date(self):
224+
def past_due_date(self) -> bool:
223225
return date.today() > self.price_range_end_date
224226

227+
225228
class LearnPythonMultiCityCourses(models.Model):
226229
class Meta:
227230
verbose_name_plural = 'LearnPython Цены на курсы в разных городах'
228231

229-
def __str__(self):
232+
def __str__(self) -> str:
230233
return f'Курсы в городе {self.city_name}'
231234

232235
city_name = models.CharField(
@@ -286,7 +289,7 @@ class Curators(models.Model):
286289
class Meta:
287290
verbose_name_plural = 'LearnPython Кураторы'
288291

289-
def __str__(self):
292+
def __str__(self) -> str:
290293
return f'Куратор {self.curator_name}'
291294

292295
curator_name = models.CharField(
@@ -338,7 +341,7 @@ class Feedback(models.Model):
338341
class Meta:
339342
verbose_name_plural = "LearnPython Отзывы"
340343

341-
def __str__(self):
344+
def __str__(self) -> str:
342345
return f'Отзыв участника {self.feedback_author}'
343346

344347
feedback_author = models.CharField(
@@ -387,7 +390,7 @@ class GraduateStories(models.Model):
387390
class Meta:
388391
verbose_name_plural = 'Learn Python Истории учеников'
389392

390-
def __str__(self):
393+
def __str__(self) -> str:
391394
return f'История участника {self.story_author}'
392395

393396
story_author = models.CharField(
@@ -459,7 +462,7 @@ class GraduateProjects(models.Model):
459462
class Meta:
460463
verbose_name_plural = 'LearnPython Проекты Учеников'
461464

462-
def __str__(self):
465+
def __str__(self) -> str:
463466
return f'Проект "{self.project_name}"'
464467

465468
project_name = models.CharField(
@@ -481,7 +484,7 @@ class GraduateProjectsVideos(models.Model):
481484
class Meta:
482485
verbose_name_plural = 'LearnPython Видео проектов Учеников'
483486

484-
def __str__(self):
487+
def __str__(self) -> str:
485488
return f'Проект "{self.project_name}"'
486489

487490
project_name = models.CharField(
@@ -517,7 +520,7 @@ class Podcasts(models.Model):
517520
class Meta:
518521
verbose_name_plural = 'LearnPython Подкаст с учеником'
519522

520-
def __str__(self):
523+
def __str__(self) -> str:
521524
return f'Проект "{self.podcast_name}"'
522525

523526
podcast_name = models.CharField(

landing_page/mainpage/views.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import dataclasses
22
import datetime
3+
from datetime import date
34
from typing import Optional
45

5-
from django.http import HttpResponse
6+
from django.http import HttpRequest, HttpResponse
67
from django.template import loader
7-
from .models import (LearnPythonCourse, GraduateProjects,
8-
Feedback, Curators, GraduateProjectsVideos
9-
)
10-
from datetime import date
8+
9+
from .models import Curators, Feedback, GraduateProjects, GraduateProjectsVideos, LearnPythonCourse
1110

1211

1312
@dataclasses.dataclass
@@ -27,7 +26,7 @@ class Enrollment:
2726
late_price: CoursePrice
2827

2928

30-
def index(request):
29+
def index(request: HttpRequest) -> HttpResponse:
3130
template = loader.get_template('mainpage/index.html')
3231

3332
enrollment = Enrollment(
@@ -65,7 +64,7 @@ def index(request):
6564
return HttpResponse(template.render(context, request))
6665

6766

68-
def projects(request):
67+
def projects(request: HttpRequest) -> HttpResponse:
6968
template = loader.get_template('mainpage/projects.html')
7069

7170
try:

landing_page/tests/__init__.py

Whitespace-only changes.

landing_page/tests/test_index.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pytest
2+
from django.test import Client
3+
4+
5+
@pytest.mark.django_db
6+
def test__index__shows_up(client: Client) -> None:
7+
response = client.get('/')
8+
assert response.status_code == 200

requirements-dev.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-r requirements.txt
2+
flake8==6.1.0
3+
mypy==1.5.0
4+
isort==5.12.0
5+
pytest==7.4.0
6+
pytest-django==4.5.2

setup.cfg

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[flake8]
2+
exclude = migrations
3+
max-line-length = 120
4+
5+
6+
[mypy]
7+
ignore_missing_imports = True
8+
disallow_incomplete_defs = True
9+
no_implicit_optional = True
10+
disallow_untyped_calls = True
11+
warn_redundant_casts = True
12+
warn_unused_ignores = True
13+
disallow_untyped_defs = True
14+
check_untyped_defs = True
15+
exclude = migrations
16+
17+
[isort]
18+
combine_as_imports = true
19+
default_section = THIRDPARTY
20+
include_trailing_comma = true
21+
use_parentheses = true
22+
known_first_party = learn_bot
23+
line_length = 120
24+
multi_line_output = 3
25+
26+
27+
[tool:pytest]
28+
DJANGO_SETTINGS_MODULE = landing_page.settings

0 commit comments

Comments
 (0)