Skip to content

Commit

Permalink
Merge pull request #116 from codethechange/develop
Browse files Browse the repository at this point in the history
Release v0.2.0-beta
  • Loading branch information
U8NWXD authored Jan 26, 2019
2 parents 5359de0 + ed27e37 commit 61aadcd
Show file tree
Hide file tree
Showing 17 changed files with 297 additions and 43 deletions.
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitsecrets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[0-9A-Za-z]{32}
27 changes: 16 additions & 11 deletions culturemesh/blueprints/events/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from culturemesh.utils import get_network_title
from culturemesh.utils import get_event_location
from culturemesh.utils import safe_get_query_arg
from culturemesh.utils import is_logged_in

from culturemesh.blueprints.events.forms.event_forms import *
from culturemesh.blueprints.networks.utils import gather_network_info
Expand All @@ -24,7 +25,6 @@ def ping():
return c.ping_event()

@events.route("/")
@login_required
def render_event():
current_event_id = request.args.get('id')
c = Client(mock=False)
Expand All @@ -40,27 +40,32 @@ def render_event():

role = None

if event['id_host'] == current_user.id:
if is_logged_in(current_user):
user_id = current_user.id
if event['id_host'] == user_id:

# The current user is hosting this event.
role = 'hosting'
host['username'] = 'you'

# The current user is hosting this event.
role = 'hosting'
host['username'] = 'you'
elif user_is_attending_event(c, user_id, event):

elif user_is_attending_event(c, current_user.id, event):
# The current user is already signed up for this event.
role = 'attending'
else:

# The current user is already signed up for this event.
role = 'attending'
# The current user is not signed up for this event.
pass
else:
user_id = None

# The current user is not signed up for this event.
pass

return render_template(
'event.html',
event=event,
host=host,
role=role,
curr_user_id=current_user.id,
curr_user_id=user_id,
join_form=EventJoinForm(),
leave_form=EventLeaveForm(),
cancel_form=EventCancelForm()
Expand Down
34 changes: 16 additions & 18 deletions culturemesh/blueprints/networks/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from culturemesh.utils import get_network_title
from culturemesh.utils import get_upcoming_events_by_network
from culturemesh.utils import get_time_ago
from culturemesh.utils import is_logged_in
from utils import parse_date

from culturemesh.blueprints.networks.forms.network_forms import NetworkJoinForm
Expand All @@ -22,13 +23,12 @@
utc=pytz.UTC

@networks.route("/")
@flask_login.login_required
def network():
id_network = request.args.get('id')
c = Client(mock=False)
id_user = current_user.id
network_info = gather_network_info(id_network, id_user, c)

id_user = current_user.get_id()
network_info = gather_network_info(id_network, id_user, c)
upcoming_events = get_upcoming_events_by_network(c, id_network, 3)

return render_template(
Expand All @@ -54,7 +54,6 @@ def join_network():
)

@networks.route("/events/")
@flask_login.login_required
def network_events() :
# TODO: A lot of this code is repeated from network(), with just minor variations.
# This should be factored out.
Expand Down Expand Up @@ -93,13 +92,14 @@ def network_events() :
utils.enhance_event_date_info(event)
event['num_registered'] = c.get_event_reg_count(event['id'])['reg_count']

id_user = current_user.id
user_networks = c.get_user_networks(id_user, count=100)
user_is_member = False
for network_ in user_networks:
if int(id_network) == int(network_['id']):
user_is_member = True
break

if is_logged_in(current_user):
user_networks = c.get_user_networks(current_user.get_id(), count=100)
for network_ in user_networks:
if int(id_network) == int(network_['id']):
user_is_member = True
break

network_info = {}
network_info['id'] = id_network
Expand All @@ -121,7 +121,6 @@ def network_events() :
)

@networks.route("/posts/")
@flask_login.login_required
def network_posts() :
# TODO: A lot of this code is repeated from network(), with just minor variations.
# This should be factored out.
Expand Down Expand Up @@ -165,13 +164,13 @@ def network_posts() :
else :
post_index = posts[-1]['id']

id_user = current_user.id
user_networks = c.get_user_networks(id_user, count=100)
user_is_member = False
for network_ in user_networks:
if int(id_network) == int(network_['id']):
user_is_member = True
break
if is_logged_in(current_user):
user_networks = c.get_user_networks(current_user.get_id(), count=100)
for network_ in user_networks:
if int(id_network) == int(network_['id']):
user_is_member = True
break

network_info = {}
network_info['id'] = id_network
Expand Down Expand Up @@ -366,4 +365,3 @@ def leave():
def ping():
c = Client(mock=False)
return c.ping_network()

11 changes: 6 additions & 5 deletions culturemesh/blueprints/networks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ def gather_network_info(id_network, id_user, client, scenario="normal"):
post['reply_count'] = client.get_post_reply_count(post['id'])['reply_count']
post['time_ago'] = get_time_ago(post['post_date'])

user_networks = client.get_user_networks(id_user, count=100)
user_is_member = False
for network_ in user_networks:
if int(id_network) == int(network_['id']):
user_is_member = True
break
if not id_user == None:
user_networks = client.get_user_networks(id_user, count=100)
for network_ in user_networks:
if int(id_network) == int(network_['id']):
user_is_member = True
break

