Skip to content

Commit

Permalink
Merge pull request #1 from andela/ft-heroku-deployment-159396311
Browse files Browse the repository at this point in the history
  • Loading branch information
lym authored and RrNn committed Aug 2, 2018
2 parents e85134c + 8909bfb commit f578c12
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 40 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var/
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
package-lock.json

# Installer logs
pip-log.txt
Expand All @@ -46,7 +47,6 @@ coverage.xml

# Django stuff:
*.log
settings*.py
*.sqlite
/CACHE

Expand All @@ -58,7 +58,9 @@ target/

# IDE
.idea/
.vscode/
package-lock.json

# External Libraries
# External Libraries
wger/core/static/bower_components
node_modules
25 changes: 8 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ sudo: false

# Python versions to test
python:
- "2.7"
- "3.4"
- "3.5"

services:
- postgresql

# Manually define here the combinations environment variables to test
# https://github.com/travis-ci/travis-ci/issues/1519
env:
- TEST_MOBILE=True DB=postgresql TRAVIS_NODE_VERSION="4"
- TEST_MOBILE=True DB=sqlite TRAVIS_NODE_VERSION="4"
- TEST_MOBILE=False DB=postgresql TRAVIS_NODE_VERSION="4"
- TEST_MOBILE=False DB=sqlite TRAVIS_NODE_VERSION="4"

# Install the application
install:
Expand All @@ -39,29 +38,21 @@ install:

# Install requirements
- pip install -r requirements_devel.txt
- npm install
- if [[ "$DB" = "postgresql" ]]; then pip install psycopg2; fi
- pip install coverage
- pip install coveralls

# Setup application
- if [[ "$DB" = "sqlite" ]]; then invoke create_settings; fi
- if [[ "$DB" = "postgresql" ]]; then invoke create_settings --database-type postgresql; fi
- invoke create-settings --database-type postgresql

# Create test databases
before_script:
- if [[ "$DB" = "postgresq" ]]; then psql -c 'DROP DATABASE IF EXISTS test_wger;' -U postgres; fi
- if [[ "$DB" = "postgresql" ]]; then psql -c 'CREATE DATABASE test_wger;' -U postgres; fi
- psql -c 'DROP DATABASE IF EXISTS test_wger;' -U postgres
- psql -c 'CREATE DATABASE test_wger;' -U postgres

# Do the tests
script:
# Formatting
- pep8 wger

# Javascript linting
- gulp lint

# Regular application
- coverage run --source='.' ./manage.py test


# Code coverage
- coverage report
3 changes: 3 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
release: invoke migrate-db
web: gunicorn wger.wsgi:application

20 changes: 20 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "wger-bs-staging",
"scripts": {},
"env": {},
"formation": {
"web": {
"quantity": 1
}
},
"addons": [
"heroku-postgresql"
],
"buildpacks": [{
"url": "heroku/nodejs"
},
{
"url": "https://github.com/solnsubuga/heroku-buildpack-python"
}
]
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"eslint-plugin-react": "^6.1.2",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1"
},
"dependencies": {
"bower": "^1.8.4"
}
}
9 changes: 7 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

Django>=1.9,<1.10
django-recaptcha
django-recaptcha==1.3.1
reportlab
django_mobile
django-formtools>=1.0,<1.1
Expand All @@ -19,10 +19,15 @@ django-sortedm2m
django-bower
invoke
requests
gunicorn==19.8.1
python-decouple==3.1
dj-database-url==0.5.0
psycopg2-binary==2.7.5
whitenoise==3.3.1

# REST API
djangorestframework>=3.2,<3.3
django-filter
django-filter==1.1.0
django-tastypie
django-cors-headers

Expand Down
65 changes: 65 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from wger.settings_global import *
from decouple import config
import dj_database_url
import os

# Use 'DEBUG = True' to get more details for server errors
DEBUG = True
TEMPLATES[0]['OPTIONS']['debug'] = True

ADMINS = (
(os.environ.get('ADMIN_NAME'), os.environ.get('ADMIN_EMAIL')),
)
MANAGERS = ADMINS

if os.environ.get("DB") == 'postgresql':
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get('WGER_NAME') or 'wger',
'USER': os.environ.get('WGER_USER') or 'postgres',
'PASSWORD': os.environ.get('WGER_PASSWORD') or '',
'HOST': os.environ.get('WGER_HOST') or 'localhost',
'PORT': os.environ.get('WGER_PORT') or '',
}
}

if os.environ.get("DB") == "heroku":
DATABASES = {
'default': dj_database_url.config(default=config('DATABASE_URL'))
}


# Your reCaptcha keys
RECAPTCHA_PUBLIC_KEY = ''
RECAPTCHA_PRIVATE_KEY = ''
NOCAPTCHA = True

# The site's URL (e.g. http://www.my-local-gym.com or http://localhost:8000)
# This is needed for uploaded files and images (exercise images, etc.) to be
# properly served.
SITE_URL = 'http://localhost:8000'

# Path to uploaded files
# Absolute filesystem path to the directory that will hold user-uploaded files.
MEDIA_ROOT = ''
MEDIA_URL = '/media/'

# Allow all hosts to access the application. Change if used in production.
ALLOWED_HOSTS = '*'

# This might be a good idea if you setup memcached
#SESSION_ENGINE = "django.contrib.sessions.backends.cache"

# Configure a real backend in production
if DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

