def load_files(self, paths): results = {} for path in paths: data = Hugo_Page().load(path) if data: results[data.get('path')] = data return results
def __init__(self, name=None, folder_oss=None): self.base_folder = 'content/participant/' self.hugo_page = Hugo_Page(base_folder=self.base_folder,folder_oss=folder_oss) self.name = name.strip() self.data = None self.path_md_file = None if self.name: self.load()
def load_files(self, paths, index_by_title=False): results = {} for path in paths: data = Hugo_Page().load(path) if data: if index_by_title: results[data.get('metadata').get('title')] = data else: results[data.get('path')] = data return results
def __init__(self): self.folder_oss = Hugo_Page().folder_oss self._participants = None self._sessions = None
def setUp(self): self.base_folder = 'content/participant' self.hugo_page = Hugo_Page(self.base_folder) self.result = None
class test_Hugo_Page(TestCase): def setUp(self): self.base_folder = 'content/participant' self.hugo_page = Hugo_Page(self.base_folder) self.result = None def tearDown(self): if self.result is not None: Dev.pprint(self.result) def test__init__(self): assert Files.folder_exists(self.hugo_page.folder_oss) assert Files.file_name(self.hugo_page.folder_oss) == 'oss2019' assert Files.exists(self.hugo_page.file_template) def test_participant_create(self): name = 'an test user' result = self.hugo_page.create(name) assert result.get('status') == 'ok' data = result.get('data') path = self.hugo_page.md_file_path(data['path']) assert data['metadata']['title'] == 'an test user' assert data['path'] == '/content/participant/an-test-user.md' assert Files.exists(path) is True assert self.hugo_page.delete(name) is True assert Files.exists(path) is False def test_load_file(self): file_path = self.hugo_page.file_template data = self.hugo_page.load(file_path) assert data == { 'path': '/content/participant/_template.md', 'content': '<!-- put more details about participant here -->', 'metadata': { 'chapter_leader': '', 'company': '', 'email': '', 'eventbrite_id': '', 'facebook': '', 'image': '', 'job_title': '', 'linkedin': '', 'notes': '', 'project_leader': '', 'sessions': [], 'status': 'add-details', 'title': '', 'travel_from': '', 'twitter': '', 'type': 'participant', 'website': '' } } def test_load_save(self): file_path = self.hugo_page.file_template data = self.hugo_page.load(file_path) result = self.hugo_page.save(data) assert result.get('status') == 'ok'
class OSS_Participant: def __init__(self, name=None, folder_oss=None): self.base_folder = 'content/participant/' self.hugo_page = Hugo_Page(base_folder=self.base_folder, folder_oss=folder_oss) self.name = name.strip() if name else None self.data = None self.path_md_file = None if self.name: self.load() def create(self): if self.exists() is False: self.hugo_page.create(self.name) self.load() return self def delete(self): if self.exists() is False: return False self.hugo_page.delete(self.path_md_file) return self.exists() is False def delete_field(self, field, auto_save=False): if field in self.fields(): del self.metadata()[field] if auto_save: self.save() return True return False def exists(self): self.load() return Files.exists(self.path_md_file) def field(self, key, value=None): metadata = self.metadata() if metadata: if value is not None: metadata[key] = value return self else: return metadata.get(key) return None def fields(self): metadata = self.metadata() if metadata: return list(set(self.metadata())) return [] def load(self, reload=False): if self.data is None or reload: path = self.name if Files.exists(path) and '.md' in path: self.path_md_file = path else: if '.md' not in path: path = self.hugo_page.fix_name(path) + '.md' if self.name.startswith(self.base_folder) is False: # fix path path = self.base_folder + path self.path_md_file = self.hugo_page.md_file_path(path) if Files.not_exists(self.path_md_file): self.path_md_file = self.hugo_page.find_in_md_files(self.name) self.data = self.hugo_page.load(self.path_md_file) title = self.field('title') if title: self.name = title return self def metadata(self): if self.data: return self.data.get('metadata') return None def save(self): self.hugo_page.save(self.data) return self def set_field(self, key, value): return self.field(key, value)
def __init__(self, name=None): self.base_folder = 'content/tracks/' self.hugo_page = Hugo_Page(base_folder=self.base_folder) self.name = name self.data = None self.path_md_file = None
class OSS_Session: def __init__(self, name=None): self.base_folder = 'content/tracks/' self.hugo_page = Hugo_Page(base_folder=self.base_folder) self.name = name self.data = None self.path_md_file = None #if self.name: # self.load() def create(self): if self.exists() is False: self.hugo_page.create(self.name) self.load() return self def delete(self): if self.exists() is False: return False self.hugo_page.delete(self.path_md_file) return self.exists() is False def exists(self): self.load() return Files.exists(self.path_md_file) def field(self, key, value=None): metadata = self.metadata() if metadata: if value is not None: metadata[key] = value return self else: return metadata.get(key) return None def fields(self): metadata = self.metadata() if metadata: return list(set(self.metadata())) return [] def load(self, reload=False): if self.data is None or reload: path = self.name if Files.exists(path) and '.md' in path: self.path_md_file = path else: if '.md' not in path: path = self.hugo_page.fix_name(path) + '.md' if self.name.startswith(self.base_folder) is False: # fix path path = self.base_folder + path self.path_md_file = self.hugo_page.md_file_path(path) self.data = self.hugo_page.load(self.path_md_file) title = self.field('title') if title: self.name = title return self def metadata(self): if self.data: return self.data.get('metadata') return None def save(self): self.hugo_page.save(self.data) return self def set_field(self, key, value): return self.field(key, value)