Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
niki4 committed Apr 22, 2018
0 parents commit 119729a
Show file tree
Hide file tree
Showing 26 changed files with 506 additions and 0 deletions.
104 changes: 104 additions & 0 deletions .gitignore
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/
11 changes: 11 additions & 0 deletions AppDesign.md
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 added catalog/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions catalog/admin.py
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)
5 changes: 5 additions & 0 deletions catalog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class CatalogConfig(AppConfig):
name = 'catalog'
45 changes: 45 additions & 0 deletions catalog/migrations/0001_initial.py
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'),
),
]
28 changes: 28 additions & 0 deletions catalog/migrations/0002_auto_20180422_2043.py
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 added catalog/migrations/__init__.py
Empty file.
35 changes: 35 additions & 0 deletions catalog/models.py
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
21 changes: 21 additions & 0 deletions catalog/serializers.py
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')
14 changes: 14 additions & 0 deletions catalog/urls.py
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))
]
24 changes: 24 additions & 0 deletions catalog/views.py
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, ]
12 changes: 12 additions & 0 deletions manage.py
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 added otus_site/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions otus_site/permissions.py
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
)
Loading

0 comments on commit 119729a

Please sign in to comment.