def add_page_fileinfo(page, template_mapping, file_path, url, sitewide_file_path, mapping_sort=None): ''' Add a given page (could also be an index) to the fileinfo index. Called by the page builder routines. ''' try: existing_fileinfo = FileInfo.get( FileInfo.sitewide_file_path == sitewide_file_path, FileInfo.template_mapping == template_mapping) except FileInfo.DoesNotExist: new_fileinfo = FileInfo.create(page=page, template_mapping=template_mapping, file_path=file_path, sitewide_file_path=sitewide_file_path, url=url, mapping_sort=mapping_sort) fileinfo = new_fileinfo else: existing_fileinfo.file_path = file_path existing_fileinfo.sitewide_file_path = sitewide_file_path existing_fileinfo.url = url existing_fileinfo.modified_date = datetime.datetime.now() existing_fileinfo.mapping_sort = mapping_sort existing_fileinfo.save() fileinfo = existing_fileinfo return fileinfo
def add_page_fileinfo(page, template_mapping, file_path, url, sitewide_file_path, mapping_sort=None): ''' Add a given page (could also be an index) to the fileinfo index. If the page already exists, then the existing fileinfo is updated with the new information. Called by the page builder routines. :param page: The page object to add to the fileinfo index. :param template_mapping: The template mapping to use for creating the page's fileinfo(s). :param file_path: The file path to use for the fileinfo. :param url: The URL to associate with the fileinfo. :param sitewide_file_path: The sitewide file path to use for the fileinfo. :param mapping_sort: Sort order for the mapping, if used. ''' try: existing_fileinfo = FileInfo.get( FileInfo.sitewide_file_path == sitewide_file_path, FileInfo.template_mapping == template_mapping ) except FileInfo.DoesNotExist: try: new_fileinfo = FileInfo.create(page=page, template_mapping=template_mapping, file_path=file_path, sitewide_file_path=sitewide_file_path, url=url, mapping_sort=mapping_sort) fileinfo = new_fileinfo except IntegrityError: from core.error import FileInfoCollision collision = FileInfo.get( FileInfo.sitewide_file_path == sitewide_file_path) raise FileInfoCollision(''' Template mapping #{}, {}, for template #{}, yields a path that already exists in the system: {} This appears to be a collision with mapping {} in template {}'''.format( template_mapping.id, template_mapping.path_string, template_mapping.template.id, sitewide_file_path, collision.template_mapping.path_string, collision.template_mapping.template.for_log)) else: existing_fileinfo.file_path = file_path existing_fileinfo.sitewide_file_path = sitewide_file_path existing_fileinfo.url = url existing_fileinfo.modified_date = datetime.datetime.utcnow() existing_fileinfo.mapping_sort = mapping_sort existing_fileinfo.save() fileinfo = existing_fileinfo return fileinfo