Update api and templates for note and page
This commit is contained in:
@@ -29,3 +29,6 @@ SECRET_KEY = '''0123456789'''
|
|||||||
LOG_FILE = DIR_DATA + '/myapp.log'
|
LOG_FILE = DIR_DATA + '/myapp.log'
|
||||||
LONG_LOG_FORMAT = '%(asctime)s - [%(name)s.%(levelname)s] [%(threadName)s, %(module)s.%(funcName)s@%(lineno)d] %(message)s'
|
LONG_LOG_FORMAT = '%(asctime)s - [%(name)s.%(levelname)s] [%(threadName)s, %(module)s.%(funcName)s@%(lineno)d] %(message)s'
|
||||||
LOG_FILE_SIZE = 128 # Размер файла лога в МБ
|
LOG_FILE_SIZE = 128 # Размер файла лога в МБ
|
||||||
|
|
||||||
|
# Количество выводимых элементов на странице
|
||||||
|
ITEMS_ON_PAGE = 100
|
||||||
|
|||||||
@@ -26,30 +26,6 @@ def note_id(id: int)->dict:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@jsonrpc.method('note.update')
|
|
||||||
@login_required
|
|
||||||
def note_update(title: str, body: str)->dict:
|
|
||||||
"""Обновить заметку
|
|
||||||
"""
|
|
||||||
note = models.db_session.query(
|
|
||||||
models.Note
|
|
||||||
).filter(
|
|
||||||
models.Note.id==id
|
|
||||||
).first()
|
|
||||||
if note is None:
|
|
||||||
raise ValueError
|
|
||||||
|
|
||||||
note.title = title
|
|
||||||
note.body = body
|
|
||||||
|
|
||||||
result = note.as_dict()
|
|
||||||
result['user'] = note.user.as_dict()
|
|
||||||
result['tags'] = []
|
|
||||||
for tagLink in note.tags:
|
|
||||||
result['tags'].append(tagLink.tag.as_dict())
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
@jsonrpc.method('note.add')
|
@jsonrpc.method('note.add')
|
||||||
@login_required
|
@login_required
|
||||||
def note_add(title: str, body: str)->dict:
|
def note_add(title: str, body: str)->dict:
|
||||||
@@ -91,6 +67,30 @@ def note_destroy(id: int)->bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@jsonrpc.method('note.update')
|
||||||
|
@login_required
|
||||||
|
def note_update(id: int, title: str, body: str)->dict:
|
||||||
|
"""Обновить заметку
|
||||||
|
"""
|
||||||
|
note = models.db_session.query(
|
||||||
|
models.Note
|
||||||
|
).filter(
|
||||||
|
models.Note.id==id
|
||||||
|
).first()
|
||||||
|
if note is None:
|
||||||
|
raise ValueError
|
||||||
|
|
||||||
|
note.title = title
|
||||||
|
note.body = body
|
||||||
|
|
||||||
|
result = note.as_dict()
|
||||||
|
result['user'] = note.user.as_dict()
|
||||||
|
result['tags'] = []
|
||||||
|
for tagLink in note.tags:
|
||||||
|
result['tags'].append(tagLink.tag.as_dict())
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
@jsonrpc.method('notes')
|
@jsonrpc.method('notes')
|
||||||
def notes_list(page: int)->list:
|
def notes_list(page: int)->list:
|
||||||
"""Список заметок
|
"""Список заметок
|
||||||
|
|||||||
@@ -26,30 +26,6 @@ def page_id(id: int)->dict:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@jsonrpc.method('page.update')
|
|
||||||
@login_required
|
|
||||||
def page_update(title: str, text: str)->dict:
|
|
||||||
"""Обновить статью
|
|
||||||
"""
|
|
||||||
page = models.db_session.query(
|
|
||||||
models.Page
|
|
||||||
).filter(
|
|
||||||
models.Page.id==id
|
|
||||||
).first()
|
|
||||||
if page is None:
|
|
||||||
raise ValueError
|
|
||||||
|
|
||||||
page.title = title
|
|
||||||
page.text = text
|
|
||||||
|
|
||||||
result = page.as_dict()
|
|
||||||
result['user'] = page.user.as_dict()
|
|
||||||
result['tags'] = []
|
|
||||||
for tagLink in page.tags:
|
|
||||||
result['tags'].append(tagLink.tag.as_dict())
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
@jsonrpc.method('page.add')
|
@jsonrpc.method('page.add')
|
||||||
@login_required
|
@login_required
|
||||||
def page_add(title: str, body: str)->dict:
|
def page_add(title: str, body: str)->dict:
|
||||||
@@ -91,6 +67,30 @@ def page_destroy(id: int)->bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@jsonrpc.method('page.update')
|
||||||
|
@login_required
|
||||||
|
def page_update(id: int, title: str, text: str)->dict:
|
||||||
|
"""Обновить статью
|
||||||
|
"""
|
||||||
|
page = models.db_session.query(
|
||||||
|
models.Page
|
||||||
|
).filter(
|
||||||
|
models.Page.id==id
|
||||||
|
).first()
|
||||||
|
if page is None:
|
||||||
|
raise ValueError
|
||||||
|
|
||||||
|
page.title = title
|
||||||
|
page.text = text
|
||||||
|
|
||||||
|
result = page.as_dict()
|
||||||
|
result['user'] = page.user.as_dict()
|
||||||
|
result['tags'] = []
|
||||||
|
for tagLink in page.tags:
|
||||||
|
result['tags'].append(tagLink.tag.as_dict())
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
@jsonrpc.method('pages')
|
@jsonrpc.method('pages')
|
||||||
def pages_list(page: int)->list:
|
def pages_list(page: int)->list:
|
||||||
"""Список статей
|
"""Список статей
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button type="button" class="btn btn-outline-success pull-right" v-on:click="send"><i class="fa fa-save-o"></i> Сохранить</button>
|
<button type="submit" class="btn btn-outline-success pull-right" v-on:click="send"><i class="fa fa-save-o"></i> Сохранить</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button type="button" class="btn btn-outline-success pull-right" v-on:click="send"><i class="fa fa-plus"></i> Добавить</button>
|
<button type="submit" class="btn btn-outline-success pull-right" v-on:click="send"><i class="fa fa-plus"></i> Добавить</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button type="button" class="btn btn-outline-success pull-right" v-on:click="send"><i class="fa fa-save-o"></i> Сохранить</button>
|
<button type="submit" class="btn btn-outline-success pull-right" v-on:click="send"><i class="fa fa-save-o"></i> Сохранить</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -27,12 +27,14 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block breadcrumb %}
|
{% block breadcrumb %}
|
||||||
|
{% raw %}
|
||||||
<ol class="breadcrumb mt-3">
|
<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="/"><i class="fa fa-home"></i></a></li>
|
||||||
<li class="breadcrumb-item"><a href="/pages">Страницы</a></li>
|
<li class="breadcrumb-item"><a href="/pages">Страницы</a></li>
|
||||||
<li class="breadcrumb-item"><a href="/page/{{ pagedata['page'].id }}">{{ pagedata['page'].title }}</a></li>
|
<li class="breadcrumb-item"><a :href="'/page/' + page.id">{{ page.title }}</a></li>
|
||||||
<li class="breadcrumb-item active">Редактирование страницы</li>
|
<li class="breadcrumb-item active">Редактирование страницы</li>
|
||||||
</ol>
|
</ol>
|
||||||
|
{% endraw %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
|
|||||||
Reference in New Issue
Block a user