Add inline_svg
This commit is contained in:
parent
baed59ea39
commit
8b5e2ed41b
18 changed files with 56 additions and 21 deletions
|
|
@ -30,6 +30,8 @@ __version__ = '0.9-dev'
|
|||
if sys.version_info[0] < 3:
|
||||
raise RuntimeError('Python 3 required')
|
||||
|
||||
os.chdir(os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_pyfile('../config.py')
|
||||
|
||||
|
|
@ -60,7 +62,11 @@ def after_request(response):
|
|||
|
||||
@app.context_processor
|
||||
def _inject_variables():
|
||||
return {'site_name': app.config['SITE_NAME'], 'locations': locations}
|
||||
return {
|
||||
'site_name': app.config['SITE_NAME'],
|
||||
'locations': locations,
|
||||
'inline_svg': inline_svg
|
||||
}
|
||||
|
||||
@login_manager.user_loader
|
||||
def _inject_user(userid):
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Filter functions used in the website templates.
|
|||
|
||||
from flask import Markup
|
||||
import html, datetime, re, time
|
||||
from .utils import tokenize
|
||||
from .utils import tokenize, inline_svg as _inline_svg
|
||||
from . import app
|
||||
|
||||
@app.template_filter()
|
||||
|
|
@ -64,3 +64,4 @@ def is_following(from_user, to_user):
|
|||
def locationdata(key):
|
||||
if key > 0:
|
||||
return locations[str(key)]
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import os
|
|||
# here should go `from .utils import get_current_user`, but it will cause
|
||||
# import errors. It's instead imported at function level.
|
||||
|
||||
database = SqliteDatabase(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'coriplus.sqlite'))
|
||||
database = SqliteDatabase('coriplus.sqlite')
|
||||
|
||||
class BaseModel(Model):
|
||||
class Meta:
|
||||
|
|
@ -51,8 +51,7 @@ class User(BaseModel):
|
|||
return False
|
||||
@property
|
||||
def is_authenticated(self):
|
||||
from .utils import get_current_user
|
||||
return self == get_current_user()
|
||||
return True
|
||||
|
||||
# it often makes sense to put convenience methods on model instances, for
|
||||
# example, "give me all the users this user is following":
|
||||
|
|
|
|||
|
|
@ -1,9 +1,16 @@
|
|||
body,button,input,select,textarea{font-family:'Segoe UI',Arial,Helvetica,sans-serif}
|
||||
body,button,input,select,textarea{font-family:Roboto,'Segoe UI',Arial,Helvetica,sans-serif}
|
||||
body{margin:0}
|
||||
.header{padding:12px;color:white;background-color:#ff3018}
|
||||
a{text-decoration:none}
|
||||
a:hover{text-decoration:underline}
|
||||
@media (max-width:640px){
|
||||
.mobile-collapse{display:none}
|
||||
}
|
||||
.header{padding:12px;color:white;background-color:#ff3018;box-shadow:0 0 3px 3px #ccc}
|
||||
.content{padding:12px}
|
||||
.header a{color:white}
|
||||
.header a svg{fill:white}
|
||||
.content a{color:#3399ff}
|
||||
.content a svg{fill:#3399ff}
|
||||
.content a.plus{color:#ff3018}
|
||||
.metanav{float:right}
|
||||
.header h1{margin:0;display:inline-block}
|
||||
|
|
@ -14,7 +21,9 @@ body{margin:0}
|
|||
}
|
||||
.weak{opacity:.5}
|
||||
.field_desc{display:block}
|
||||
.message-visual img{max-width:100%;max-height:8em}
|
||||
ul.timeline{padding:0;margin:auto;max-width:960px}
|
||||
ul.timeline > li{list-style:none;border-bottom:#808080 1px solid}
|
||||
.message-visual img{max-width:100%;margin:auto}
|
||||
.message-options-showhide::before{content:'\2026'}
|
||||
.message-options{display:none}
|
||||
.create_text{width:100%;height:8em}
|
||||
|
|
|
|||
|
|
@ -12,18 +12,18 @@
|
|||
<h1><a href="{{ url_for('website.homepage') }}">{{ site_name }}</a></h1>
|
||||
<div class="metanav">
|
||||
{% if current_user.is_anonymous %}
|
||||
<a href="{{ url_for('website.login', next=request.full_path) }}">log in</a>
|
||||
<a href="{{ url_for('website.register', next=request.full_path) }}">register</a>
|
||||
<a href="{{ url_for('website.login', next=request.full_path) }}">{{ inline_svg('exit_to_app') }} log in</a>
|
||||
<a href="{{ url_for('website.register', next=request.full_path) }}">{{ inline_svg('person_add') }} register</a>
|
||||
{% else %}
|
||||
<a href="{{ url_for('website.user_detail', username=current_user.username) }}">{{ current_user.username }}</a>
|
||||
<a href="{{ url_for('website.user_detail', username=current_user.username) }}">{{ inline_svg('person') }} {{ current_user.username }}</a>
|
||||
{% set notification_count = current_user.unseen_notification_count() %}
|
||||
{% if notification_count > 0 %}
|
||||
<a href="{{ url_for('website.notifications') }}">(<strong>{{ notification_count }}</strong>)</a>
|
||||
{% endif %}
|
||||
-
|
||||
<a href="{{ url_for('website.public_timeline') }}">explore</a>
|
||||
<a href="{{ url_for('website.create') }}">create</a>
|
||||
<a href="{{ url_for('website.logout') }}">log out</a>
|
||||
<a href="{{ url_for('website.public_timeline') }}">{{ inline_svg('explore') }} explore</a>
|
||||
<a href="{{ url_for('website.create') }}">{{ inline_svg('edit') }} create</a>
|
||||
<a href="{{ url_for('website.logout') }}">{{ inline_svg('exit_to_app') }} log out</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -36,7 +36,8 @@
|
|||
<div class="footer">
|
||||
<p class="copyright">© 2019 Sakuragasaki46.
|
||||
<a href="/about/">About</a> - <a href="/terms/">Terms</a> -
|
||||
<a href="/privacy/">Privacy</a></p>
|
||||
<a href="/privacy/">Privacy</a> -
|
||||
<a href="https://github.com/sakuragasaki46/coriplus">GitHub</a></p>
|
||||
</div>
|
||||
<script src="/static/lib.js"></script>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
{% block body %}
|
||||
<h2>Explore</h2>
|
||||
<ul>
|
||||
<ul class="timeline">
|
||||
{% for message in message_list %}
|
||||
<li id="{{ message.id }}">{% include "includes/message.html" %}</li>
|
||||
{% endfor %}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
{% block body %}
|
||||
<h2>Your Timeline</h2>
|
||||
<ul>
|
||||
<ul class="timeline">
|
||||
{% for message in message_list %}
|
||||
<li id="{{ message.id }}">{% include "includes/message.html" %}</li>
|
||||
{% endfor %}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,6 @@
|
|||
<a href="{{ url_for('website.user_following', username=user.username) }}"><strong>{{ user.following()|count }}</strong></a> following
|
||||
</p>
|
||||
{% if user == current_user %}
|
||||
<p><a href="/edit_profile/">Edit profile</a></p>
|
||||
<p><a href="/edit_profile/">{{ inline_svg('edit', 18) }} Edit profile</a></p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
<a href="/create/">Create a message</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<ul>
|
||||
<ul class="timeline">
|
||||
{% for message in message_list %}
|
||||
<li id="{{ message.id }}">{% include "includes/message.html" %}</li>
|
||||
{% endfor %}
|
||||
|
|
|
|||
15
app/utils.py
15
app/utils.py
|
|
@ -5,7 +5,7 @@ A list of utilities used across modules.
|
|||
import datetime, re, base64, hashlib, string, sys, json
|
||||
from .models import User, Message, Notification, MSGPRV_PUBLIC, MSGPRV_UNLISTED, \
|
||||
MSGPRV_FRIENDS, MSGPRV_ONLYME
|
||||
from flask import abort, render_template, request, session
|
||||
from flask import Markup, abort, render_template, request, session
|
||||
|
||||
_forbidden_extensions = 'com net org txt'.split()
|
||||
_username_characters = frozenset(string.ascii_letters + string.digits + '_')
|
||||
|
|
@ -82,7 +82,7 @@ class Visibility(object):
|
|||
|
||||
def get_locations():
|
||||
data = {}
|
||||
with open('locations.txt') as f:
|
||||
with open('locations.txt', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
line = line.rstrip()
|
||||
if line.startswith('#'):
|
||||
|
|
@ -215,3 +215,14 @@ def create_mentions(cur_user, text, privacy):
|
|||
push_notification('mention', mention_user, user=user.id)
|
||||
except User.DoesNotExist:
|
||||
pass
|
||||
|
||||
# New in 0.9
|
||||
def inline_svg(name, width=None):
|
||||
try:
|
||||
with open('icons/' + name + '-24px.svg') as f:
|
||||
data = f.read()
|
||||
if isinstance(width, int):
|
||||
data = re.sub(r'( (?:height|width)=")\d+(")', lambda x:x.group(1) + str(width) + x.group(2), data)
|
||||
return Markup(data)
|
||||
except OSError:
|
||||
return ''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue