Skip to content

Commit afb6c21

Browse files
committed
Completed Project
0 parents  commit afb6c21

21 files changed

+394
-0
lines changed

How to Run.docx

66.6 KB
Binary file not shown.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Django Project to Iteratively take Inputs
2+
3+
## Getting Started
4+
5+
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
6+
7+
1. Set up a new virtualenv directory.
8+
9+
```
10+
virtualenv .
11+
source bin/activate
12+
Pull the repository
13+
```
14+
15+
### Prerequisites
16+
17+
The project is implemented on
18+
1. Django 1.8
19+
The requirements.txt file contains the python packages which needs to be installed.
20+
21+
```
22+
localhost:8000/login
23+
credentials - abc/0000
24+
```

app/__init__.py

Whitespace-only changes.

app/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

app/apps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AppConfig(AppConfig):
5+
name = 'app'

app/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

app/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

app/views.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
from django.shortcuts import render
2+
from django.http import HttpResponse, FileResponse
3+
from django.template.loader import render_to_string
4+
from django.views.generic import View
5+
from django.core.management import call_command
6+
from django.template import Template, Context
7+
8+
import os, io, csv
9+
10+
userCredentials = {
11+
'abc' : '0000'
12+
}
13+
14+
players = []
15+
index = 0
16+
17+
class Login(View):
18+
def get(self, request):
19+
html = render_to_string('login.html')
20+
return HttpResponse(html, status=200)
21+
22+
def post(self, request):
23+
data = request.POST
24+
username = data['username']
25+
password = data['password']
26+
27+
if username in userCredentials:
28+
if userCredentials[username] == password:
29+
return HttpResponse(render_to_string('landingPage.html'), status=200)
30+
31+
return HttpResponse(render_to_string('invalidLogin.html'), status=200)
32+
33+
class PlayerFile(View):
34+
def post(self, request):
35+
global index, players
36+
index = 0
37+
players.clear()
38+
39+
file = request.FILES
40+
41+
if file:
42+
file = file['filename']
43+
if file.name[-3:] == 'csv':
44+
temp = file.read().decode('utf-8').split('\n')
45+
for p in temp:
46+
if len(p) > 1:
47+
p = p.rstrip('\r')
48+
players.append(p)
49+
print(p)
50+
print(players)
51+
52+
context = {
53+
'name' : str(players[index])
54+
}
55+
return render(request, 'playerInfo.html', context, status=200)
56+
57+
return HttpResponse('Please upload a valid csv file', status = 200)
58+
59+
class Player(View):
60+
def post(self, request):
61+
global index, players
62+
63+
if(index < len(players)):
64+
# UPDATE THAT PLAYER INFO
65+
data = request.POST
66+
string = str(players[index]) + ',' + data['lastscore'] + ',' + data['balls'] + ',' + data['sixes']
67+
print(string)
68+
players[index] = string
69+
index = index + 1
70+
71+
# IF MORE PLAYERS REMAINING
72+
if(index < len(players)):
73+
context = {
74+
'name' : str(players[index])
75+
}
76+
return render(request, 'playerInfo.html', context, status=200)
77+
return HttpResponse(render_to_string('exit.html'), status=200)
78+
79+
class Exit(View):
80+
def get(self, request):
81+
# ALL INFO COLLECTED, TERMINATE
82+
print(players)
83+
header = 'Player Name' + ',' + 'Last Game Score' + ',' + 'Balls Played' + ',' + '6s Hits'
84+
with open('final.csv', 'w') as final:
85+
final.write(header + '\n')
86+
87+
for p in players:
88+
final.write(p + '\n')
89+
90+
with open('final.csv', 'rb') as final:
91+
response = HttpResponse(final, content_type='text/csv')
92+
response['Content-Disposition'] = 'attachment; filename = final.csv'
93+
return response

final.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Player Name,Last Game Score,Balls Played,6s Hits
2+
cde,45,8,2
3+
abc,45,8,45
4+
efg,89,6,2

manage.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == '__main__':
6+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError as exc:
10+
raise ImportError(
11+
"Couldn't import Django. Are you sure it's installed and "
12+
"available on your PYTHONPATH environment variable? Did you "
13+
"forget to activate a virtual environment?"
14+
) from exc
15+
execute_from_command_line(sys.argv)

players.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cde
2+
abc
3+
efg

project/__init__.py

Whitespace-only changes.

