|  | @@ -1,3 +1,5 @@
 | 
	
		
			
			|  | 1 | +import os
 | 
	
		
			
			|  | 2 | +
 | 
	
		
			
			| 1 | 3 |  import re
 | 
	
		
			
			| 2 | 4 |  import transaction
 | 
	
		
			
			| 3 | 5 |  
 | 
	
	
		
			
			|  | @@ -24,50 +26,28 @@ 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()
 | 
	
		
			
			|  | 38 | +        return cfg.RADICALE_CLIENT_BASE_URL_TEMPLATE
 | 
	
		
			
			| 50 | 39 |  
 | 
	
		
			
			| 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,
 | 
	
		
			
			| 57 |  | -        )
 | 
	
		
			
			| 58 |  | -
 | 
	
		
			
			| 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()
 | 
	
		
			
			|  | 40 | +    @classmethod
 | 
	
		
			
			|  | 41 | +    def get_user_calendar_url(cls, user_id: int):
 | 
	
		
			
			|  | 42 | +        user_path = CALENDAR_USER_URL_TEMPLATE.format(id=str(user_id))
 | 
	
		
			
			|  | 43 | +        return os.path.join(cls.get_base_url(), user_path)
 | 
	
		
			
			| 63 | 44 |  
 | 
	
		
			
			| 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,
 | 
	
		
			
			|  | 45 | +    @classmethod
 | 
	
		
			
			|  | 46 | +    def get_workspace_calendar_url(cls, workspace_id: int):
 | 
	
		
			
			|  | 47 | +        workspace_path = CALENDAR_WORKSPACE_URL_TEMPLATE.format(
 | 
	
		
			
			|  | 48 | +            id=str(workspace_id)
 | 
	
		
			
			| 70 | 49 |          )
 | 
	
		
			
			|  | 50 | +        return os.path.join(cls.get_base_url(), workspace_path)
 | 
	
		
			
			| 71 | 51 |  
 | 
	
		
			
			| 72 | 52 |      def __init__(self, user: User):
 | 
	
		
			
			| 73 | 53 |          self._user = user
 |