Basic site, login, simple list is working

This commit is contained in:
2017-02-02 00:49:38 -05:00
parent efc5c220c5
commit 07ad08d16c
28 changed files with 689 additions and 0 deletions

View File

View File

@@ -0,0 +1,5 @@
from django.contrib import admin
from models import Committee
# Register your models here.
admin.site.register(Committee)

7
fincom/committee/apps.py Normal file
View File

@@ -0,0 +1,7 @@
from __future__ import unicode_literals
from django.apps import AppConfig
class CommitteeConfig(AppConfig):
name = 'committee'

View File

@@ -0,0 +1,11 @@
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models
class Committee(models.Model):
name = models.CharField(max_length=100)
chair = models.ForeignKey(User, null=True)
def __str__(self):
return self.name

View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

143
fincom/fincom/settings.py Normal file
View File

@@ -0,0 +1,143 @@
"""
Django settings for fincom project.
Generated by 'django-admin startproject' using Django 1.10.5.
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 = os.environ['SECRET_KEY']
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
AUTHENTICATION_BACKENDS = [
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'items',
'committee',
'social_django',
]
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 = 'fincom.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['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',
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
},
},
]
WSGI_APPLICATION = 'fincom.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'dbu9ujb6cnhc3n',
'USER': 'dexgqmkgoabqyd',
'PASSWORD': os.environ['DBPASSWD'],
'HOST': 'ec2-50-19-89-124.compute-1.amazonaws.com',
'PORT': '5432',
}
}
# 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',
},
]
# social_auth configuration
# http://python-social-auth.readthedocs.io/en/latest/configuration/settings.html
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = os.environ['SOCIAL_AUTH_GOOGLE_OAUTH2_KEY']
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = os.environ['SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET']
SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS = ['andrew.cmu.edu']
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/items/'
# 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/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)

25
fincom/fincom/urls.py Normal file
View File

@@ -0,0 +1,25 @@
"""fincom 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 include, url
from django.contrib import admin
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^items/', include('items.urls')),
url('', include('social_django.urls', namespace='social')),
url(r'^admin/', admin.site.urls),
]

6
fincom/fincom/views.py Normal file
View File

@@ -0,0 +1,6 @@
from django.http import HttpResponse
from django.template import loader
def index(request):
template = loader.get_template('fincom/index.html')
return HttpResponse(template.render({}, request))

16
fincom/fincom/wsgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
WSGI config for fincom 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", "fincom.settings")
application = get_wsgi_application()

0
fincom/items/__init__.py Normal file
View File

5
fincom/items/admin.py Normal file
View File

@@ -0,0 +1,5 @@
from django.contrib import admin
from models import Item
# Register your models here.
admin.site.register(Item)

7
fincom/items/apps.py Normal file
View File

@@ -0,0 +1,7 @@
from __future__ import unicode_literals
from django.apps import AppConfig
class ItemsConfig(AppConfig):
name = 'items'

125
fincom/items/models.py Normal file
View File

@@ -0,0 +1,125 @@
from __future__ import unicode_literals
from django.contrib.auth.models import User
from committee.models import Committee
from django.db import models
class Item(models.Model):
NEW = 'N'
PREAPPROVED = 'C'
PROCESSED = 'P'
REJECTED = 'R'
STATUS = (
(NEW, 'New'),
(PREAPPROVED, 'Committee Approved'),
(PROCESSED, 'Processed'),
(REJECTED, 'Rejected'),
)
desc = models.CharField(max_length=200)
event = models.CharField(max_length=200)
committee = models.ForeignKey(Committee)
details = models.TextField()
cost = models.DecimalField(max_digits=7, decimal_places=2)
date_purchased = models.DateField('date purchased')
created_by = models.ForeignKey(User, related_name='created_by')
approved_by = models.ManyToManyField(User, blank=True, related_name='approved_by')
date_filed = models.DateTimeField('date filed')
status = models.CharField(max_length=2, choices=STATUS)
task_id = models.CharField(max_length=30)
def approved(self):
return self.status == 'P'
def processed(self):
return self.status == 'C'
def rejected(self):
return self.status == 'R'
def new(self):
return self.status == 'N'
def comName(self):
return self.committee.name
def __str__(self):
return self.committee.name + ": " + self.event + " " + self.desc
@staticmethod
def parseDate(date_str):
try:
return datetime.strptime(date_str, "%m/%d/%y").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%m/%d/%Y").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%m-%d-%y").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%m-%d-%Y").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%m %d %y").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%m %d %Y").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%y %m %d").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%Y %m %d").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%y-%m-%d").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%Y-%m-%d").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%y/%m/%d").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%Y/%m/%d").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%d %m %y").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%d %m %Y").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%d/%m/%y").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%d/%m/%Y").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%d-%m-%y").date().isoformat()
except ValueError:
pass
try:
return datetime.strptime(date_str, "%d-%m-%Y").date().isoformat()
except ValueError:
return date.today().isoformat()

3
fincom/items/tests.py Normal file
View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

6
fincom/items/urls.py Normal file
View File

@@ -0,0 +1,6 @@
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.list, name='list'),
]

13
fincom/items/views.py Normal file
View File

@@ -0,0 +1,13 @@
from django.shortcuts import HttpResponse
from django.template import loader
from models import Item
# Create your views here.
def list(request):
template = loader.get_template('items/list.html')
context = {
'items': Item.objects.all(),
}
return HttpResponse(template.render(context, request))

22
fincom/manage.py Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fincom.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)

