diff --git a/.gitignore b/.gitignore index f7ae8ec..e31ef77 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,5 @@ # Каталог с данными **/data/ -**/config/ +/config **/logs/ - -Python/graph.png -*.rrd diff --git a/README.html b/README.html index fc18c47..45c9139 100644 --- a/README.html +++ b/README.html @@ -1,3 +1,34 @@ + +
+ + + + + + + +Каркас веб-приложения на Flask
+ +Структура каталогов для проекта (в частности на Flask) https://habr.com/post/421887/
+ +Добавление пользователя
+ ++./utils/useradd.py --user admin --password admin ++ +
Запуск из консоли
+ ++./run.py ++ +
+curl -i -X POST \
+ -H "Content-Type: application/json; indent=4" \
+ -d '{
+ "jsonrpc": "2.0",
+ "method": "users.getList",
+ "params": {},
+ "id": "1"
+}' http://localhost:8000/api
+
diff --git a/myapp/ns_api/__init__.py b/myapp/ns_api/__init__.py
new file mode 100644
index 0000000..175c58e
--- /dev/null
+++ b/myapp/ns_api/__init__.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+# -*- coding: UTF-8 -*-
+
+__author__ = 'RemiZOffAlex'
+__copyright__ = '(c) RemiZOffAlex'
+__license__ = 'MIT'
+__email__ = 'remizoffalex@mail.ru'
+__url__ = 'http://remizoffalex.ru'
+
+from flask_jsonrpc import JSONRPC
+
+from .. import app
+
+jsonrpc = JSONRPC(app, '/api')
+
+from . import user
diff --git a/myapp/ns_api/user.py b/myapp/ns_api/user.py
new file mode 100644
index 0000000..7ede814
--- /dev/null
+++ b/myapp/ns_api/user.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+# -*- coding: UTF-8 -*-
+
+__author__ = 'RemiZOffAlex'
+__copyright__ = '(c) RemiZOffAlex'
+__license__ = 'MIT'
+__email__ = 'remizoffalex@mail.ru'
+__url__ = 'http://remizoffalex.ru'
+
+from flask import abort, escape
+
+from . import jsonrpc
+from .. import models
+
+
+@jsonrpc.method('users.getList')
+def users_getList():
+ """
+ Показать список пользователей
+ """
+ users = models.db_session.query(
+ models.User
+ ).all()
+
+ result = []
+ for item in users:
+ result.append(item.as_dict())
+ return result
diff --git a/myapp/ns_user/__init__.py b/myapp/ns_user/__init__.py
new file mode 100644
index 0000000..ea8e6a1
--- /dev/null
+++ b/myapp/ns_user/__init__.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+# -*- coding: UTF-8 -*-
+
+__author__ = 'RemiZOffAlex'
+__copyright__ = '(c) RemiZOffAlex'
+__license__ = 'MIT'
+__email__ = 'remizoffalex@mail.ru'
+__url__ = 'http://remizoffalex.ru'
+
+import os
+import jinja2
+
+from . import views
+from .. import app
+
+
+my_loader = jinja2.ChoiceLoader([
+ app.jinja_loader,
+ jinja2.FileSystemLoader(os.path.dirname(os.path.abspath(__file__)) + "/templates"),
+])
+app.jinja_loader = my_loader
diff --git a/myapp/ns_user/templates/users.html b/myapp/ns_user/templates/users.html
new file mode 100644
index 0000000..d5a7059
--- /dev/null
+++ b/myapp/ns_user/templates/users.html
@@ -0,0 +1,67 @@
+{% extends "skeleton.html" %}
+{% block body %}
+
+`s get reset. However, we also reset the\n// bottom margin to use `rem` units instead of `em`.\np {\n margin-top: 0;\n margin-bottom: $paragraph-margin-bottom;\n}\n\n// Abbreviations\n//\n// 1. Remove the bottom border in Firefox 39-.\n// 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.\n// 3. Add explicit cursor to indicate changed behavior.\n// 4. Duplicate behavior to the data-* attribute for our tooltip plugin\n\nabbr[title],\nabbr[data-original-title] { // 4\n text-decoration: underline; // 2\n text-decoration: underline dotted; // 2\n cursor: help; // 3\n border-bottom: 0; // 1\n}\n\naddress {\n margin-bottom: 1rem;\n font-style: normal;\n line-height: inherit;\n}\n\nol,\nul,\ndl {\n margin-top: 0;\n margin-bottom: 1rem;\n}\n\nol ol,\nul ul,\nol ul,\nul ol {\n margin-bottom: 0;\n}\n\ndt {\n font-weight: $dt-font-weight;\n}\n\ndd {\n margin-bottom: .5rem;\n margin-left: 0; // Undo browser default\n}\n\nblockquote {\n margin: 0 0 1rem;\n}\n\ndfn {\n font-style: italic; // Add the correct font style in Android 4.3-\n}\n\n// stylelint-disable font-weight-notation\nb,\nstrong {\n font-weight: bolder; // Add the correct font weight in Chrome, Edge, and Safari\n}\n// stylelint-enable font-weight-notation\n\nsmall {\n font-size: 80%; // Add the correct font size in all browsers\n}\n\n//\n// Prevent `sub` and `sup` elements from affecting the line height in\n// all browsers.\n//\n\nsub,\nsup {\n position: relative;\n font-size: 75%;\n line-height: 0;\n vertical-align: baseline;\n}\n\nsub { bottom: -.25em; }\nsup { top: -.5em; }\n\n\n//\n// Links\n//\n\na {\n color: $link-color;\n text-decoration: $link-decoration;\n background-color: transparent; // Remove the gray background on active links in IE 10.\n -webkit-text-decoration-skip: objects; // Remove gaps in links underline in iOS 8+ and Safari 8+.\n\n @include hover {\n color: $link-hover-color;\n text-decoration: $link-hover-decoration;\n }\n}\n\n// And undo these styles for placeholder links/named anchors (without href)\n// which have not been made explicitly keyboard-focusable (without tabindex).\n// It would be more straightforward to just use a[href] in previous block, but that\n// causes specificity issues in many other styles that are too complex to fix.\n// See https://github.com/twbs/bootstrap/issues/19402\n\na:not([href]):not([tabindex]) {\n color: inherit;\n text-decoration: none;\n\n @include hover-focus {\n color: inherit;\n text-decoration: none;\n }\n\n &:focus {\n outline: 0;\n }\n}\n\n\n//\n// Code\n//\n\n// stylelint-disable font-family-no-duplicate-names\npre,\ncode,\nkbd,\nsamp {\n font-family: monospace, monospace; // Correct the inheritance and scaling of font size in all browsers.\n font-size: 1em; // Correct the odd `em` font sizing in all browsers.\n}\n// stylelint-enable font-family-no-duplicate-names\n\npre {\n // Remove browser default top margin\n margin-top: 0;\n // Reset browser default of `1em` to use `rem`s\n margin-bottom: 1rem;\n // Don't allow content to break outside\n overflow: auto;\n // We have @viewport set which causes scrollbars to overlap content in IE11 and Edge, so\n // we force a non-overlapping, non-auto-hiding scrollbar to counteract.\n -ms-overflow-style: scrollbar;\n}\n\n\n//\n// Figures\n//\n\nfigure {\n // Apply a consistent margin strategy (matches our type styles).\n margin: 0 0 1rem;\n}\n\n\n//\n// Images and content\n//\n\nimg {\n vertical-align: middle;\n border-style: none; // Remove the border on images inside links in IE 10-.\n}\n\nsvg:not(:root) {\n overflow: hidden; // Hide the overflow in IE\n}\n\n\n// Avoid 300ms click delay on touch devices that support the `touch-action` CSS property.\n//\n// In particular, unlike most other browsers, IE11+Edge on Windows 10 on touch devices and IE Mobile 10-11\n// DON'T remove the click delay when `` is present.\n// However, they DO support removing the click delay via `touch-action: manipulation`.\n// See:\n// * https://getbootstrap.com/docs/4.0/content/reboot/#click-delay-optimization-for-touch\n// * https://caniuse.com/#feat=css-touch-action\n// * https://patrickhlauke.github.io/touch/tests/results/#suppressing-300ms-delay\n\na,\narea,\nbutton,\n[role=\"button\"],\ninput:not([type=\"range\"]),\nlabel,\nselect,\nsummary,\ntextarea {\n touch-action: manipulation;\n}\n\n\n//\n// Tables\n//\n\ntable {\n border-collapse: collapse; // Prevent double borders\n}\n\ncaption {\n padding-top: $table-cell-padding;\n padding-bottom: $table-cell-padding;\n color: $text-muted;\n text-align: left;\n caption-side: bottom;\n}\n\nth {\n // Matches default `