This repository was archived by the owner on Jan 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Liraisokay issues 50 57 #58
Open
liraisokay
wants to merge
7
commits into
dev
Choose a base branch
from
liraisokay-issues-50-57
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
321d641
Issue #51: podcast upload form implementation changed
liraisokay 0f48e9c
issue #50: feed implementation changed
liraisokay cadade3
issue #55: database schema is created, if it does not exist
liraisokay 9f6a620
Issue #56: redirect to upload podcast
liraisokay 8bd3553
Issue #57: fixed
liraisokay 0921c3a
issue #54: fixed
liraisokay 5312e28
Issues #52 and #53: access control fixed, edit profile form is splitt…
liraisokay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,18 @@ | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import sqlalchemy | ||
| from flask import url_for | ||
| from werkzeug.security import generate_password_hash, check_password_hash | ||
| from flask_login import UserMixin | ||
|
|
||
| from app import app, db, login_manager | ||
| from .audio_utils import concatenate_audios, text_to_speech | ||
|
|
||
|
|
||
| class User(UserMixin, db.Model): | ||
| id = db.Column(db.Integer, primary_key=True) | ||
| username = db.Column(db.String(64), index=True, | ||
| unique=True, nullable=False) | ||
| email = db.Column(db.String(120), index=True, unique=True, nullable=False) | ||
| username = db.Column(db.String(64), index=True, unique=True, nullable=False) | ||
| email = db.Column(db.String(120), index=True, nullable=False) | ||
| password_hash = db.Column(db.String(128), nullable=False) | ||
| is_admin = db.Column(db.Boolean, default=False, nullable=False) | ||
|
|
||
|
|
@@ -39,31 +40,17 @@ def __repr__(self): | |
| return f'<Episode id: {self.id}>, name: {self.name}' | ||
|
|
||
| def get_file_path(self): | ||
| ''' | ||
| Return wrapped in jingles file path | ||
| ''' | ||
| media_path = os.path.join(app.config.get('MEDIA_ROOT'), 'episodes') | ||
| file_path = f'{media_path}/{self.id}.mp3' | ||
| file_path = os.path.join(app.config.get('MEDIA_ROOT'), 'episodes', f'{self.id}.mp3') | ||
| if os.path.exists(file_path): | ||
| return file_path | ||
|
|
||
| # todo: add to celery task | ||
| def generate_wrapped_file(self, episode_path): | ||
| """ | ||
| Concatenate an episode name mp3 file and an episode mp3 file | ||
| :param episode_path: path to episode mp3 | ||
| """ | ||
| media_path = os.path.join(app.config.get('MEDIA_ROOT'), 'episodes') | ||
| if not os.path.exists(media_path): | ||
| os.makedirs(media_path) | ||
| temp_path = text_to_speech(self.name) | ||
| concatenate_audios([temp_path, episode_path], | ||
| f'{media_path}/{self.id}.mp3') | ||
|
|
||
| def get_link(self): | ||
| static = app.config.get('STATIC_ROOT') + f'{self.id}.mp3' | ||
| host = app.config.get('HOST', 'localhost:5000') | ||
| return f'http://{host}/{Path(static).as_posix()}' | ||
| return f"http://{host}{url_for('episodes', path=f'{self.id}.mp3')}" | ||
|
|
||
|
|
||
| def get_all_episodes(): | ||
| return Episode.query.all() | ||
|
|
||
|
|
||
| class Joke(db.Model): | ||
|
|
@@ -84,8 +71,7 @@ def get_file_path(self): | |
| Return wrapped in jingles file path | ||
| ''' | ||
|
|
||
| media_path = os.path.join(app.config.get('MEDIA_ROOT'), 'jokes') | ||
| file_path = f'{media_path}/{self.id}.mp3' | ||
| file_path = os.path.join(app.config.get('MEDIA_ROOT'), 'jokes', f'{self.id}.mp3') | ||
| if os.path.exists(file_path): | ||
| return file_path | ||
|
|
||
|
|
@@ -98,8 +84,27 @@ def generate_wrapped_file(self): | |
| if not os.path.exists(media_path): | ||
| os.makedirs(media_path) | ||
|
|
||
| file_path = text_to_speech(self.joke_text) | ||
| joke_audio_file = text_to_speech(self.joke_text) | ||
| concatenate_audios([self.jingle_file_path(), | ||
| file_path, | ||
| joke_audio_file, | ||
| self.jingle_file_path()], | ||
| f'{media_path}/{self.id}.mp3') | ||
| os.path.join(media_path, f'{self.id}.mp3')) | ||
|
|
||
| def get_link(self): | ||
| host = app.config.get('HOST', 'localhost:5000') | ||
| return f"http://{host}{url_for('jokes', path=f'{self.id}.mp3')}" | ||
|
|
||
|
|
||
| def get_random_jokes_from_db(number=1): | ||
| return Joke.query.order_by(sqlalchemy.func.random()).limit(number) | ||
|
|
||
|
|
||
| def check_database_schema_existence(): | ||
| try: | ||
| test_user_id = 1 | ||
| User.query.get(test_user_id) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it an appropriate test for the existence of the schema? |
||
| except sqlalchemy.exc.OperationalError: | ||
| db.create_all() | ||
|
|
||
|
|
||
| check_database_schema_existence() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is happening here? why do we have a mix of quotes and why are we building URLs by concatenating strings?