network_info = {}
network_info['id'] = id_network
Expand Down
8 changes: 6 additions & 2 deletions culturemesh/blueprints/posts/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from culturemesh.utils import get_time_ago
from culturemesh.utils import get_network_title
from culturemesh.utils import safe_get_query_arg
from culturemesh.utils import is_logged_in

from culturemesh.blueprints.posts.forms.post_forms import *

Expand All @@ -16,12 +17,11 @@
posts = Blueprint('posts', __name__, template_folder='templates')

@posts.route("/", methods=['GET', 'POST'])
@flask_login.login_required
def render_post():

current_post_id = safe_get_query_arg(request, 'id')

user_id = current_user.id
user_id = current_user.get_id()
c = Client(mock=False)
post = c.get_post(current_post_id)

Expand All @@ -41,6 +41,10 @@ def render_post():

if request.method == 'GET':
pass
elif not is_logged_in(current_user):
return redirect(
url_for('render_login_page')
)
else:
data = request.form
form_submitted = CreatePostReplyForm(request.form)
Expand Down
2 changes: 1 addition & 1 deletion culturemesh/blueprints/user_home/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def update_profile_and_render_home():
'id': user_id, 'first_name': first_name,
'last_name': last_name, 'about_me': about_me
}

if form.validate():
c.update_user(current_user, user)

Expand Down
1 change: 0 additions & 1 deletion culturemesh/blueprints/users/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
users = Blueprint('users', __name__, template_folder='templates')

@users.route('/<int:user_id>/', methods=['GET'])
@flask_login.login_required
def user_profile(user_id):

c = Client(mock=False)
Expand Down
3 changes: 3 additions & 0 deletions culturemesh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,6 @@ def user_is_attending_event(client, user_id, event):
if user_id == reg['id_guest']:
return True
return False

def is_logged_in(current_user):
return current_user.get_id() != None
1 change: 0 additions & 1 deletion culturemesh/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,3 @@ def page_not_found(e):
@app.errorhandler(httplib.METHOD_NOT_ALLOWED)
def internal_server_error(e):
return render_template('error.html')

24 changes: 24 additions & 0 deletions dev/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

# Inspired by RJ Zaworski's blog post at
# https://rjzaworski.com/2018/01/keeping-git-hooks-in-sync

set -e

install_hooks() {
rm -rf ./.git/hooks
cp -r ./dev/hooks ./.git/hooks
}

log() {
echo "$1"
}

if [ ! -d ".git" ]; then {
log "Aborting because you are not at the root of a git repository"
exit 1
}
fi

log "Configuring git hooks"
install_hooks
6 changes: 6 additions & 0 deletions dev/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

# Pre-commit hook to run before each commit

# Check that no secrets are about to be committed
git secrets scan
21 changes: 17 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
alabaster==0.7.11
atomicwrites==1.2.1
attrs==18.2.0
Babel==2.6.0
blinker==1.4
certifi==2018.8.13
chardet==3.0.4
click==6.7
Click==7.0
colorama==0.3.9
coverage==4.5.2
docutils==0.14
Flask==0.12.2
Flask==1.0.2
Flask-BabelEx==0.9.3
Flask-Login==0.4.1
Flask-Mail==0.9.1
Expand All @@ -22,20 +25,30 @@ itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
mccabe==0.6.1
mock==2.0.0
more-itertools==5.0.0
nose==1.3.7
packaging==17.1
passlib==1.7.1
pbr==5.1.1
pluggy==0.8.0
py==1.7.0
Pygments==2.2.0
pyparsing==2.2.0
pytest==4.1.0
pytest-cov==2.6.1
pytest-mock==1.10.0
python-dateutil==2.7.3
pytz==2018.3
qpp-git-secrets==1.1.1
requests==2.20.1
six==1.11.0
snowballstemmer==1.2.1
speaklater==1.3
Sphinx==1.7.6
sphinx-rtd-theme==0.4.1
sphinxcontrib-websupport==1.1.0
urllib3==1.22
Werkzeug==0.12.2
unidiff==0.5.5
urllib3==1.24.1
Werkzeug==0.14.1
WTForms==2.1
7 changes: 7 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

export CULTUREMESH_API_KEY=1234
export WTF_CSRF_SECRET_KEY=1234
export CULTUREMESH_API_BASE_ENDPOINT=https://www.culturemesh.com/api-dev/v1

python -m pytest
57 changes: 57 additions & 0 deletions test/unit/webapp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import pytest
from culturemesh import app

"""Initialize the testing environment
Creates an app for testing that has the configuration flag ``TESTING`` set to
``True``.
"""

# The following function is derived from an example in the Flask documentation
# found at the following URL: http://flask.pocoo.org/docs/1.0/testing/. The
# Flask license statement has been included below as attribution.
#
# Copyright (c) 2010 by the Pallets team.
#
# Some rights reserved.
#
# Redistribution and use in source and binary forms of the software as well as
# documentation, with or without modification, are permitted provided that the
# following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE AND DOCUMENTATION, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


@pytest.fixture
def client():
"""Configures the app for testing
Sets app config variable ``TESTING`` to ``True``
:return: App for testing
"""

#app.config['TESTING'] = True
client = app.test_client()

yield client
Loading

0 comments on commit 61aadcd

Please sign in to comment.