This repository was archived by the owner on Mar 16, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
74 lines (54 loc) · 2.53 KB
/
Copy path__init__.py
File metadata and controls
74 lines (54 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Pytsite Content Plugin
"""
__author__ = 'Oleksandr Shepetko'
__email__ = 'a@shepetko.com'
__license__ = 'MIT'
# Public API
from . import _model as model, _widget as widget
from ._constants import CONTENT_STATUS_UNPUBLISHED, CONTENT_STATUS_WAITING, CONTENT_STATUS_PUBLISHED, \
CONTENT_PERM_VIEW, CONTENT_PERM_VIEW_OWN, CONTENT_PERM_SET_LOCALIZATION, CONTENT_PERM_SET_PUBLISH_TIME, \
CONTENT_PERM_BYPASS_MODERATION
from ._api import register_model, get_models, find, get_model, get_model_title, dispense, is_model_registered, \
generate_rss, find_by_url, paginate, on_content_view
from ._model import Content, ContentWithURL
# Locally needed imports
from semaver import Version as _Version
def plugin_load():
from pytsite import router
from plugins import permissions, admin
from . import _controllers
# Permissions group
permissions.define_group('content', 'content@content')
# Admin section should exist before any content's models registration
admin.sidebar.add_section('content', 'content@content', 100)
# Routes which must be registered in any environment
router.handle(_controllers.View, 'content/view/<model>/<eid>', 'content@view')
def plugin_load_console():
from pytsite import console
from . import _console_command
console.register_command(_console_command.Generate())
def plugin_load_wsgi():
from pytsite import cron, events, router
from plugins import http_api, settings, robots_txt, flag
from . import _eh, _controllers, _http_api_controllers, _settings_form
# Events listeners
cron.hourly(_eh.on_cron_hourly)
cron.daily(_eh.on_cron_daily)
on_content_view(_eh.on_content_view)
events.listen('comments@create_comment', _eh.on_comments_create_comment)
flag.on_flag_create(_eh.on_flag_toggle)
flag.on_flag_delete(_eh.on_flag_toggle)
# Routes
router.handle(_controllers.Index, 'content/index/<model>', 'content@index')
# HTTP API endpoints
http_api.handle('PATCH', 'content/view/<model>/<uid>', _http_api_controllers.PatchViewsCount,
'content@patch_view_count')
http_api.handle('POST', 'content/abuse/<model>/<uid>', _http_api_controllers.PostAbuse, 'content@post_abuse')
# Settings
settings.define('content', _settings_form.Form, 'content@content', 'fa fa-glass', 'dev')
# Sitemap location in robots.txt
robots_txt.sitemap('/sitemap/index.xml')
def plugin_update(v_from: _Version):
if v_from < '4.20':
from pytsite import mongodb
mongodb.get_collection('content_model_entities').drop()