-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 119729a
Showing
26 changed files
with
506 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
.venv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# PyCharm stuff | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Entity - Course (start date, description, Tutor), | ||
- Webinar (date, description, Tutor) | ||
|
||
Users - Admin, Tutor (isTutor=True), Student (isTutor=False) -> custom User model (of models.Model) | ||
|
||
Views - CourseListView, WebinarListView | ||
- TutorView (list of courses Tutor assigned to, list of students and their progress), | ||
- StudentView (list of courses paid by Student and with access to, list of upcoming webinars) | ||
|
||
|
||
API access - read for all, write for admin only (could be logged in to /admin/ if API opened in browser) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
|
||
from . import models | ||
|
||
admin.site.register(models.Tag) | ||
admin.site.register(models.Course) | ||
admin.site.register(models.Webinar) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CatalogConfig(AppConfig): | ||
name = 'catalog' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Generated by Django 2.0.4 on 2018-04-22 20:43 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Course', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=200)), | ||
('description', models.TextField()), | ||
('start_date', models.DateField()), | ||
('duration', models.DurationField()), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Tag', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=50)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Webinar', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=200)), | ||
('description', models.TextField()), | ||
('scheduled_time', models.DateTimeField()), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='course', | ||
name='tags', | ||
field=models.ManyToManyField(blank=True, to='catalog.Tag'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 2.0.4 on 2018-04-22 20:43 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('catalog', '0001_initial'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='course', | ||
name='user', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='courses', to=settings.AUTH_USER_MODEL), | ||
), | ||
migrations.AddField( | ||
model_name='course', | ||
name='webinars', | ||
field=models.ManyToManyField(blank=True, to='catalog.Webinar'), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from django.db import models | ||
from otus_site import settings | ||
|
||
|
||
class Tag(models.Model): | ||
title = models.CharField(max_length=50) | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
|
||
class Course(models.Model): | ||
user = models.ForeignKey( | ||
settings.Base.AUTH_USER_MODEL, | ||
related_name='courses', | ||
on_delete=models.CASCADE) | ||
title = models.CharField(max_length=200) | ||
description = models.TextField() | ||
start_date = models.DateField() | ||
duration = models.DurationField() | ||
|
||
tags = models.ManyToManyField('Tag', blank=True) | ||
webinars = models.ManyToManyField('Webinar', blank=True) | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
|
||
class Webinar(models.Model): | ||
title = models.CharField(max_length=200) | ||
description = models.TextField() | ||
scheduled_time = models.DateTimeField() | ||
|
||
def __str__(self): | ||
return self.title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from rest_framework import serializers | ||
from . import models | ||
|
||
|
||
class TagSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = models.Tag | ||
fields = ('id', 'title') | ||
|
||
|
||
class CourseSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = models.Course | ||
fields = ('id', 'user', 'title', 'description', | ||
'start_date', 'duration', 'tags', 'webinars') | ||
|
||
|
||
class WebinarSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = models.Webinar | ||
fields = ('id', 'title', 'description', 'scheduled_time') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.conf.urls import include, url | ||
from rest_framework import routers | ||
|
||
from . import views | ||
|
||
router = routers.DefaultRouter() | ||
router.register(r'tags', views.TagViewSet) | ||
router.register(r'courses', views.CourseViewSet) | ||
router.register(r'webinars', views.WebinarViewSet) | ||
|
||
app_name = 'catalog' | ||
urlpatterns = [ | ||
url(r'^', include(router.urls)) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.shortcuts import render | ||
|
||
from rest_framework import viewsets | ||
from otus_site import permissions | ||
|
||
from . import models, serializers | ||
|
||
|
||
class TagViewSet(viewsets.ModelViewSet): | ||
queryset = models.Tag.objects.all() | ||
serializer_class = serializers.TagSerializer | ||
permission_classes = [permissions.IsAccountAdminOrReadOnly, ] | ||
|
||
|
||
class CourseViewSet(viewsets.ModelViewSet): | ||
queryset = models.Course.objects.all() | ||
serializer_class = serializers.CourseSerializer | ||
permission_classes = [permissions.IsAccountAdminOrReadOnly, ] | ||
|
||
|
||
class WebinarViewSet(viewsets.ModelViewSet): | ||
queryset = models.Webinar.objects.all() | ||
serializer_class = serializers.WebinarSerializer | ||
permission_classes = [permissions.IsAccountAdminOrReadOnly, ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'otus_site.settings') | ||
os.environ.setdefault('DJANGO_CONFIGURATION', 'Dev') | ||
|
||
from configurations.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from rest_framework import permissions | ||
|
||
|
||
class IsAccountAdminOrReadOnly(permissions.BasePermission): | ||
""" | ||
Read-only requests are allowed for any users (both authorized and anonymous). | ||
Write/Delete requests are allowed only to authorized Admin. | ||
""" | ||
|
||
def has_permission(self, request, view): | ||
return ( | ||
request.method in permissions.SAFE_METHODS or | ||
request.user and | ||
request.user.is_staff | ||
) |
Oops, something went wrong.