Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Merge branch 'email' of https://bitbucket.org/dtraviglia/stout into e…
…mail
  • Loading branch information
Kyle Finley committed Sep 22, 2015
2 parents 9df6fe1 + bb3f5db commit 6b3976ec7235186bb8b5e7211405c04c300e3eb9
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 42 deletions.
@@ -13,4 +13,6 @@ files/draper-openrc.sh
op_tasks/migrations/*
exp_portal/migrations/*
developer/migrations/*
uploads/migrations/*
secret.py

@@ -1,9 +1,5 @@
{% extends "main.html" %}

{% block head %}
<!-- <link rel="stylesheet" type="text/css" href="/static/css/styles.css"> -->
{% endblock %}

{% block container %}
<section>
<h1 align="center"><b>Login to XDATA Online</b></h1>
@@ -14,5 +10,8 @@ <h4 class="form-signin-heading">Please sign in</h4>
<input class="form-control" type="password" name="password" value="" placeholder="Password" required/>
<button class="btn btn-lg btn-primary btn-block" type="submit" value="submit">Sign in</button>
</form>
<h4 align="center">
<a href="{% url 'op_tasks:reset' %}">Forgot password?</a>
</h4>
</section>
{% endblock %}
@@ -0,0 +1,16 @@
{% extends "main.html" %}
{% block title %}Reset Password{% endblock %}
{% block container %}
<div align="center">
{% if validlink %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Submit</button>
</form>
{% else %}
<p>This reset link is no longer valid!</p>
{% endif %}
</div>

{% endblock%}
@@ -0,0 +1,11 @@
{% extends "main.html" %}

{% block title %}Password Reset In Progress{% endblock %}

{% block container %}

<h1>Password reset in progress</h1>

<p>We've emailed you instructions for setting your password to the email address you submitted. You should be receiving it shortly.</p>

{% endblock %}
@@ -0,0 +1,14 @@
{% autoescape off %}
You're receiving this email because you requested a password reset for your user account at {{ site_name }}.

Please go to the following page and choose a new password:
{% block reset_link %}
{{ protocol }}://{{ domain }}{% url 'op_tasks:reset_confirm' uidb64=uid token=token %}
{% endblock %}
Your username, in case you've forgotten: {{ user.get_username }}

Thanks for using our site!

The {{ site_name }} team

{% endautoescape %}
@@ -0,0 +1,16 @@
{% extends "main.html" %}
{% block title %}Reset Password{% endblock %}
{% block container %}

<form method="post">
<h2 align="center">Password Reset</h2>
<h4 align="center">Please enter your email to continue:</h4>
{% csrf_token %}
<div align="center">
{{ form.as_p }}
<button type="submit">Submit</button>
</div>
</form>

{% endblock %}

@@ -12,7 +12,6 @@
url(r'^task_test/(?P<task_pk>[0-9]+)$', views.task_test, name='task_test'),
url(r'^task_launch/(?P<task_pk>[0-9]+)$', views.task_launch, name='task_launch'),
url(r'^register$', views.register, name='register'),
# url(r'^login/(?P<title>\w+)$', views.login_participant, name='login'),
url(r'^login/$', views.login_participant, name='login'),
url(r'^logout/$', views.logout_participant, name='logout'),
url(r'^intro/$', views.intro, name='intro'),
@@ -22,7 +21,10 @@
url(r'^experiment_instructions$', views.exp_instruct, name='exp_instruct'),
url(r'^portal_instructions$', views.portal_instruct, name='portal_instruct'),
url(r'^product_instructions$', views.product_instruct, name='product_instruct'),
url(r'^user_profile$', views.view_profile, name='view_profile'),
url(r'^user_profile$', views.view_profile, name='view_profile'),
url(r'^reset/confirm/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', views.reset_confirm, name='reset_confirm'),
url(r'^reset/$', views.reset, name='reset'),
url(r'^reset/sent/$', views.reset_sent, name='reset_sent')
)

# print settings.DEBUG, settings.STATIC_ROOT
@@ -2,19 +2,18 @@
from django.http import HttpResponseRedirect, HttpResponse
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.views import password_reset, password_reset_confirm
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.conf import settings
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import User
from django.utils import timezone
from elasticsearch import Elasticsearch

import exp_portal
import json
import datetime
import exceptions

from op_tasks.models import Dataset, Product, OpTask, UserProfile, TaskListItem, Experiment
from op_tasks.models import Product, UserProfile, TaskListItem, Experiment


def set_cookie(response, key, value, days_expire = 7):
@@ -128,6 +127,7 @@ def product(request, task_pk):
set_cookie(response, 'USID', '%s::%s' % (userprofile.user_hash, tasklistitem.pk))
return response


def product_test(request, task_pk):
user = request.user
userprofile = user.userprofile
@@ -139,6 +139,7 @@ def product_test(request, task_pk):
set_cookie(response, 'USID', '%s::%s' % (userprofile.user_hash, tasklistitem.pk))
return response


def task_test(request, task_pk):
user = request.user
userprofile = user.userprofile
@@ -148,6 +149,7 @@ def task_test(request, task_pk):

return render(request, 'task.html', {'tasklistitem':tasklistitem})


def task_launch(request, task_pk):
tasklistitem = TaskListItem.objects.get(pk=task_pk)

@@ -222,13 +224,15 @@ def register(request):
# possibly change this to render task list - see notes above
return render_to_response('registration/register.html', {'registered': registered}, context)


def logout_participant(request):
"""
Log users out and re-direct them to the main page.
"""
logout(request)
return HttpResponseRedirect('/')


def login_participant(request):
# Like before, obtain the context for the user's request.
context = RequestContext(request)
@@ -276,6 +280,23 @@ def login_participant(request):

# return login_view(request, authentication_form=MyAuthForm)


def reset_confirm(request, uidb64=None, token=None):
return password_reset_confirm(request, template_name='registration/reset_password_confirm.html',
uidb64=uidb64, token=token,
post_reset_redirect=reverse('op_tasks:login'))


def reset(request):
return password_reset(request, template_name='registration/reset_password_form.html',
email_template_name='registration/reset_password_email.html',
post_reset_redirect=reverse('op_tasks:reset_sent'))


def reset_sent(request):
return render(request, 'registration/reset_password_done.html')


@login_required(login_url='/tasking/login')
def task_list(request):
# print [x.both_complete for x in userprofile.tasklistitem_set.all()]
@@ -321,14 +342,18 @@ def instruct(request, read=None):
first_task.save()
return render(request, 'instruction_home.html', {'user': request.user, 'product': product})


def exp_instruct(request):
return render(request, 'instructions/exp_instructions.html', {'user': request.user})


def portal_instruct(request):
return render(request, 'instructions/portal_instructions.html', {'user': request.user})


def product_instruct(request):
return render(request, 'instructions/product_instructions.html', {'user': request.user})


def view_profile(request):
return render(request, 'user_profile.html', {'user': request.user})
@@ -1,7 +1,4 @@
from django import forms

class DocumentForm(forms.Form):
docfile = forms.FileField(
label='Select a file',
help_text='max. 42 megabytes'
)
docfile = forms.FileField()
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('uploads', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='document',
name='dirPath',
field=models.CharField(default=b'abc', max_length=1000),
preserve_default=True,
),
migrations.AlterField(
model_name='document',
name='docfile',
field=models.FileField(upload_to=models.CharField(default=b'abc', max_length=1000)),
),
]
@@ -1,4 +1,8 @@
from django.db import models

def content_file_name(request, filename):
return '/'.join([request.POST['dirName'], filename])

class Document(models.Model):
docfile = models.FileField(upload_to='data')
dirPath = models.CharField(max_length=1000, default="abc")
docfile = models.FileField(upload_to=content_file_name)
@@ -5,22 +5,23 @@
<title>Master Answer Sheet Uploader</title>
</head>
<body>
<!-- List of uploaded documents -->
{% if documents %}
<ul>
{% for document in documents %}
<li><a href="{{ document.docfile.url }}">{{ document.docfile.name }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No documents.</p>
{% endif %}

<!-- Upload form. Note enctype attribute! -->
<form action="{% url 'list' %}" method="post" enctype="multipart/form-data">
<form action="{% url 'list' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div>
<h3>Folder:</h3>
<label for="dirName">Exp Name:</label>
<input type="text" name="dirName">
<select id="existingExpNames">
<option></option>
{% for experiment in experiments %}
<option>{{ experiment }}</option>
}
{% endfor %}
</select>
</div>
<p>{{ form.non_field_errors }}</p>
<p>{{ form.docfile.label_tag }} {{ form.docfile.help_text }}</p>
<p>
{{ form.docfile.errors }}
{{ form.docfile }}
@@ -1,8 +1,10 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import render
from op_tasks.models import Experiment
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse

import os

from models import Document
from forms import DocumentForm

@@ -11,21 +13,24 @@ def list(request):
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(docfile = request.FILES['docfile'])
newdoc.save()
handle_uploaded_file(request.FILES, request.POST.get('dirName', 'error'))

# redirect to the document after POST
return HttpResponseRedirect(reverse('uploads.views.list'))
# redirect to the document after POST
return HttpResponseRedirect(reverse('uploads.views.list'))

else:
form = DocumentForm() # An empty, unbound form
experiments = Experiment.objects.all()
# Render list page with the documents and the form
return render(request, 'list.html', {'form': form, 'experiments': experiments})

# Load documents for the list page
documents = Document.objects.all()

# Render list page with the documents and the form
return render_to_response(
'list.html',
{'documents': documents, 'form': form},
context_instance=RequestContext(request)
)
def handle_uploaded_file(f, dirname):
path = os.path.join('../', dirname)
try:
os.mkdir(path)
except:
pass
file = f['docfile']
with open(path + '/' + file.name, 'wb+') as destination:
for chunk in file.chunks():
destination.write(chunk)

0 comments on commit 6b3976e

Please sign in to comment.