Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update db, created photorequest functionality #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

12 changes: 5 additions & 7 deletions hackathon_starter/hackathon/admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from django.contrib import admin
from hackathon.models import UserProfile, Profile, InstagramProfile, TwitterProfile, MeetupToken, GithubProfile, LinkedinProfile, TumblrProfile
from .models import UserProfile, Profile, InstagramProfile, TwitterProfile, MeetupToken, GithubProfile, LinkedinProfile, TumblrProfile, PhotoRequest

# Register your models here.
class TwitterProfileAdmin(admin.ModelAdmin):
list_display = ('user','twitter_user')
class PhotoRequestAdmin(admin.ModelAdmin):
list_display = ('event','first_name', 'last_name', 'department', 'submit_date')
list_filter = ('submit_date', 'start_date_time', 'department', 'first_name', 'last_name')

admin.site.register(UserProfile)
admin.site.register(Profile)
admin.site.register(InstagramProfile)
admin.site.register(TwitterProfile, TwitterProfileAdmin)
admin.site.register(GithubProfile)
admin.site.register(MeetupToken)
admin.site.register(LinkedinProfile)
admin.site.register(TumblrProfile)
admin.site.register(PhotoRequest, PhotoRequestAdmin)
13 changes: 12 additions & 1 deletion hackathon_starter/hackathon/forms.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django import forms
from hackathon.models import UserProfile
from django.core.exceptions import ValidationError

from models import UserProfile
from models import PhotoRequest

class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput())

class Meta:
model = User
fields = ('username', 'email', 'password')

class UploadFileForm(forms.Form):
file = forms.FileField(required=True)

class PhotoRequestForm(forms.ModelForm):
class Meta:
model = PhotoRequest
fields = ['first_name', 'last_name', 'department', 'event', 'description', 'start_date_time', 'end_date_time']
73 changes: 73 additions & 0 deletions hackathon_starter/hackathon/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import datetime

from django.core.exceptions import ValidationError
from django.db import models
from django.contrib.auth.models import User


# Create your models here.
class UserProfile(models.Model):
# This line is required. Links UserProfile to a User model instance.
Expand All @@ -10,6 +14,7 @@ class UserProfile(models.Model):
def __unicode__(self):
return self.user.username


class Profile(models.Model):
user = models.ForeignKey(User)
oauth_token = models.CharField(max_length=200)
Expand All @@ -18,6 +23,7 @@ class Profile(models.Model):
def __unicode__(self):
return unicode(self.user)


class GithubProfile(models.Model):
user = models.ForeignKey(User)
github_user = models.CharField(max_length=200)
Expand All @@ -27,6 +33,7 @@ class GithubProfile(models.Model):
def __unicode__(self):
return unicode(self.user)


class TumblrProfile(models.Model):
user = models.ForeignKey(User)
tumblr_user = models.CharField(max_length=200)
Expand All @@ -36,6 +43,7 @@ class TumblrProfile(models.Model):
def __unicode__(self):
return unicode(self.user)


class InstagramProfile(models.Model):
user = models.ForeignKey(User)
instagram_user = models.CharField(max_length=200)
Expand All @@ -44,6 +52,7 @@ class InstagramProfile(models.Model):
def __unicode__(self):
return unicode(self.user)


class TwitterProfile(models.Model):
user = models.ForeignKey(User)
twitter_user = models.CharField(max_length=200)
Expand All @@ -53,6 +62,7 @@ class TwitterProfile(models.Model):
def __unicode__(self):
return unicode(self.user)


class LinkedinProfile(models.Model):
user = models.ForeignKey(User)
linkedin_user = models.CharField(max_length=200)
Expand All @@ -61,6 +71,7 @@ class LinkedinProfile(models.Model):
def __unicode__(self):
return unicode(self.user)


class Snippet(models.Model):
created = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=100, blank=True, default='')
Expand All @@ -70,27 +81,31 @@ class Snippet(models.Model):
class Meta:
ordering = ('created',)


class MeetupToken(models.Model):
# user = models.ForeignKey(User)
access_token = models.CharField(max_length=200)

def __unicode__(self):
return unicode(self.access_token)


class FacebookProfile(models.Model):
user = models.ForeignKey(User)
fb_user_id = models.CharField(max_length=100)
time_created = models.DateTimeField(auto_now_add=True)
profile_url = models.CharField(max_length=50)
access_token = models.CharField(max_length=100)


class GoogleProfile(models.Model):
user = models.ForeignKey(User)
google_user_id = models.CharField(max_length=100)
time_created = models.DateTimeField(auto_now_add=True)
access_token = models.CharField(max_length=100)
profile_url = models.CharField(max_length=100)


class DropboxProfile(models.Model):
user = models.ForeignKey(User)
dropbox_user_id = models.CharField(max_length=100)
Expand All @@ -103,3 +118,61 @@ class FoursquareProfile(models.Model):
foursquare_id = models.CharField(max_length=100)
time_created = models.DateTimeField(auto_now_add=True)
access_token = models.CharField(max_length=100)