View File

@@ -0,0 +1,4 @@
SRC=$(wildcard *.scss)
all: $(SRC)
sass include.scss ../css/site.css

View File

@@ -0,0 +1,68 @@
$purple: #563d7c;
$gold: #fdd017;
$lightgray: #fcfcfc;
$midgray: #969499;
$darkgray: #4b4a4d;
$text: #252526;
$shadowgray: rgba(0, 0, 0, .8);
// size constants
$pad-s: 2px;
$pad-m: 8px;
$pad-l: 16px;
$pad-xl: 36;
body {
color: $text;
font-family: Sans-Serif;
background-color: $lightgray;
padding-bottom: 0px;
margin: 0px $pad-l;
}
.nav {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 50px;;
box-sizing: border-box;
padding: 16px;
background-color: $purple;
color: $gold;
box-shadow: 0px 3px 12px $shadowgray;
z-index: 10;
h3 {
font-weight: lighter;
font-size: 16px;
margin: 0;
}
}
.container {
height: 100%;
margin-left: auto;
margin-right: auto;
margin-top: 64px;
max-width: 960;
background-color: #fff;
border: solid 1px $midgray;
}
.btn {
border-radius: $pad-s;
color: $purple;
display: inline-block;
padding: $pad-m $pad-l;
text-decoration: none;
vertical-align: middle;
white-space: nowrap;
&:hover {
background-color: darken($purple, 15%);
}
}

View File

@@ -0,0 +1,2 @@
@import 'items';
@import 'login';

View File

@@ -0,0 +1,80 @@
@import 'globals';
.item {
padding: $pad-m $pad-xl;
margin: 0px;
border-bottom: 1px solid $midgray;
box-sizing: border-box;
width: 100%;
.committee {
color: $midgray;
font-size: 12px;
font-weight: bold;
margin: 0px;
}
.details-row {
margin: $pad-m 0;
font-size: 16px;
color: $text;
padding: 0px;
b {
color: $darkgray;
}
em {
color: $midgray;
margin: 0 $pad-s;
}
}
.status {
color: $midgray;
font-size: 12px;
margin: 0px;
}
.cost {
float: right;
display: inline-block;
text-align: center;
width: 120px;
height: 24px;
font-size: 12px;
color: $midgray;
border-radius: $pad-s;
border: 1px solid $midgray;
box-sizing: border-box;
padding: 2*$pad-s;
margin: 2*$pad-s 0;
}
.approved {
background-color: #ffd9d9;
}
.processed {
background-color: #d9ffd9;
}
.newItem {
background-color: #fff7d9;
}
}
$button-size: 24px;
.btn-floating {
position: fixed;
bottom: $button-size;
right: $button-size;
padding: $button-size;
z-index: 1000;
border-radius: 50%;
text-align: center;
box-shadow: 0 0 6px rgba(0,0,0,.16),0 6px 12px rgba(0,0,0,.32);
}

View File

@@ -0,0 +1,35 @@
@import 'globals';
body.login {
background-color: $purple;
color: $gold;
}
.login {
text-align: center;
color: $gold;
div {
margin-top: 30%;
}
h3 {
font-size: 24px;
margin-bottom: $pad-m;
}
h2 {
font-size: 28px;
margin-top: -$pad-l;
}
.btn {
background-color: $gold;
color: $purple;
&:hover {
background-color: darken($gold, 15%);
}
}
}

View File

@@ -0,0 +1,26 @@
<html>
<head>
<title>{% block title %}Fincom Webapp{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{% load staticfiles %}
<link href="{% static "css/site.css" %}" rel="stylesheet" />
</head>
<body>
<div class="nav">
<h3>Fincom Web App</h3>
</div>
<div class="container">
{% block main %}
{% endblock %}
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-62761470-2', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>

View File

@@ -0,0 +1,31 @@
<html>
<head>
<title>Login - Fincom</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{% load staticfiles %}
<link href="{% static "css/site.css" %}" rel="stylesheet">
</head>
<body class="login">
<div class="container">
<h3>Delta Beta Chapter</h3>
<h2>Fincom Webapp</h2>
{% if error %}
<p>{{ error }}</p>
{% endif %}
<a class="btn btn-info btn-lg"
href="/login/google-oauth2/?next={{ next }}">
Login with your AndrewID
</a>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-62761470-2', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>

View File

@@ -0,0 +1,32 @@
<div class="item">
<div class="committee">
{{ I.comName }}
</div>
{% if I.approved %}
<div class="cost approved">
{% elif I.processed %}
<div class="cost processed">
{% else %}
<div class="cost newItem">
{% endif %}
${{ I.cost|floatformat:"2" }}
</div>
<div class="details-row">
<b>{{ I.event }}:</b>
{{ I.desc }}
<em>by</em>
{{ I.created_by.first_name }} {{ I.created_by.last_name }}
<em>on</em> {{ I.date_purchased }}
<em>(filed {{ I.date_filed }})</em>
</div>
<div class="status">
{% if I.approved or I.processed %}
Approved By:
{% for u in I.approved_by.all %}
{{ u.first_name }} {{ u.last_name }}
{% endfor %}
{% else %}
Needs Approval
{% endif %}
</div>
</div>

View File

@@ -0,0 +1,11 @@
{% extends "../boilerplate.html" %}
{% block main %}
{% for I in items %}
{% include "./item.html" %}
{% empty %}
<div>No Reimbursements</div>
{% endfor %}
{% endblock %}