Skip to content
Open

upd #33

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
431 changes: 431 additions & 0 deletions TV/.idea/workspace.xml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Telecast/.idea/Telecast.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Telecast/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Telecast/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

468 changes: 468 additions & 0 deletions Telecast/.idea/workspace.xml

Large diffs are not rendered by default.

Empty file added Telecast/TV/__init__.py
Empty file.
Binary file added Telecast/TV/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added Telecast/TV/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file added Telecast/TV/__pycache__/models.cpython-35.pyc
Binary file not shown.
Binary file added Telecast/TV/__pycache__/urls.cpython-35.pyc
Binary file not shown.
Binary file added Telecast/TV/__pycache__/views.cpython-35.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions Telecast/TV/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin

# Register your models here.
from .models import TV

admin.site.register(TV)
7 changes: 7 additions & 0 deletions Telecast/TV/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import unicode_literals

from django.apps import AppConfig


class TvConfig(AppConfig):
name = 'TV'
27 changes: 27 additions & 0 deletions Telecast/TV/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2016-12-07 17:51
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='TV',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('description', models.CharField(max_length=1000)),
('duration', models.CharField(max_length=10)),
('date', models.CharField(max_length=10)),
('advert', models.BooleanField(default=0)),
],
),
]
Empty file.
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions Telecast/TV/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import unicode_literals

from django.db import models


class TV(models.Model):
name = models.CharField(max_length=200)
description = models.CharField(max_length=1000)
duration = models.CharField(max_length=10)
date = models.CharField(max_length=10)
advert = models.BooleanField(default=0)

def __str__(self):
return self.name
15 changes: 15 additions & 0 deletions Telecast/TV/templates/TV/edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit</title>
</head>
<body>
<form action="{% url 'TV:save' obj.id %}" method="post">
{% csrf_token %}
<input type="text" name="description"
value=“{{ obj.description }}”>
<input type="submit" value="Save" />
</form>
</body>
</html>
29 changes: 29 additions & 0 deletions Telecast/TV/templates/TV/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>index.html</title>
{% load static %}
</head>
<body>
<div class="main">Telecasts</div>

{% if tv_list %}
<ul>
{% for tv in tv_list %}
<li> </li>
<ul>{{ tv.name }}
<li>{{ tv.description }}</li>
<li>{{ tv.duration }}</li>
<li>{{ tv.date }}</li>
<a href="{% url 'TV:edit' tv.id%}">Edit</a>
</ul>

{% endfor %}
</ul>
{% else %}
<p>No telecasts are available.</p>
{% endif %}

</body>
</html>
3 changes: 3 additions & 0 deletions Telecast/TV/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
10 changes: 10 additions & 0 deletions Telecast/TV/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.conf.urls import url
from . import views

app_name = "TV"
urlpatterns = [

url(r'^$', views.index, name='index'),
url(r'^(?P<id>[0-9]*)/$', views.edit, name='edit'),
url(r'^(?P<id>[0-9]*)/save/$', views.save, name='save')
]
36 changes: 36 additions & 0 deletions Telecast/TV/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse, Http404, HttpResponseRedirect
from .models import TV
from django.urls import reverse


# Create your views here.

def index(request):
tv_list = TV.objects.all()
context = {'tv_list': tv_list}
return render(request, 'TV/index.html', context)


def edit(request, id):
obj = get_object_or_404(TV, id=id)
return render(request, 'TV/edit.html', {'obj': obj})


def save(request, id):
obj = get_object_or_404(TV, id=id)
try:
obj.description = request.POST['description']
except KeyError:
return render(request, 'TV/edit.html', {'obj': obj})
else:
return HttpResponseRedirect(reverse('index.html'))


def add(request):
tv = TV(name=request.POST['name'], description=request.POST['description'],
duration=request.POST['duration'],
date=request.POST['date'],
advert=request.POST['advert'])
tv.save()
return HttpResponseRedirect(reverse('TV:index'))
Empty file added Telecast/Telecast/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Telecast/Telecast/__pycache__/wsgi.cpython-35.pyc
Binary file not shown.
121 changes: 121 additions & 0 deletions Telecast/Telecast/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"""
Django settings for Telecast project.

Generated by 'django-admin startproject' using Django 1.10.3.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'ab1*!_k#1fjl&809$7nn@%l3phb62xk55&a$185j*9uj6w7$zd'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'TV',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'Telecast.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'Telecast.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

STATIC_URL = '/static/'
23 changes: 23 additions & 0 deletions Telecast/Telecast/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Telecast URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.10/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from django.conf.urls import url, include

urlpatterns = [
url(r'^TV/', include('TV.urls')),
url(r'^admin/', admin.site.urls),
]
16 changes: 16 additions & 0 deletions Telecast/Telecast/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for Telecast project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Telecast.settings")

application = get_wsgi_application()
Binary file added Telecast/db.sqlite3
Binary file not shown.
22 changes: 22 additions & 0 deletions Telecast/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Telecast.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)