Skip to content

Commit

Permalink
Merge pull request OpenHumans#2 from madprime/master
Browse files Browse the repository at this point in the history
Switch yaml/env to db-based configuration
  • Loading branch information
gedankenstuecke authored Jan 30, 2018
2 parents 15b7947 + 870b686 commit 574c41f
Show file tree
Hide file tree
Showing 35 changed files with 605 additions and 103 deletions.
25 changes: 22 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
DATABASE_URL=postgres:///myurl
################################
# #
# THIS IS A SECRET FILE!!! #
# #
# Do not add your .env to git! #
# #
################################

# SECRET_KEY encrypts things. In production it should be a random string.
SECRET_KEY=mysecretshouldnotbeongit
OH_CLIENT_ID=myclientidshouldnotbeongit
OH_CLIENT_SECRET=myclientsecretshouldnotbeongit

# ADMIN_PASSWORD is how you log in to manage this app and configuration.
ADMIN_PASSWORD=''

# Optional, but you probably want this for logging and debugging.
PYTHONUNBUFFERED='true'

# Set DATABASE_URL to use something other than the default SQLite.
# DATABASE_URL=postgres:///myurl

# Set app base URL. If unset, defaults to http://127.0.0.1:5000 local,
# and herokuapp.com URL on Heroku.
# APP_BASE_URL='http://127.0.0.1:5000'
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Bastian Greshake Tzovaras
Copyright (c) 2018 Bastian Greshake Tzovaras, Mad Price Ball

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
release: python manage.py migrate
web: gunicorn oh_data_uploader.wsgi --log-file=-
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
> *it's like Jekyll for Open Humans*
or something along the lines.

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)

Ultimately this should be an easy to deploy Django project that functions as a
file uploader for individual *Open Humans* projects. It should be easy deploy to
*heroku* and the configuration/styling of the project website should be done more
Expand All @@ -24,17 +26,23 @@ conda create -n oh_uploader python=3.6
pip install -r requirements.txt
```

*Step 2: Install heroku-CLI & PostgreSQL*
*Step 2: Install Heroku Command Line Interface (CLI)*

You should install the Heroku CLI to run this app. Heroku has [installation instructions for MacOS, Windows, and Linux](https://devcenter.heroku.com/articles/heroku-cli#download-and-install).

If you are running MacOS the easiest way to do this is using [Homebrew](https://brew.sh/). If you are on a Linux machine you [should be able to do the same things using Linuxbrew](https://virtualenv.pypa.io/en/stable/). After installing Homebrew/Linuxbrew
you can do:
If you are running MacOS the easiest way to do this is using [Homebrew](https://brew.sh/). After installing Homebrew you can do:

```
brew install postgres
brew install heroku/brew/heroku
```

Once this is done you can start the setup of your *Open Humans uploader* by copying the example `.env` file (`cp .env.sample .env`) and entering at least your database URL. Once this is done you can migrate your database using `heroku local:run python manage.py migrate`. Afterwards you can start the webserver of your local heroku environment using `heroku local`.
Once this is done you can complete minimal setup by:
* Create an `.env` file from the example: `cp .env.sample .env`)
* Edit `.env` to set a random string for `DJANGO_SECRET`
* Migrate your database using `heroku local:run python manage.py migrate`
* Initialize config with `heroku local:run python manage.py init_proj_config`

Now you can run the webserver of your local heroku environment using `heroku local`.

To fully set up your uploader you will have to modify some files, as described below.

Expand Down Expand Up @@ -97,7 +105,7 @@ prominently on the front page.

```
# Give the path to the logo of your project.
logo: ' static/example_logo.png'
logo: ' static/default_logo.png'
# Is there a larger project website where more info might be located?
more_info_link: http://www.github.com/gedankenstuecke/oh_data_uploader
Expand Down
23 changes: 12 additions & 11 deletions _descriptions/index.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# What does my project do?
This tool allows you to easily setup your own *Open Humans* project that wants
to collect data. You just need to set up some configuration files before you
can deploy it *heroku*.
to collect data.

The configuration files are:
The configuration for this project is in:

- `config.yaml` in the main directory of this git repository. This contains details
on your project that aren't secret like the title, description, where the logo can be found etc.
- The `.env` contains the secret details that shouldn't be shared. E.g. your database setup,
your *Open Humans* API keys etc.
- The texts that should be displayed on this project website. In `_descriptions` you can find the
markdown files needed to customize this template. E.g. this page is written in `_descriptions/index.md`.
- **Environment variables:** If you deploy to Heroku, you'll probably be
prompted to provide these, and they can be modified in the the app. Locally,
your `.env` file defines these. These are secret details that should not be
shared. (Be sure not to add this to your git repository!)
- **Project configuration:** The [Project Admin page](/project-admin) can be
used to configure other aspects of your site. Log in with the `ADMIN_PASSWORD`
you set in environment variables.

Use this page to inform your users about what your project is about and what it tries to do. It's the first
page they will see, so be verbose!
As you configure the project, replace this "front page" text to inform
users what your project is about and what it tries to do. It's the first page
they will see, so be verbose!
23 changes: 23 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Open Humans Data Uploader",
"description": "A web app to support data uploads to an Open Humans project",
"repository": "https://github.com/madprime/oh_data_uploader",
"keywords": ["django"],
"scripts": {
"postdeploy": "python manage.py init_proj_config"
},
"env": {
"HEROKUCONFIG_APP_NAME": {
"description": "Heroku \"App name\" (copy/paste what you set above)",
"required": true
},
"ADMIN_PASSWORD": {
"description": "You'll use this password to manage configuring this app.",
"required": true
},
"SECRET_KEY": {
"description": "This is set for you and is used to encrypt data.",
"generator": "secret"
}
}
}
26 changes: 0 additions & 26 deletions config.yaml

