Browse Source

avatar fixed with flask_avatar 0.1.3

honmaple 7 years ago
parent
commit
02535c05e3
3 changed files with 41 additions and 42 deletions
  1. 5 22
      forums/extension/__init__.py
  2. 2 2
      requirements.txt
  3. 34 18
      templates/maple/footer.html

+ 5 - 22
forums/extension/__init__.py

@@ -6,11 +6,11 @@
 # Author: jianglin
 # Author: jianglin
 # Email: xiyang0807@gmail.com
 # Email: xiyang0807@gmail.com
 # Created: 2018-02-11 14:52:12 (CST)
 # Created: 2018-02-11 14:52:12 (CST)
-# Last Update: 星期日 2018-02-11 15:31:19 (CST)
+# Last Update: Saturday 2018-03-03 21:53:59 (CST)
 #          By:
 #          By:
 # Description:
 # Description:
 # ********************************************************************************
 # ********************************************************************************
-from flask import request, current_app
+from flask import request
 from flask_wtf.csrf import CSRFProtect
 from flask_wtf.csrf import CSRFProtect
 from flask_avatar import Avatar
 from flask_avatar import Avatar
 from flask_maple.models import db
 from flask_maple.models import db
@@ -28,31 +28,14 @@ cache = Cache()
 mail = Mail()
 mail = Mail()
 principal = Principal()
 principal = Principal()
 search = Search(db=db)
 search = Search(db=db)
-
-
-class AvatarCache(Avatar):
-    @cache.cached(
-        timeout=180, key_prefix=lambda: "avatar:{}".format(request.url))
-    def avatar(self, text, width=128):
-        from flask import abort, make_response
-        from flask_avatar.avatar import GenAvatar
-        width_range = current_app.config.get('AVATAR_RANGE', [0, 512])
-        if width < width_range[0] or width > width_range[1]:
-            abort(404)
-        stream = GenAvatar.generate(width, text)
-        buf_value = stream.getvalue()
-        response = make_response(buf_value)
-        response.headers['Content-Type'] = 'image/jpeg'
-        return response
-
-
-avatar = AvatarCache()
+avatar = Avatar(cache=cache.cached(
+    timeout=259200, key_prefix=lambda: "avatar:{}".format(request.url)))
 
 
 
 
 def init_app(app):
 def init_app(app):
     db.init_app(app)
     db.init_app(app)
-    avatar.init_app(app)
     cache.init_app(app)
     cache.init_app(app)
+    avatar.init_app(app)
     csrf.init_app(app)
     csrf.init_app(app)
     principal.init_app(app)
     principal.init_app(app)
     redis_data.init_app(app)
     redis_data.init_app(app)

+ 2 - 2
requirements.txt

@@ -4,7 +4,7 @@ cssmin==0.2.0
 Flask==0.12.2
 Flask==0.12.2
 Flask-Admin==1.4.2
 Flask-Admin==1.4.2
 Flask-Assets==0.12
 Flask-Assets==0.12
-Flask-Avatar==0.1.0
+Flask-Avatar==0.1.3
 Flask-BabelEx==0.9.3
 Flask-BabelEx==0.9.3
 Flask-Caching==1.3.2
 Flask-Caching==1.3.2
 Flask-Login==0.4.1
 Flask-Login==0.4.1
@@ -21,7 +21,7 @@ Jinja2==2.10
 jsmin==2.2.0
 jsmin==2.2.0
 misaka==2.0.0
 misaka==2.0.0
 Pillow==3.2.0
 Pillow==3.2.0
-psycopg2==2.6.1
+psycopg2==2.7.1
 Pygments==2.1
 Pygments==2.1
 pytz==2018.3
 pytz==2018.3
 redis==2.10.5
 redis==2.10.5

+ 34 - 18
templates/maple/footer.html

@@ -1,49 +1,65 @@
 <style>
 <style>
+ .main {
+     padding-bottom:100px;
+ }
  .footer {
  .footer {
-     margin-top: -30px;
+     margin-top: -100px;
      height: 100px;
      height: 100px;
      background-color:#fff;
      background-color:#fff;
-     padding:16px 0 10 10;
+     padding:12px 15px;
      border:1px solid #ddd;
      border:1px solid #ddd;
-     border-radius:5px;
+     border-radius:5px 5px 0 0;
+ }
+ .footer blockquote {
+     font-size:14px;
+ }
+ .footer blockquote p {
+     font-size:14px;
  }
  }
- p.heading a{
+ .footer-heading a{
      color: #aaa;
      color: #aaa;
      text-decoration: none;
      text-decoration: none;
      border-bottom: 1px dotted #999;
      border-bottom: 1px dotted #999;
  }
  }
- .pipe {
+ .footer-desc{
+     font-size:12px;
+     color:#777;
+ }
+ .footer-desc span{
+     margin-left:10px;
+ }
+ .footer-pipe {
      margin: 0 5px;
      margin: 0 5px;
      color: #ccc;
      color: #ccc;
  }
  }
 </style>
 </style>
 <div class="footer col-md-offset-1 col-md-10">
 <div class="footer col-md-offset-1 col-md-10">
-  <div class="pull-right" style="margin-right:30px;margin-top:10px">
-    <p class="heading text-right">
+  <div class="pull-right">
+    <p class="footer-heading text-right">
       <a href="{{ url_for('forums.help')}}">{{ _('Help')}}</a>
       <a href="{{ url_for('forums.help')}}">{{ _('Help')}}</a>
-      <span class="pipe"> | </span>
+      <span class="footer-pipe"> | </span>
       <a href="{{ url_for('forums.about')}}">{{ _('About')}}</a>
       <a href="{{ url_for('forums.about')}}">{{ _('About')}}</a>
-      <span class="pipe"> | </span>
+      <span class="footer-pipe"> | </span>
       <a href="{{ url_for('forums.contact')}}">{{ _('Contact me')}}</a>
       <a href="{{ url_for('forums.contact')}}">{{ _('Contact me')}}</a>
-      <span class="pipe"> | </span>
+      <span class="footer-pipe"> | </span>
       <a href="https://github.com/honmaple/maple-bbs" target="_blank">GitHub</a>
       <a href="https://github.com/honmaple/maple-bbs" target="_blank">GitHub</a>
     </p>
     </p>
-    <p class="text-right hidden-xs" style="font-size:12px;color:#777">
+    <p class="footer-desc text-right hidden-xs">
       {% set footer_count = g.get_online %}
       {% set footer_count = g.get_online %}
       <span>{{ _('Now users online:')}}<strong>{{ footer_count[0] }}</strong></span>
       <span>{{ _('Now users online:')}}<strong>{{ footer_count[0] }}</strong></span>
-      <span style="margin-left:10px">{{ _('Registered users online:') }}<strong>{{ footer_count[1] }}</strong></span>
-      <span style="margin-left:10px">{{ _('Guests online:')}}<strong>{{ footer_count[2] }}</strong></span>
+      <span>{{ _('Registered users online:') }}<strong>{{ footer_count[1] }}</strong></span>
+      <span>{{ _('Guests online:')}}<strong>{{ footer_count[2] }}</strong></span>
     </p>
     </p>
-    <p class="text-right hidden-xs" style="font-size:12px;color:#777">
+    <p class="footer-desc text-right hidden-xs">
       <span>{{ show_time() }}</span>
       <span>{{ show_time() }}</span>
-      <span style="margin-left:10px">{{ _('Highest online:')}}<strong>{{ footer_count[3] }}</strong></span>
-      <span style="margin-left:10px">{{ _('Time of highest online:')}}<strong>{{ footer_count[4] }}</strong></span>
+      <span>{{ _('Highest online:')}}<strong>{{ footer_count[3] }}</strong></span>
+      <span>{{ _('Time of highest online:')}}<strong>{{ footer_count[4] }}</strong></span>
     </p>
     </p>
   </div>
   </div>
   <blockquote>
   <blockquote>
-    <p style="font-size:14px;">{{ _(SITE['description']) }}</p>
+    <p>{{ _(SITE['description']) }}</p>
     <footer>
     <footer>
-      <span> Copyright © 2015-2016 honmaple.</span>
+      © 2015-2018 honmaple.
     </footer>
     </footer>
   </blockquote>
   </blockquote>
 </div>
 </div>