project/settings.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
"""
2+
Django settings for project project.
3+
4+
Generated by 'django-admin startproject' using Django 2.1.5.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/2.1/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'gjkp)z7*v+zt*leen66usc-trrg2i1l8dhif*06%g(s17d%xyp'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
'app',
41+
]
42+
43+
MIDDLEWARE = [
44+
'django.middleware.security.SecurityMiddleware',
45+
'django.contrib.sessions.middleware.SessionMiddleware',
46+
'django.middleware.common.CommonMiddleware',
47+
# 'django.middleware.csrf.CsrfViewMiddleware',
48+
'django.contrib.auth.middleware.AuthenticationMiddleware',
49+
'django.contrib.messages.middleware.MessageMiddleware',
50+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
51+
]
52+
53+
ROOT_URLCONF = 'project.urls'
54+
55+
TEMPLATES = [
56+
{
57+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
58+
'DIRS': [
59+
'templates',
60+
],
61+
'APP_DIRS': True,
62+
'OPTIONS': {
63+
'context_processors': [
64+
'django.template.context_processors.debug',
65+
'django.template.context_processors.request',
66+
'django.contrib.auth.context_processors.auth',
67+
'django.contrib.messages.context_processors.messages',
68+
],
69+
},
70+
},
71+
]
72+
73+
WSGI_APPLICATION = 'project.wsgi.application'
74+
75+
76+
# Database
77+
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
78+
79+
# DATABASES = {
80+
# 'default': {
81+
# 'ENGINE': 'django.db.backends.sqlite3',
82+
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
83+
# }
84+
# }
85+
86+
87+
# Password validation
88+
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
89+
90+
AUTH_PASSWORD_VALIDATORS = [
91+
{
92+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
93+
},
94+
{
95+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
96+
},
97+
{
98+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
99+
},
100+
{
101+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
102+
},
103+
]
104+
105+
106+
# Internationalization
107+
# https://docs.djangoproject.com/en/2.1/topics/i18n/
108+
109+
LANGUAGE_CODE = 'en-us'
110+
111+
TIME_ZONE = 'UTC'
112+
113+
USE_I18N = True
114+
115+
USE_L10N = True
116+
117+
USE_TZ = True
118+
119+
120+
# Static files (CSS, JavaScript, Images)
121+
# https://docs.djangoproject.com/en/2.1/howto/static-files/
122+
123+
STATIC_URL = '/static/'

project/urls.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""project URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/2.1/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.conf.urls import include, url
17+
18+
from app.views import *
19+
urlpatterns = [
20+
url(r'^login/', Login.as_view()),
21+
url(r'^playerfile/', PlayerFile.as_view()),
22+
url(r'^playerinfo/', Player.as_view()),
23+
url(r'^exit/', Exit.as_view()),
24+
]

project/wsgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for project project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
15+
16+
application = get_wsgi_application()

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Django==2.1.5
2+
pytz==2018.9

templates/exit.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE HTML>
2+
<html lang="en">
3+
4+
<body>
5+
<p>
6+
Your File is ready.
7+
<form action="http://localhost:8000/exit/"> <input type="submit" value="Donwload File and Log Out" />
8+
</form>
9+
</p>
10+
</body>

templates/invalidLogin.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE HTML>
2+
<html lang="en">
3+
4+
<body>
5+
<p>
6+
Invalid Credentials
7+
<form action="http://localhost:8000/login/"> <input type="submit" value="Login Again" />
8+
</form>
9+
</p>
10+
</body>

templates/landingPage.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE HTML>
2+
<html lang="en">
3+
4+
<body>
5+
<p>
6+
Upload Player Names in a .CSV File, with each name on a new Line<br>
7+
8+
<form method = "post" enctype="multipart/form-data"
9+
action="http://localhost:8000/playerfile/">
10+
File : <br><input type="file" name="filename"/><br>
11+
<br>
12+
<input type="submit" value="Run"><br>
13+
</form>
14+
</p>
15+
16+
</body>
17+
</html>

templates/login.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE HTML>
2+
<html lang="en">
3+
4+
<body>
5+
<p>
6+
LOGIN PAGE<br>
7+
Please enter username and password
8+
<form method = "post" enctype="multipart/form-data">
9+
Username : <br><input type="text" name="username"/><br>
10+
Password : <br><input type="text" name="password"/><br>
11+
<br>
12+
<input type="submit" value="Submit"><br>
13+
</form>
14+
</p>
15+
16+
</body>
17+
</html>

0 commit comments

Comments
 (0)