class PhotoRequest(models.Model):
first_name = models.CharField(max_length=50, blank=False)
last_name = models.CharField(max_length=50, blank=False)
department_choices = (
('News', 'News'),
('Sports', 'Sports'),
('Opinion', 'Opinion'),
('Life', 'Life'),
('A&E', 'A&E'),
('Focus', 'Focus'),
('H&S', 'H&S'),
('Video', 'Video'),
('Social Media', 'Social Media'),
('Humor', 'Humor'),
('Gaphics', 'Graphics'),
('Photography', 'Photography'),
('Advertising', 'Advertising'),
('Business', 'Business & Marketing')
)
department = models.CharField(max_length=25, choices=department_choices, default='News', blank=False)
event = models.CharField(max_length=100, blank=False)
description = models.CharField(max_length=200, blank=False)
start_date_time = models.DateTimeField(default=datetime.datetime.now, blank=False)
end_date_time = models.DateTimeField(default=datetime.datetime.now, blank=False)
submit_date = models.DateTimeField(default=datetime.datetime.now, blank=False)

def insert(self, fields_dict):
for field in fields_dict.keys():
if field.upper() == "department".upper():
self.department = fields_dict[field]
elif field.upper() == "event".upper():
self.event = fields_dict[field]
elif field.upper() == "description".upper():
self.description = fields_dict[field]
elif field.upper() == "first_name".upper():
self.first_name = fields_dict[field]
elif field.upper() == "last_name".upper():
self.last_name = fields_dict[field]
elif field.upper() == "start_date_time".upper():
if "/" not in fields_dict[field]:
self.start_date_time = fields_dict[field]
else:
start_time = fields_dict[field]
start_date = start_time.split(" ")[0]
start_time = start_time.split(" ")[1]
start_date = start_date.replace("/", "-")
self.start_date_time = start_date + " " + start_time
elif field.upper() == "end_date_time".upper():
if "/" not in fields_dict[field]:
self.end_date_time = fields_dict[field]
else:
end_time = fields_dict[field]
end_date = end_time.split(" ")[0]
end_time = end_time.split(" ")[1]
end_date = end_date.replace("/", "-")
self.end_date_time = end_date + " " + end_time
103 changes: 57 additions & 46 deletions hackathon_starter/hackathon/templates/hackathon/base.html
Original file line number Diff line number Diff line change
@@ -1,61 +1,72 @@
<!DOCTYPE html>
{% load staticfiles %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

{% load bootstrap3 %}

{% bootstrap_css %}
{% bootstrap_javascript %}
<html lang="en">
<head>
<head>
<title> Django Hackathon Starter </title>
<script src="/static/bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="/static/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/bower_components/d3/d3.min.js"></script>

<link rel="stylesheet" href="/static/bower_components/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/bower_components/bootstrap/dist/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="/static/bower_components/bootstrap-social/bootstrap-social.css">
<link rel="stylesheet" href="/static/bower_components/font-awesome/css/font-awesome.min.css">

</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
</head>

<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Django Hackathon Starter</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-left">
{% if user.is_authenticated %}
<li><a href="/hackathon/api">API</a></li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if not user.is_authenticated %}
<li class="active"><a href="/hackathon/register">Register <span class="sr-only">(current)</span></a></li>

<li><a href="/hackathon/login">Login</a></li>
{% endif %}

</ul>

<ul class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}

<li><a>Hello {{user}}</a></li>
<li><a href="/hackathon/logout/">Logout</a></li>
{% endif %}
</ul>


</li>
</ul>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Django Hackathon Starter</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-left">
{% if user.is_authenticated %}
<li><a href="{% url 'api' %}">API</a></li>
<li><a href="{% url 'upload_file' %}">Upload CSV</a></li>
<li><a href="{% url 'create_photo_request'%}">New Photo Request</a></li>

{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% if not user.is_authenticated %}
<li class="active"><a href="/hackathon/register">Register <span class="sr-only">(current)</span></a>
</li>
<li><a href="/hackathon/login">Login</a></li>
{% endif %}

</ul>

<ul class="nav navbar-nav navbar-right">
{% if user.is_authenticated %}

<li><a>Hello {{user}}</a></li>
<li><a href="/hackathon/logout/">Logout</a></li>
{% endif %}
</ul>


</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</body>
</div><!-- /.container-fluid -->
</nav>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create New Photo Request</title>
<style>
form {
text-align: left;
}

.form_item > li {
padding: 5pt;
}
</style>
</head>
<body>
{% include 'hackathon/base.html' %}

{% load static %}

{% block content %}
<form method="post" enctype="multipart/form-data">
<div style="margin-left: auto; margin-right: auto">
{% csrf_token %}
<ul style="list-style-type: none" class="form_item">
<li><b>First Name: </b>{{form.first_name}}</li>
<li><b>Last Name: </b>{{form.last_name}}</li>
<li><b>Department: </b>{{form.department}}</li>
<hr>
<li><b>Event name: </b>{{form.event}}</li>
<li><b>Description: </b>{{form.description}}</li>
<li><b>Start Date/Time: </b>{{form.start_date_time}}</li>
<li><b>End Date/Time: </b>{{form.end_date_time}}</li>
</ul>
</div>
<div style="padding-left: 5pt">
<input type="submit" value="Create">
</div>
</form>
{% endblock %}
</body>
</html>
Loading