# Sender address used for sent emails
WGER_SETTINGS['EMAIL_FROM'] = 'wger Workout Manager <wger@example.com>'

# Your twitter handle, if you have one for this instance.
#WGER_SETTINGS['TWITTER'] = ''
2 changes: 1 addition & 1 deletion wger/core/templates/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<li><a href="{% url 'core:weight-unit:list' %}">{% trans "Weight units" %} </a></li>
{% endif %}
{% if perms.gym.manage_gyms %}
<li><a href="{% url 'core:user:list' %}">{% trans "User list" %} </a></li>
<li><a href="{% url 'core:user:list'%}">{% trans "User list" %} </a></li>
<li><a href="{% url 'gym:gym:list' %}">{% trans "Gyms" %} </a></li>
{% endif %}

Expand Down
38 changes: 37 additions & 1 deletion wger/core/templates/user/list.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
{% extends "base.html" %}
{% load i18n staticfiles wger_extras django_bootstrap_breadcrumbs %}

{% block title %}{% trans "User list" %}{% endblock %}
{% block title %}
<a href="{% url 'core:user:list'%}" id="active_users_link"
style="visibility: hidden">Check</a>

<a href="{% url 'core:user:list_filtered' filtered=True%}" id="inactive_users_link"
style="visibility: hidden">Check</a>

{% if user_table.active == False %}
{% trans "Active Users" %}&nbsp;
<span>
<a id="active" class="btn btn-sm btn-primary" name={{ user_table.active }}
role="button">
</a>
</span>
{% else %}
{% trans "Inactive Users" %}&nbsp;
<span>
<a id="active" class="btn btn-sm btn-primary" name={{ user_table.active }}
role="button">
</a>
</span>
{% endif %}
{% endblock %}

{% block content %}
{% include 'gym/partial_user_list.html' %}
<script>
active = document.getElementById('active')
let active_users_link = document.getElementById('active_users_link')
let inactive_users_link = document.getElementById('inactive_users_link')
if (active.name == "True"){
active.setAttribute('href',active_users_link)
active.innerHTML="View Active Users"
}
else{
active.setAttribute('href',inactive_users_link)
active.innerHTML="View Inactive Users"
}
</script>
{% endblock %}


{% block sidebar %}

{% endblock %}


7 changes: 6 additions & 1 deletion wger/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@
url(r'^(?P<pk>\d+)/overview',
user.UserDetailView.as_view(),
name='overview'),
url(r'^list',
url(r'^list/',
user.UserListView.as_view(),
name='list'),

url(r'^list_filtered/(?P<filtered>[\w-]+)',
user.UserListView.as_view(),
name='list_filtered'),


# Password reset is implemented by Django, no need to cook our own soup here
# (besides the templates)
url(r'^password/change$',
Expand Down
31 changes: 26 additions & 5 deletions wger/core/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,24 +496,43 @@ def get_context_data(self, **kwargs):


class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):

'''
Overview of all users in the instance
'''
model = User
permission_required = ('gym.manage_gyms',)
permission_required = ('gym.manage_gyms')
template_name = 'user/list.html'


def get_queryset(self):
filtered = self.request.GET.get('filtered')
'''
Return a list with the users, not really a queryset.
'''
out = {'admins': [],
'members': []}
if bool(self.kwargs):
active_users = True
self.active = True
else:
active_users = False
self.active = False


for u in User.objects.select_related('usercache', 'userprofile__gym').all():
out['members'].append({'obj': u,
'last_log': u.usercache.last_activity})
# active_users = False if self.kwargs['filtered'] == 'False' else True
if not active_users:
for u in User.objects.select_related('usercache', 'userprofile__gym').all().\
filter(is_active=True):
out['members'].append({'obj': u,
'last_log': u.usercache.last_activity})
else:
for u in User.objects.select_related('usercache', 'userprofile__gym').all().\
filter(is_active=False):
out['members'].append({'obj': u,
'last_log': u.usercache.last_activity})


return out

def get_context_data(self, **kwargs):
Expand All @@ -527,5 +546,7 @@ def get_context_data(self, **kwargs):
_('Name'),
_('Last activity'),
_('Gym')],
'users': context['object_list']['members']}
'users': context['object_list']['members'],
'active':self.active}
return context

3 changes: 2 additions & 1 deletion wger/manager/views/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
from wger.utils.pdf import styleSheet
from wger.utils.pdf import render_footer

from reportlab.lib.pagesizes import A4, cm
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import cm
from reportlab.platypus import (
Paragraph,
SimpleDocTemplate,
Expand Down
5 changes: 3 additions & 2 deletions wger/nutrition/views/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
from django.views.generic import DeleteView, UpdateView

from reportlab.lib import colors
from reportlab.lib.pagesizes import A4, cm
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import cm
from reportlab.platypus import (
Paragraph,
SimpleDocTemplate,
Expand Down Expand Up @@ -316,7 +317,7 @@ def export_pdf(request, id, uidb64=None, token=None):
# Create table with nutritional calculations
data = []
data.append([Paragraph(u'<para align="center">{0}</para>'.format(_('Nutritional data')),
styleSheet["Bold"])])
styleSheet["Bold"])])
data.append([Paragraph(_('Macronutrients'), styleSheet["Normal"]),
Paragraph(_('Total'), styleSheet["Normal"]),
Paragraph(_('Percent of energy'), styleSheet["Normal"]),
Expand Down
Loading

0 comments on commit f578c12

Please sign in to comment.