This file was deleted.

8 changes: 5 additions & 3 deletions oh_connection/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.conf import settings
from project_admin.models import ProjectConfiguration


def read_config(request):
context = {'yaml_config': settings.YAML_CONFIG,
'oh_proj_page': settings.YAML_CONFIG['oh_activity_page']}
config = ProjectConfiguration.objects.get(id=1)
context = {'config': config,
'is_admin': request.user.username == 'admin',
'oh_proj_page': config.oh_activity_page}
return context
14 changes: 12 additions & 2 deletions oh_connection/templates/oh_connection/application.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>{{yaml_config.project_title}}</title>
<title>{{config.project_title}}</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,700' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=PT+Serif:400,700,400italic' rel='stylesheet' type='text/css'>
<link href='https://netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.css' rel='stylesheet' type='text/css'>
Expand Down Expand Up @@ -73,18 +73,28 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'index' %}">{{yaml_config.project_title}}</a>
<a class="navbar-brand" href="{% url 'index' %}">{{config.project_title}}</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li {% if section == 'home' %} class="active" {%endif%}>
<a href="{% url 'index' %}">Home</a>
</li>
{% if is_admin %}
<li>
<a href="{% url 'project-admin:home' %}">Project config</a>
</li>
{% endif %}
</ul>
<ul class="nav navbar-nav navbar-right">
<li {% if section == 'about' %} class="active" {%endif%}>
<a href="{% url 'about' %}">About</a>
</li>
{% if request.user.is_authenticated %}
<li>
<form action="{% url 'logout' %}" method="post">{% csrf_token %}<input type="submit" value="Log out" style="margin-top:12px;"></form>
</li>
{% endif %}
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
Expand Down
2 changes: 1 addition & 1 deletion oh_connection/templates/oh_connection/complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block content %}

<h1>One last step: Uploading your data to {{yaml_config.project_title}}</h1>
<h1>One last step: Uploading your data to {{config.project_title}}</h1>
<p class="lead">
Thank you! We got your authorization to connect to <i>Open Humans</i>.
</p>
Expand Down
12 changes: 6 additions & 6 deletions oh_connection/templates/oh_connection/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
{% block content %}

<div class="jumbotron">
<img alt="Brand" src="{{yaml_config.logo}}" height="150px" align="left">
<h1>Welcome to {{yaml_config.project_title}}</h1>
<img alt="Brand" src="{% if config.logo_url %}{{config.logo_url}}{% else %}/static/default_logo.png{% endif %}" height="150px" align="left">
<h1>Welcome to {{config.project_title}}</h1>
<p>
{{yaml_config.project_description}}
{{config.project_description}}
</p>
</div>

Expand All @@ -19,13 +19,13 @@ <h1>Welcome to {{yaml_config.project_title}}</h1>
<h2>How it works</h2>
<ol>
<li><b>Log in or create an Open Humans account</b><br>
You can upload your data for <i>{{yaml_config.project_title}}</i>
You can upload your data for <i>{{config.project_title}}</i>
once you have done this.
</li>
<li><b>Authorize {{yaml_config.project_title}} on <i>Open Humans</i></b><br>
<li><b>Authorize {{config.project_title}} on <i>Open Humans</i></b><br>
This authorizes us to deposit your archive into your Open Humans account.</li>
<li><b>Upload your data.</b><br>
You will be redirected back to {{yaml_config.project_title}} and can then
You will be redirected back to {{config.project_title}} and can then
upload your data.
You'll be able to
<a href="{{ oh_proj_page }}">access &amp; manage your data on
Expand Down
2 changes: 1 addition & 1 deletion oh_connection/templates/oh_connection/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block content %}

<h1>Manage your {{yaml_config.project_title}} data.</h1>
<h1>Manage your {{config.project_title}} data.</h1>
<p class="lead">
Thank you! We logged you in through <i>Open Humans</i>.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
replacement = '<h3>Your Upload started</h3><div class="progress"><div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 45%"></div></div>'
$("#upload_form").replaceWith('<div id="upload_form">'+replacement+'</div>');
var xhr = new XMLHttpRequest();
var metadata = JSON.stringify({"tags":{{yaml_config.file_tags|safe}},"description" : '{{yaml_config.file_description}}'});
var metadata = JSON.stringify({"tags":{{config.file_tags|safe}},"description" : '{{config.file_description}}'});
xhr.open('POST', "https://www.openhumans.org/api/direct-sharing/project/files/upload/direct/?access_token={{oh_member.access_token}}", true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send('project_member_id={{oh_member.oh_id}}&filename='+file['name']+'&metadata='+metadata);
Expand Down
1 change: 1 addition & 0 deletions oh_connection/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^complete/?$', views.complete, name='complete'),
url(r'^logout/?$', views.logout_user, name='logout'),
url(r'^overview/?$', views.overview, name='overview'),
url(r'^upload_simple/?$', views.upload_old, name='upload_old'),
url(r'^about/?$', views.about, name='about')
Expand Down
Loading

0 comments on commit 574c41f

Please sign in to comment.