Skip to content

Commit

Permalink
Fixed renaming entities led to no images bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jose.correia committed Oct 6, 2019
1 parent b53160a commit 4ee97a8
Show file tree
Hide file tree
Showing 23 changed files with 148 additions and 25 deletions.
13 changes: 8 additions & 5 deletions jeec_brain/apps/admin_api/companies/routes.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from .. import bp
from flask import render_template, request, redirect, url_for, current_app
from flask_login import current_user

# handlers
from jeec_brain.handlers.companies_handler import CompaniesHandler

# finders
from jeec_brain.finders.companies_finder import CompaniesFinder

# values
from jeec_brain.values.api_error_value import APIErrorValue

from jeec_brain.apps.auth.wrappers import allowed_roles, allow_all_roles
# services
from jeec_brain.services.files.rename_image_service import RenameImageService



@bp.route('/companies', methods=['GET'])
Expand Down Expand Up @@ -121,7 +120,8 @@ def update_company(company_external_id):
access_cv_platform = False

image_path = CompaniesHandler.find_image(name)

old_company_name = company.name

updated_company = CompaniesHandler.update_company(
company=company,
name=name,
Expand All @@ -135,6 +135,9 @@ def update_company(company_external_id):
if updated_company is None:
return render_template('admin/companies/update_company.html', company=company, image=image_path, error="Failed to update company!")

if old_company_name != name:
RenameImageService('static/companies', old_company_name, name).call()

if 'file' in request.files:
file = request.files['file']

Expand Down
100 changes: 100 additions & 0 deletions jeec_brain/apps/admin_api/event/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from .. import bp
from flask import render_template, current_app, request, redirect, url_for
from jeec_brain.handlers.event_handler import EventHandler
from jeec_brain.services.users.get_roles_service import GetRolesService
from jeec_brain.apps.auth.wrappers import allowed_roles
from jeec_brain.models.enums.roles_enum import RolesEnum
from flask_login import current_user


@bp.route('/new-event', methods=['GET'])
@allowed_roles(['admin')
def add_event_dashboard():
return render_template('admin/event/add_event.html', \
error=None)


@bp.route('/new-event', methods=['POST'])
@allowed_roles(['admin'])
def create_event():
# extract form parameters
name = request.form.get('name')
date = request.form.get('date')
email = request.form.get('email')
address = request.form.get('address')
facebook_link = request.form.get('facebook_link')
youtube_link = request.form.get('youtube_link')
instagram_link = request.form.get('instagram_link')

# create new user
event = EventHandler.create_event(
name=name,
date=date,
email=email,
address=address,
facebook_link=facebook_link,
youtube_link=youtube_link,
instagram_link=instagram_link
)

if user is None:
return render_template('admin/event/add_event.html', \
error="Failed to create event!")

return redirect(url_for('admin_api.get_event'))


@bp.route('/event', methods=['GET'])
@allowed_roles(['admin')
def get_event():
event = EventsFinder.get_event()

if event is None:
return render_template(url_for('admin_api.add_event_dashboard'))

logo = EventHandler.find_logo()
logo_mobile = EventHandler.find_logo_mobile()
return render_template('admin/event/update_event.html', company=company, image=image_path, error=None)


@bp.route('/company/<string:company_external_id>', methods=['POST'])
@allowed_roles(['admin', 'companies_admin'])
def update_company(company_external_id):

company = CompaniesFinder.get_from_external_id(company_external_id)

if company is None:
return APIErrorValue('Couldnt find company').json(500)

name = request.form.get('name')
date = request.form.get('date')
email = request.form.get('email')
address = request.form.get('address')
facebook_link = request.form.get('facebook_link')
youtube_link = request.form.get('youtube_link')
instagram_link = request.form.get('instagram_link')

image_path = CompaniesHandler.find_image(name)

updated_event = EventHandler.update_event(
name=name,
date=date,
email=email,
address=address,
facebook_link=facebook_link,
youtube_link=youtube_link,
instagram_link=instagram_link
)

if updated_event is None:
return render_template('admin/event/update_event.html', event=event, image=image_path, error="Failed to update company!")

if 'file' in request.files:
file = request.files['file']

result, msg = CompaniesHandler.upload_image(file, name)

if result == False:
return render_template('admin/companies/update_company.html', company=updated_company, image=image_path, error=msg)

return redirect(url_for('admin_api.companies_dashboard'))
14 changes: 14 additions & 0 deletions jeec_brain/apps/admin_api/speakers/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from jeec_brain.apps.auth.wrappers import allowed_roles, allow_all_roles
from jeec_brain.values.api_error_value import APIErrorValue
from flask_login import current_user
from jeec_brain.services.files.rename_image_service import RenameImageService


@bp.route('/speakers', methods=['GET'])
Expand Down Expand Up @@ -138,6 +139,9 @@ def update_speaker(speaker_external_id):
image_path = SpeakersHandler.find_image(name)
company_logo_path = SpeakersHandler.find_company_logo(company)

old_speaker_name = speaker.name
old_company_name = speaker.company

updated_speaker = SpeakersHandler.update_speaker(
speaker=speaker,
name=name,
Expand All @@ -159,6 +163,11 @@ def update_speaker(speaker_external_id):
company_logo=company_logo_path, \
error="Failed to update speaker!")


# Handle Speaker image ------------------------------------
if old_speaker_name != name:
RenameImageService('static/speakers', old_speaker_name, name).call()

if 'file' in request.files:
file = request.files['file']

Expand All @@ -170,6 +179,11 @@ def update_speaker(speaker_external_id):
image=image_path, \
company_logo=company_logo_path, \
error=msg)


# Handle Speaker's Company image ---------------------------
if old_company_name != company:
RenameImageService('static/speakers/companies', old_company_name, company).call()

if updated_speaker.company and 'company_logo' in request.files:
file = request.files['company_logo']
Expand Down
6 changes: 6 additions & 0 deletions jeec_brain/apps/admin_api/team/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from jeec_brain.apps.auth.wrappers import allowed_roles, allow_all_roles
from jeec_brain.values.api_error_value import APIErrorValue
from flask_login import current_user
from jeec_brain.services.files.rename_image_service import RenameImageService


# Team management
Expand Down Expand Up @@ -219,6 +220,8 @@ def update_team_member(team_external_id, member_external_id):
email = request.form.get('email')
linkedin_url = request.form.get('linkedin_url')

old_member_name = member.name

updated_member = TeamsHandler.update_team_member(
member=member,
name=name,
Expand All @@ -232,6 +235,9 @@ def update_team_member(team_external_id, member_external_id):
if updated_member is None:
return render_template('admin/teams/update_team_member.html', member=member, image=image_path, error="Failed to update team member!")

if old_member_name != name:
RenameImageService('static/members', old_member_name, name).call()

if 'file' in request.files:
file = request.files['file']

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/activities/add_activity.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/activities/update_activity.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/admin_login.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>

<head>
<title>Admin|Login</title>
<title>JEEC|Brain</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no,maximum-scale=1">
<link rel="stylesheet" href="/static/admin/css/admin_login.css">
<link rel="stylesheet" href="/static/admin/css/global.css">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/companies/add_company.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/companies/update_company.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
4 changes: 2 additions & 2 deletions jeec_brain/templates/admin/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down Expand Up @@ -58,7 +58,7 @@ <h2>JEEC Brain</h2>
<form action="{{ url_for('admin_api.users_dashboard') }}" method="get">
<button class="waves-effect blue lighten-2 btn-large dashboard-btn"><i class="large material-icons left">lock</i>Users</button>
</form>
</div>
</div>
{% endif %}

<blockquote style="margin-left: 40px;margin-top: 70px;">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/speakers/add_speaker.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/speakers/update_speaker.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/teams/add_team.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/teams/add_team_member.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/teams/teams_dashboard.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/teams/update_team.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/teams/update_team_member.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/users/add_user.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down
2 changes: 1 addition & 1 deletion jeec_brain/templates/admin/users/users_dashboard.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>JEEC|Admin</title>
<title>JEEC|Brain</title>
<link rel="stylesheet" href="/static/admin/css/global.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down

0 comments on commit 4ee97a8

Please sign in to comment.