Commit 2ff62f35 authored by Tarsvini's avatar Tarsvini

init

parent 649a11b6
web: gunicorn praktikum.wsgi --log-file -
\ No newline at end of file
Name : Tarsvini
# Where do we start from here?
NPN : 1706103146
Class: B
Hobby: Dreaming
# Where do we start from here?
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class Lab1Config(AppConfig):
name = 'lab_1'
from django.db import models
# Create your models here.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ name }}</title>
</head>
<body>
<h1>Hello my name is {{ name }}</h1>
<article>I am {{ age }} years old</article>
</body>
</html>
from django.test import TestCase
from django.test import Client
from django.urls import resolve
from .views import index, mhs_name, calculate_age
from django.http import HttpRequest
from datetime import date
import unittest
# Create your tests here.
class Lab1UnitTest(TestCase):
def test_hello_name_is_exist(self):
response = Client().get('/lab-1/')
self.assertEqual(response.status_code,200)
def test_using_index_func(self):
found = resolve('/lab-1/')
self.assertEqual(found.func, index)
def test_name_is_changed(self):
request = HttpRequest()
response = index(request)
html_response = response.content.decode('utf8')
self.assertIn('<title>' + mhs_name + '</title>', html_response)
self.assertIn('<h1>Hello my name is ' + mhs_name + '</h1>', html_response)
self.assertFalse(len(mhs_name) == 0)
def test_calculate_age_is_correct(self):
self.assertEqual(0, calculate_age(date.today().year))
self.assertEqual(17, calculate_age(2000))
self.assertEqual(27, calculate_age(1990))
def test_index_contains_age(self):
request = HttpRequest()
response = index(request)
html_response = response.content.decode('utf8')
self.assertRegex(html_response, r'<article>I am [0-9]\d+ years old</article>')
from django.conf.urls import url
from .views import index
#url for app
urlpatterns = [
url(r'^$', index, name='index'),
]
from django.shortcuts import render
from datetime import datetime, date
# Enter your name here
mhs_name = 'VINI' # TODO Implement this
curr_year = int(datetime.now().strftime("%Y"))
birth_date = date(1996,3,14) #TODO Implement this, format (Year, Month, Date)
# Create your views here.
def index(request):
response = {'name': mhs_name, 'age': calculate_age(birth_date.year)}
return render(request, 'index_lab1.html', response)
def calculate_age(birth_year):
return curr_year - birth_year if birth_year <= curr_year else 0
# What should you learn from codes & documentation in this sub-directory?
* The implementation of View: the presentation layer to the user, what you see on the browser
* The implementation of Controller: intermediary tier between model and view
* How Django Webserver Works ![How Django Webserver Works](docs/how-django-webserver-works.png)
* How Django Framework Works with Templating ![How Django Framework Works with Templating](docs/how-django-framework-works.png)
* How Django Framework Works with Templating & Models ![How Django Framework Works with Templating & Models](docs/how-django-framework-with-models-works.png)
# References
* Class Material "02. Intro to Framework, Server Side Programming with Django", Slide 1-31
* https://www.djangoproject.com/
* https://docs.djangoproject.com/en/1.11/
* https://docs.djangoproject.com/en/1.11/topics/http/urls/
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class Lab2Config(AppConfig):
name = 'lab_2'
from django.db import models
# Create your models here.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Biodata</title>
</head>
<style>
table, th, td {
border: 1px solid black;
}
.subject{
font-size: 20px;
font-family: "Comic Sans MS";
color: #6650ff;
}
.value{
font-size: 20px;
font-family: "Roboto", "Lucida Grande", Verdana, Arial, sans-serif;
color: #ff102c;
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body style="background-color: aqua">
<h3 style="text-align: center">Hi all, This is my complete biodata</h3>
<table align="center" style="text-align: center">
{% for bio in bio_dict %}
<tr>
<td class="subject">{{ bio.subject }}</td>
<td class="value">{{ bio.value }}</td>
</tr>
{% endfor %}
</table>
<br><br>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Landing Page</title>
</head>
<style>
.status{
font-size: 20px;
font-family: "Comic Sans MS";
color: #6650ff;
text-align: justify;
text-justify: inter-word;
}
.name{
font-size: 20px;
font-family: "Roboto", "Lucida Grande", Verdana, Arial, sans-serif;
color: #ff102c;
}
.center_screen {
position: absolute;
width: 500px;
height: 50px;
top: 50%;
left: 50%;
margin-left: -250px; /* margin is -0.5 * dimension */
margin-top: -25px;
}
#href_bio{
}
</style>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body style="background-color: lightgray">
<div class="center_screen">
<p class="status">Hello, this is {{ name }}. {{ content }} Check my <a id="href_bio">Biography</a>.</p>
</div>
</body>
<script>
$(document).ready(function(){
$("#href_bio").click(function(){
window.location.href = '/lab-2-addon/'
});
});
</script>
</html>
from django.test import TestCase
from django.test import Client
from django.urls import resolve
from .views import index, landing_page_content, mhs_name
from django.http import HttpRequest
from unittest import skip
# Create your tests here.
class Lab2UnitTest(TestCase):
def test_lab_2_url_is_exist(self):
response = Client().get('/lab-2/')
self.assertEqual(response.status_code,200)
def test_lab2_using_index_func(self):
found = resolve('/lab-2/')
self.assertEqual(found.func, index)
def test_landing_page_content_is_written(self):
#Content cannot be null
self.assertIsNotNone(landing_page_content)
#Content is filled with 30 characters at least
self.assertTrue(len(landing_page_content) >= 30)
def test_landing_page_is_completed(self):
request = HttpRequest()
response = index(request)
html_response = response.content.decode('utf8')
self.assertIn('Hello, this is '+ mhs_name +'.', html_response)
self.assertIn(landing_page_content, html_response)
class Lab2AddonUnitTest(TestCase):
@skip('Move this test case to lab_2_addon apps')
def test_lab_2_addon_url_is_exist(self):
response = Client().get('/lab-2-addon/')
self.assertEqual(response.status_code, 200)
@skip('Move this test case to lab_2_addon apps')
def test_root_url_now_is_using_index_page_from_lab_2(self):
response = Client().get('/')
self.assertEqual(response.status_code, 301)
self.assertRedirects(response,'/lab-2/',301,200)
@skip('Move this test case to lab_2_addon apps')
def test_lab2_addon_using_index_func(self):
found = resolve('/lab-2-addon/')
self.assertEqual(found.func, index)
@skip('Move this test case to lab_2_addon apps')
def test_lab2_addon_bio_dict(self):
# Check whether bio_dict is not None Object
self.assertIsNotNone(bio_dict)
# Check whether bio_dict entry is less than 3 items
self.assertTrue(len(bio_dict) >= 3)
# Checking all element in family member
for bio in bio_dict:
# Name cannot be None
self.assertIsNotNone(bio['subject'])
self.assertIsNotNone(bio['value'])
# Name cannot be integer
self.assertIsNot(type(bio['value']), type(8))
@skip('Move this test case to lab_2_addon apps')
def test_lab2_addon_bio_shown_in_page(self):
request = HttpRequest()
response = index(request)
html_response = response.content.decode('utf8')
# Checking all family member is shown in page
for bio in bio_dict:
self.assertIn('<td class="subject">' + bio['subject'] + '</td>', html_response)
self.assertIn('<td class="value">' + bio['value'] + '</td>', html_response)
from django.conf.urls import url
from .views import index
#url for app, add your URL Configuration
urlpatterns = [
#TODO Implement this
]
from django.shortcuts import render
from lab_1.views import mhs_name, birth_date
#TODO Implement
#Create a content paragraph for your landing page:
landing_page_content = ''
def index(request):
response = {'name': mhs_name, 'content': landing_page_content}
return render(request, 'index_lab2.html', response)
\ No newline at end of file
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "praktikum.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
# 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)
# Where do we start from here?
"""
Django settings for draft_lab project.
Generated by 'django-admin startproject' using Django 1.11.4.
For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/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.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'wu8+v3gh8+1dt6vq+15kfk&)-h70!o6+&ke+#1o@kt6i-98yxq'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'lab_1',
'lab_2',
]
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 = 'praktikum.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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 = 'praktikum.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/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.11/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.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATIC_URL = '/static/'
"""Lab1 URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/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, include
from django.contrib import admin
import lab_1.urls as lab_1
from lab_1.views import index as index_lab1
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^lab-1/', include(lab_1,namespace='lab-1')),
url(r'^$', index_lab1, name='index')
]
"""
WSGI config for draft_lab 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.11/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "praktikum.settings")
application = get_wsgi_application()
astroid==1.5.3
colorama==0.3.9
coverage==4.4.1
Django==1.11.4
gunicorn==19.7.1
isort==4.2.15
lazy-object-proxy==1.3.1
mccabe==0.6.1
pylint==1.7.2
pytz==2017.2
six==1.10.0
wrapt==1.10.11
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment