Browse Source

Lot of shit to fix to get it working in prod

root 1 year ago
parent
commit
94dddb2400
10 changed files with 37 additions and 43 deletions
  1. 1
    1
      app/__init__.py
  2. 1
    1
      app/main/__init__.py
  3. 0
    19
      app/main/views.py
  4. 5
    2
      app/models/admin.py
  5. 4
    6
      app/templates/base.html
  6. 7
    7
      app/templates/menu.html
  7. 1
    1
      config.py
  8. 12
    5
      gunicorn.py
  9. 1
    1
      manage.py
  10. 5
    0
      wsgi.py

+ 1
- 1
app/__init__.py View File

@@ -16,7 +16,7 @@ admin = Admin(name = __APP_NAME__ + ' Admin', template_mode="bootstrap3")
16 16
 base_path = op.dirname(__file__)
17 17
 
18 18
 def create_app(config_name):
19
-    app = Flask(__name__)
19
+    app = Flask(__name__, static_url_path='/staticsite')
20 20
     app.config.from_object(config[config_name])
21 21
     app.config['SECRET_KEY'] = 'Thatdumkey'
22 22
     config[config_name].init_app(app)

+ 1
- 1
app/main/__init__.py View File

@@ -1,5 +1,5 @@
1 1
 from flask import Blueprint
2 2
 
3
-main = Blueprint('main', __name__)
3
+main = Blueprint('main', __name__, url_prefix="/site")
4 4
 
5 5
 from . import views, errors

+ 0
- 19
app/main/views.py View File

@@ -41,8 +41,6 @@ app = Flask(__name__)
41 41
 
42 42
 def base():
43 43
     return render_template( 'base.html',
44
-                            styles = getStyles(),
45
-                            scripts = getScripts(),
46 44
                             podcasts = Podcast.list(),
47 45
                             blog_posts = BlogPost.list(),
48 46
                             events = Event.list(),
@@ -216,20 +214,3 @@ def next_live():
216 214
                      "on_air_light": on_air_light["on_air_light"]})
217 215
 
218 216
 
219
-#########################
220
-#  Static stuff         #
221
-#########################
222
-
223
-def getStyles():
224
-     return [ url_for('static',
225
-                      filename=file.replace('app/static/', ''),
226
-                      #_scheme='https',
227
-                      _external=True)
228
-             for file in glob("app/static/css/*.css") ]
229
-
230
-def getScripts():
231
-     return [ url_for('static',
232
-                      filename=file.replace('app/static/', ''),
233
-                      #_scheme='https',
234
-                      _external=True)
235
-             for file in glob("app/static/js/*.js") ]

+ 5
- 2
app/models/admin.py View File

@@ -157,8 +157,11 @@ class PageAdminView(FullTextView):
157 157
     )
158 158
 
159 159
 admin.add_view(PodcastView(Podcast, db.session))
160
-admin.add_view(FileAdmin(podcastPath, '/static/podcasts/',
161
-                         name='Anciens podcasts'))
160
+try:
161
+    admin.add_view(FileAdmin(podcastPath, '/static/podcasts/', 
162
+                             name='Anciens podcasts'))
163
+except:
164
+    print("Failed to load /static/podcasts, ignoring. (Is sshfs working properly?)")
162 165
 admin.add_view(BlogView(BlogPost, db.session))
163 166
 admin.add_view(ContributorView(Contributor, db.session))
164 167
 admin.add_view(ContributorView(Collective, db.session))

+ 4
- 6
app/templates/base.html View File

@@ -3,9 +3,8 @@
3 3
     <head>
4 4
         {% block head %}
5 5
         <meta charset="utf-8" lang="FR/fr">
6
-        {% for style in styles %}
7
-        <link rel="stylesheet" href="{{ style }}">
8
-        {% endfor %}
6
+        <link rel="stylesheet" href="{{ url_for('static', filename='css/player.css') }}">
7
+        <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
9 8
         <title>Radio Rhino{% if title %} | {{ title }} {% endif %}</title>
10 9
         {% endblock %}
11 10
     </head>
@@ -24,9 +23,8 @@
24 23
         {% endblock %}
25 24
     </body>
26 25
 
27
-    {% for script in scripts %}
28
-    <script type="text/javascript" src={{ script }}></script>
29
-    {% endfor %}
26
+    <script type="text/javascript" src={{ url_for('static', filename='js/player.js') }}></script>
27
+    <script type="text/javascript" src={{ url_for('static', filename='js/app.js') }}></script>
30 28
 
31 29
     {% if content %}
32 30
     <script type="text/javascript">

+ 7
- 7
app/templates/menu.html View File

@@ -1,21 +1,21 @@
1 1
 <nav>
2
-    <a id="logo" class="content-link" href="/">
2
+    <a id="logo" class="content-link" href="{{ url_for('main.index') }}">
3 3
         {% include 'svg/logo.svg' %}
4 4
     </a>
5 5
     <div>
6
-        <a class="content-link" href="/podcasts">
6
+        <a class="content-link" href="{{ url_for('main.podcasts') }}">
7 7
             {% include 'svg/title_podcasts.svg' %}</a>
8
-        <a class="content-link" href="/contributors">
8
+        <a class="content-link" href="{{ url_for('main.contributors') }}">
9 9
             {% include 'svg/title_contributors.svg' %}</a>
10
-        <a class="content-link" href="/blogs">
10
+        <a class="content-link" href="{{ url_for('main.blogs') }}">
11 11
             {% include 'svg/title_blog.svg' %}</a>
12
-        <a class="content-link" href="/agendas">
12
+        <a class="content-link" href="{{ url_for('main.agendas') }}">
13 13
             {% include 'svg/title_agenda.svg' %}</a>
14 14
     </div>
15 15
     <div>
16
-        <a class="content-link" href="/about">
16
+        <a class="content-link" href="{{ url_for('main.about') }}">
17 17
             {% include 'svg/title_about.svg' %}</a>
18
-        <a class="content-link" href="/contrib">
18
+        <a class="content-link" href="{{ url_for('main.contribute') }}">
19 19
             {% include 'svg/title_contribute.svg' %}</a>
20 20
     </div>
21 21
 </nav>

+ 1
- 1
config.py View File

@@ -39,7 +39,7 @@ class ProductionConfig(Config):
39 39
     MAIL_USE_TLS = True
40 40
     MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
41 41
     MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
42
-    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or 'postgresql://rhino'
42
+    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or 'postgresql+psycopg2://localhost/rhino'
43 43
 
44 44
 config = {
45 45
         'development':   DevelopmentConfig,

+ 12
- 5
gunicorn.py View File

@@ -1,11 +1,18 @@
1
-import multiprocessing
1
+command = "/home/rhino/RhinoRadioCMS/venv/bin/gunicorn"
2
+pythonpath = '/home/rhino/RhinoRadioCMS'
2 3
 
3
-bind = "127.0.0.1:8000"
4
-backlog = 2048
4
+user = 'rhino'
5
+workers = 4
5 6
 
6
-workers = multiprocessing.cpu_count() * 2 + 1
7
+bind = 'unix:/home/rhino/RhinoRadioCMS/sock'
8
+pid = "/run/gunicorn/rhinosite-pid"
7 9
 
8
-user = 1000
10
+backlog = 2048
11
+errorlog = "/var/log/rhinosite/error.log"
12
+accesslog = "/var/log/rhinosite/acces.log"
13
+access_log_format = '%({X-Real-IP}i)s %({X-Forwarded-For}i)s %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
14
+loglevel = 'warning'
15
+capture_output = True
9 16
 
10 17
 limit_request_line = 2048
11 18
 limit_request_fields = 50

+ 1
- 1
manage.py View File

@@ -4,7 +4,7 @@ from flask_script import Manager, Shell
4 4
 from flask_migrate import Migrate, MigrateCommand
5 5
 from app.commands import *
6 6
 
7
-app = create_app(os.getenv('FLASK_CONFIG') or 'default')
7
+app = create_app(os.getenv('FLASK_CONFIG') or 'production')
8 8
 manager = Manager(app)
9 9
 
10 10
 def make_shell_context():

+ 5
- 0
wsgi.py View File

@@ -0,0 +1,5 @@
1
+from app import create_app
2
+
3
+application = create_app('production')
4
+if __name__ == "__main__":
5
+    application.run()

Loading…
Cancel
Save