Update tag
This commit is contained in:
@@ -7,7 +7,7 @@ __url__ = 'https://remizoffalex.ru'
|
||||
import os
|
||||
import jinja2
|
||||
|
||||
from . import views
|
||||
from . import routes
|
||||
from .. import app
|
||||
|
||||
|
||||
|
||||
28
myapp/ns_tag/routes.py
Normal file
28
myapp/ns_tag/routes.py
Normal file
@@ -0,0 +1,28 @@
|
||||
__author__ = 'RemiZOffAlex'
|
||||
__email__ = 'remizoffalex@mail.ru'
|
||||
__url__ = 'https://remizoffalex.ru/'
|
||||
|
||||
from flask import abort
|
||||
|
||||
from . import views_user, views_guest
|
||||
from .. import app, lib
|
||||
|
||||
|
||||
@app.route('/tags')
|
||||
def tags():
|
||||
"""Список меток
|
||||
"""
|
||||
if lib.get_user():
|
||||
return views_user.tags()
|
||||
else:
|
||||
return views_guest.tags()
|
||||
|
||||
|
||||
@app.route('/tag/<int:id>')
|
||||
def tag_id(id):
|
||||
"""Метка
|
||||
"""
|
||||
if lib.get_user():
|
||||
return views_user.tag_id(id)
|
||||
else:
|
||||
return views_guest.tag_id(id)
|
||||
100
myapp/ns_tag/templates/guest/tag.html
Normal file
100
myapp/ns_tag/templates/guest/tag.html
Normal file
@@ -0,0 +1,100 @@
|
||||
{% extends "skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
{% raw %}
|
||||
<h3>
|
||||
<a class="btn btn-outline-secondary" href="/tags"><i class="fa fa-chevron-left"></i></a>
|
||||
Тег {{ tag.name }}</h3>
|
||||
<hr />
|
||||
{% endraw %}
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
|
||||
|
||||
{% include 'inc/pages.html' %}
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{% raw %}
|
||||
<ol class="breadcrumb mt-3">
|
||||
<li class="breadcrumb-item"><a href="/"><i class="fa fa-home"></i></a></li>
|
||||
<li class="breadcrumb-item"><a href="/tags">Список тегов</a></li>
|
||||
<li class="breadcrumb-item">{{ tag.name }}</li>
|
||||
</ol>
|
||||
{% endraw %}
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript" src="/static/components/backtotop.js"></script>
|
||||
<link rel="stylesheet" href="/static/components/backtotop.css"></link>
|
||||
<script type="text/javascript" src="/static/components/pagination.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
tag: {{ pagedata['tag']|tojson|safe }},
|
||||
pages: [],
|
||||
pagination: {{ pagedata['pagination']|tojson|safe }},
|
||||
},
|
||||
methods: {
|
||||
getPages: function() {
|
||||
/* Получить список статей */
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "tag.pages",
|
||||
"params": {
|
||||
"id": vm.tag.id,
|
||||
"page": vm.pagination.page
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data) {
|
||||
vm.pages = response.data['result'];
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
},
|
||||
created: function() {
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
[
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "tag.pages",
|
||||
"params": {
|
||||
"id": vm.tag.id,
|
||||
"page": vm.pagination.page
|
||||
},
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "tag.pages.count",
|
||||
"params": {},
|
||||
"id": 1
|
||||
}
|
||||
]
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data[0]) {
|
||||
vm.pages = response.data[0]['result'];
|
||||
}
|
||||
if ('result' in response.data[1]) {
|
||||
vm.pagination.size = response.data[1]['result'];
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
61
myapp/ns_tag/templates/guest/tags.html
Normal file
61
myapp/ns_tag/templates/guest/tags.html
Normal file
@@ -0,0 +1,61 @@
|
||||
{% extends "skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
<h3>Список тегов</h3>
|
||||
<hr />
|
||||
|
||||
{% raw %}
|
||||
<div class="row">
|
||||
<div class="col py-2">
|
||||
<div class="btn-group mr-2 mb-3" v-for="(tag, tagIdx) in tags">
|
||||
<a class="btn btn-outline-secondary" :href="'/tag/' + tag.id">{{ tag.name }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endraw %}
|
||||
|
||||
<backtotop-component></backtotop-component>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
<ol class="breadcrumb mt-3">
|
||||
<li class="breadcrumb-item"><a href="/"><i class="fa fa-home"></i></a></li>
|
||||
<li class="breadcrumb-item">Список тегов</li>
|
||||
</ol>
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript" src="/static/components/backtotop.js"></script>
|
||||
<link rel="stylesheet" href="/static/components/backtotop.css"></link>
|
||||
|
||||
<script type="text/javascript">
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
tags: [],
|
||||
},
|
||||
methods: {
|
||||
},
|
||||
created: function() {
|
||||
/* Получить список тегов после загрузки страницы */
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": 'tags',
|
||||
"params": {},
|
||||
"id": 1
|
||||
}
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data) {
|
||||
vm.tags = response.data['result'];
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -1,37 +0,0 @@
|
||||
{% extends "skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
{% raw %}
|
||||
<h3>
|
||||
<a class="btn btn-outline-secondary" :href="'/tag/' + tag.id"><i class="fa fa-chevron-left"></i></a>
|
||||
Тег {{ tag.name }}</h3>
|
||||
<hr />
|
||||
{% endraw %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{% raw %}
|
||||
<ol class="breadcrumb mt-3">
|
||||
<li class="breadcrumb-item"><a href="/"><i class="fa fa-home"></i></a></li>
|
||||
<li class="breadcrumb-item"><a href="/tags">Список тегов</a></li>
|
||||
<li class="breadcrumb-item">Тег {{ tag.id }}</li>
|
||||
</ol>
|
||||
{% endraw %}
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript" src="/static/components/backtotop.js"></script>
|
||||
<link rel="stylesheet" href="/static/components/backtotop.css"></link>
|
||||
|
||||
<script type="text/javascript">
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
tag: {{ pagedata['tag']|tojson|safe }}
|
||||
},
|
||||
methods: {
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
100
myapp/ns_tag/templates/user/tag.html
Normal file
100
myapp/ns_tag/templates/user/tag.html
Normal file
@@ -0,0 +1,100 @@
|
||||
{% extends "user/skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
{% raw %}
|
||||
<h3>
|
||||
<a class="btn btn-outline-secondary" href="/tags"><i class="fa fa-chevron-left"></i></a>
|
||||
Тег {{ tag.name }}</h3>
|
||||
<hr />
|
||||
{% endraw %}
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
|
||||
|
||||
{% include 'inc/pages.html' %}
|
||||
|
||||
<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumb %}
|
||||
{% raw %}
|
||||
<ol class="breadcrumb mt-3">
|
||||
<li class="breadcrumb-item"><a href="/"><i class="fa fa-home"></i></a></li>
|
||||
<li class="breadcrumb-item"><a href="/tags">Список тегов</a></li>
|
||||
<li class="breadcrumb-item">{{ tag.name }}</li>
|
||||
</ol>
|
||||
{% endraw %}
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script type="text/javascript" src="/static/components/backtotop.js"></script>
|
||||
<link rel="stylesheet" href="/static/components/backtotop.css"></link>
|
||||
<script type="text/javascript" src="/static/components/pagination.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
tag: {{ pagedata['tag']|tojson|safe }},
|
||||
pages: [],
|
||||
pagination: {{ pagedata['pagination']|tojson|safe }},
|
||||
},
|
||||
methods: {
|
||||
getPages: function() {
|
||||
/* Получить список статей */
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "tag.pages",
|
||||
"params": {
|
||||
"id": vm.tag.id,
|
||||
"page": vm.pagination.page
|
||||
},
|
||||
"id": 1
|
||||
}
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data) {
|
||||
vm.pages = response.data['result'];
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
},
|
||||
created: function() {
|
||||
let vm = this;
|
||||
axios.post(
|
||||
'/api',
|
||||
[
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "tag.pages",
|
||||
"params": {
|
||||
"id": vm.tag.id,
|
||||
"page": vm.pagination.page
|
||||
},
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "tag.pages.count",
|
||||
"params": {},
|
||||
"id": 1
|
||||
}
|
||||
]
|
||||
).then(
|
||||
function(response) {
|
||||
if ('result' in response.data[0]) {
|
||||
vm.pages = response.data[0]['result'];
|
||||
}
|
||||
if ('result' in response.data[1]) {
|
||||
vm.pagination.size = response.data[1]['result'];
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -1,4 +1,4 @@
|
||||
{% extends "skeleton.html" %}
|
||||
{% extends "user/skeleton.html" %}
|
||||
{% block content %}
|
||||
|
||||
<h3>
|
||||
46
myapp/ns_tag/views_guest.py
Normal file
46
myapp/ns_tag/views_guest.py
Normal file
@@ -0,0 +1,46 @@
|
||||
__author__ = 'RemiZOffAlex'
|
||||
__copyright__ = '(c) RemiZOffAlex'
|
||||
__license__ = 'MIT'
|
||||
__email__ = 'remizoffalex@mail.ru'
|
||||
__url__ = 'https://remizoffalex.ru'
|
||||
|
||||
from flask import render_template
|
||||
|
||||
from .. import app, models
|
||||
|
||||
|
||||
def tags():
|
||||
"""Список меток
|
||||
"""
|
||||
pagedata = {}
|
||||
pagedata['title'] = 'Список меток - ' + app.config['TITLE']
|
||||
body = render_template('guest/tags.html', pagedata=pagedata)
|
||||
return body
|
||||
|
||||
|
||||
def tag_id(id):
|
||||
"""Метка
|
||||
"""
|
||||
pagedata = {}
|
||||
tag = models.db_session.query(
|
||||
models.Tag
|
||||
).filter(
|
||||
models.Tag.id == id
|
||||
).first()
|
||||
if tag is None:
|
||||
abort(404)
|
||||
|
||||
pagedata['title'] = 'Метка {} - {}'.format(
|
||||
tag.name,
|
||||
app.config['TITLE']
|
||||
)
|
||||
pagedata['tag'] = tag.as_dict()
|
||||
|
||||
pagedata['pagination'] = {
|
||||
"page": 1,
|
||||
"per_page": app.config['ITEMS_ON_PAGE'],
|
||||
"size": 0
|
||||
}
|
||||
|
||||
body = render_template('guest/tag.html', pagedata=pagedata)
|
||||
return body
|
||||
@@ -9,21 +9,17 @@ from flask import render_template
|
||||
from .. import app, models
|
||||
|
||||
|
||||
@app.route('/tags')
|
||||
def tags():
|
||||
"""
|
||||
Список меток
|
||||
"""Список меток
|
||||
"""
|
||||
pagedata = {}
|
||||
pagedata['title'] = 'Список меток - ' + app.config['TITLE']
|
||||
body = render_template('tags.html', pagedata=pagedata)
|
||||
body = render_template('user/tags.html', pagedata=pagedata)
|
||||
return body
|
||||
|
||||
|
||||
@app.route('/tag/<int:id>')
|
||||
def tag_id(id):
|
||||
"""
|
||||
Метка
|
||||
"""Метка
|
||||
"""
|
||||
pagedata = {}
|
||||
tag = models.db_session.query(
|
||||
@@ -40,5 +36,11 @@ def tag_id(id):
|
||||
)
|
||||
pagedata['tag'] = tag.as_dict()
|
||||
|
||||
body = render_template('tag.html', pagedata=pagedata)
|
||||
pagedata['pagination'] = {
|
||||
"page": 1,
|
||||
"per_page": app.config['ITEMS_ON_PAGE'],
|
||||
"size": 0
|
||||
}
|
||||
|
||||
body = render_template('user/tag.html', pagedata=pagedata)
|
||||
return body
|
||||
Reference in New Issue
Block a user