|
@@ -1,3 +1,5 @@
|
|
1
|
+import os
|
|
2
|
+
|
1
|
3
|
import re
|
2
|
4
|
import transaction
|
3
|
5
|
|
|
@@ -24,50 +26,32 @@ CALENDAR_WORKSPACE_PATH_RE = 'workspace\/([0-9]+).ics'
|
24
|
26
|
CALENDAR_TYPE_USER = UserCalendar
|
25
|
27
|
CALENDAR_TYPE_WORKSPACE = WorkspaceCalendar
|
26
|
28
|
|
27
|
|
-CALENDAR_BASE_URL_TEMPLATE = '{proto}://{domain}:{port}'
|
28
|
|
-CALENDAR_USER_URL_TEMPLATE = \
|
29
|
|
- CALENDAR_BASE_URL_TEMPLATE + '/user/{id}.ics{extra}/'
|
30
|
|
-CALENDAR_WORKSPACE_URL_TEMPLATE = \
|
31
|
|
- CALENDAR_BASE_URL_TEMPLATE + '/workspace/{id}.ics{extra}/'
|
|
29
|
+CALENDAR_USER_URL_TEMPLATE = 'user/{id}.ics/'
|
|
30
|
+CALENDAR_WORKSPACE_URL_TEMPLATE = 'workspace/{id}.ics/'
|
32
|
31
|
|
33
|
32
|
|
34
|
33
|
class CalendarManager(object):
|
35
|
|
- @staticmethod
|
36
|
|
- def get_base_url():
|
37
|
|
- from tracim.config.app_cfg import CFG
|
38
|
|
- cfg = CFG.get_instance()
|
39
|
|
-
|
40
|
|
- return CALENDAR_BASE_URL_TEMPLATE.format(
|
41
|
|
- proto='https' if cfg.RADICALE_CLIENT_SSL else 'http',
|
42
|
|
- domain=cfg.RADICALE_CLIENT_HOST or '127.0.0.1',
|
43
|
|
- port=str(cfg.RADICALE_CLIENT_PORT)
|
44
|
|
- )
|
45
|
|
-
|
46
|
|
- @staticmethod
|
47
|
|
- def get_user_calendar_url(user_id: int, extra: str=''):
|
|
34
|
+ @classmethod
|
|
35
|
+ def get_base_url(cls):
|
48
|
36
|
from tracim.config.app_cfg import CFG
|
49
|
37
|
cfg = CFG.get_instance()
|
50
|
38
|
|
51
|
|
- return CALENDAR_USER_URL_TEMPLATE.format(
|
52
|
|
- proto='https' if cfg.RADICALE_CLIENT_SSL else 'http',
|
53
|
|
- domain=cfg.RADICALE_CLIENT_HOST or '127.0.0.1',
|
54
|
|
- port=str(cfg.RADICALE_CLIENT_PORT),
|
55
|
|
- id=str(user_id),
|
56
|
|
- extra=extra,
|
|
39
|
+ return cfg.RADICALE_CLIENT_BASE_URL_TEMPLATE.format(
|
|
40
|
+ server_name=cfg.WEBSITE_SERVER_NAME,
|
|
41
|
+ radicale_port=cfg.RADICALE_SERVER_PORT,
|
57
|
42
|
)
|
58
|
43
|
|
59
|
|
- @staticmethod
|
60
|
|
- def get_workspace_calendar_url(workspace_id: int, extra: str=''):
|
61
|
|
- from tracim.config.app_cfg import CFG
|
62
|
|
- cfg = CFG.get_instance()
|
|
44
|
+ @classmethod
|
|
45
|
+ def get_user_calendar_url(cls, user_id: int):
|
|
46
|
+ user_path = CALENDAR_USER_URL_TEMPLATE.format(id=str(user_id))
|
|
47
|
+ return os.path.join(cls.get_base_url(), user_path)
|
63
|
48
|
|
64
|
|
- return CALENDAR_WORKSPACE_URL_TEMPLATE.format(
|
65
|
|
- proto='https' if cfg.RADICALE_CLIENT_SSL else 'http',
|
66
|
|
- domain=cfg.RADICALE_CLIENT_HOST or '127.0.0.1',
|
67
|
|
- port=str(cfg.RADICALE_CLIENT_PORT),
|
68
|
|
- id=str(workspace_id),
|
69
|
|
- extra=extra,
|
|
49
|
+ @classmethod
|
|
50
|
+ def get_workspace_calendar_url(cls, workspace_id: int):
|
|
51
|
+ workspace_path = CALENDAR_WORKSPACE_URL_TEMPLATE.format(
|
|
52
|
+ id=str(workspace_id)
|
70
|
53
|
)
|
|
54
|
+ return os.path.join(cls.get_base_url(), workspace_path)
|
71
|
55
|
|
72
|
56
|
def __init__(self, user: User):
|
73
|
57
|
self._user = user
|