Skip to content

Commit 8d8dd0f

Browse files
committedFeb 20, 2021
Initial Django Boilerplate code with excel upload utility
1 parent 2fb5fee commit 8d8dd0f

17 files changed

+246
-0
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
settings.json

‎geolocationapi/__init__.py

Whitespace-only changes.

‎geolocationapi/settings.py

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
"""
2+
Django settings for geolocationapi project.
3+
4+
Generated by 'django-admin startproject' using Django 2.1.15.
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 = 'lo@8(5xpzy4^k26(aw@zx_)@lsdg1u2vkt9-2nn=l=klalv(jb'
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+
# First Party Apps
41+
'locationapi',
42+
# Third Party Apps
43+
'django_extensions',
44+
]
45+
46+
MIDDLEWARE = [
47+
'django.middleware.security.SecurityMiddleware',
48+
'django.contrib.sessions.middleware.SessionMiddleware',
49+
'django.middleware.common.CommonMiddleware',
50+
'django.middleware.csrf.CsrfViewMiddleware',
51+
'django.contrib.auth.middleware.AuthenticationMiddleware',
52+
'django.contrib.messages.middleware.MessageMiddleware',
53+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
54+
]
55+
56+
ROOT_URLCONF = 'geolocationapi.urls'
57+
58+
TEMPLATES = [
59+
{
60+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
61+
'DIRS': [],
62+
'APP_DIRS': True,
63+
'OPTIONS': {
64+
'context_processors': [
65+
'django.template.context_processors.debug',
66+
'django.template.context_processors.request',
67+
'django.contrib.auth.context_processors.auth',
68+
'django.contrib.messages.context_processors.messages',
69+
],
70+
},
71+
},
72+
]
73+
74+
WSGI_APPLICATION = 'geolocationapi.wsgi.application'
75+
76+
77+
# Database
78+
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
79+
80+
DATABASES = {
81+
'default': {
82+
'ENGINE': 'django.db.backends.sqlite3',
83+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
84+
}
85+
}
86+
87+
88+
# Password validation
89+
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
90+
91+
AUTH_PASSWORD_VALIDATORS = [
92+
{
93+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
94+
},
95+
{
96+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
97+
},
98+
{
99+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
100+
},
101+
{
102+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
103+
},
104+
]
105+
106+
107+
# Internationalization
108+
# https://docs.djangoproject.com/en/2.1/topics/i18n/
109+
110+
LANGUAGE_CODE = 'en-us'
111+
112+
TIME_ZONE = 'UTC'
113+
114+
USE_I18N = True
115+
116+
USE_L10N = True
117+
118+
USE_TZ = True
119+
120+
121+
# Static files (CSS, JavaScript, Images)
122+
# https://docs.djangoproject.com/en/2.1/howto/static-files/
123+
124+
STATIC_URL = '/static/'

‎geolocationapi/urls.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.contrib import admin
2+
from django.urls import path, include
3+
import locationapi
4+
5+
urlpatterns = [
6+
path('admin/', admin.site.urls),
7+
path('', include('locationapi.urls')),
8+
]

‎geolocationapi/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for geolocationapi 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', 'geolocationapi.settings')
15+
16+
application = get_wsgi_application()

‎locationapi/__init__.py

Whitespace-only changes.

‎locationapi/admin.py

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

‎locationapi/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class LocationapiConfig(AppConfig):
5+
name = 'locationapi'

‎locationapi/migrations/__init__.py

Whitespace-only changes.

‎locationapi/models.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

‎locationapi/templates/base.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% load static %}
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>GeoLocation Web App</title>
9+
</head>
10+
<body>
11+
{% block content %}
12+
{% endblock %}
13+
</body>
14+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% extends 'base.html' %}
2+
{% block content %}
3+
<h2>Upload Excel File</h2>
4+
<p>
5+
Rules to follow:
6+
<br /><br />
7+
1. Please upload a excel file with .xlsx extension.
8+
<br />
9+
2. Please add address of your choice in the first column only.
10+
<br />
11+
3. All other columns should be blank for this web application to work.
12+
<br />
13+
4. Click Upload the file, a output file will be generated in 10-120 seconds depending on the file size.
14+
</p>
15+
<br />
16+
<form action='{% url "upload_excel" %}' method="post" enctype="multipart/form-data">
17+
{% csrf_token %}
18+
<input type="file"
19+
title="Upload excel file"
20+
name="excel_file"
21+
style="border: 1px solid black; padding: 5px;"
22+
required="required">
23+
<input type="submit"
24+
value="Upload"
25+
style="border: 1px solid green; padding:5px; border-radius: 2px; cursor: pointer;">
26+
</form>
27+
{% endblock %}

‎locationapi/tests.py

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

‎locationapi/urls.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.urls import path
2+
from .views import upload_excel
3+
4+
urlpatterns = [
5+
path('', upload_excel, name="upload_excel")
6+
]

‎locationapi/views.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.shortcuts import render
2+
from django.http import HttpResponse
3+
import pandas as pd
4+
5+
def upload_excel(request):
6+
if request.method == 'GET':
7+
return render(request, 'locationapi/upload_excel.html')
8+
else:
9+
excel_file = request.FILES["excel_file"]
10+
excel_data = pd.read_csv(excel_file)
11+
print(excel_data)
12+
return render(request, 'locationapi/upload_excel.html')

‎manage.py

+15
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', 'geolocationapi.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)

‎requirements.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Django==2.2.17
2+
django-extensions==3.1.1
3+
numpy==1.20.1
4+
pandas==1.2.2
5+
python-dateutil==2.8.1
6+
pytz==2021.1
7+
six==1.15.0
8+
sqlparse==0.4.1

0 commit comments

Comments
 (0)
Please sign in to comment.