'Import fields data content from files'

def _load_extra_content(self, system, course_descriptor, category, content_path, course_dir):

    for filepath in glob.glob((content_path / '*')):
        if (not os.path.isfile(filepath)):
            continue
        if filepath.endswith('~'):
            continue
        with open(filepath) as f:
            try:
                if (filepath.find('.json') != (-1)):
                    (slug, loc, data_content) = self._import_field_content(course_descriptor, category, filepath)
                    if (data_content is None):
                        continue
                    else:
                        try:
                            module = system.load_item(loc)
                            for (key, value) in data_content.iteritems():
                                setattr(module, key, value)
                            module.save()
                        except ItemNotFoundError:
                            module = None
                            data_content['location'] = loc
                            data_content['category'] = category
                else:
                    slug = os.path.splitext(os.path.basename(filepath))[0]
                    loc = course_descriptor.scope_ids.usage_id.replace(category=category, name=slug)
                    html = f.read().decode('utf-8')
                    try:
                        module = system.load_item(loc)
                        module.data = html
                        module.save()
                    except ItemNotFoundError:
                        module = None
                        data_content = {'data': html, 'location': loc, 'category': category}
                if (module is None):
                    module = system.construct_xblock(category, ScopeIds(None, category, loc, loc), DictFieldData(data_content))
                    if (category == 'static_tab'):
                        dog_stats_api.increment(DEPRECATION_VSCOMPAT_EVENT, tags=('location:xml_load_extra_content_static_tab', u'course_dir:{}'.format(course_dir)))
                        tab = CourseTabList.get_tab_by_slug(tab_list=course_descriptor.tabs, url_slug=slug)
                        if tab:
                            module.display_name = tab.name
                            module.course_staff_only = tab.course_staff_only
                    module.data_dir = course_dir
                    module.save()
                    self.modules[course_descriptor.id][module.scope_ids.usage_id] = module
            except Exception as exc:
                logging.exception('Failed    to    load    %s.    Skipping...                                                                                                                    Exception:    %s', filepath, unicode(exc))
                system.error_tracker(('ERROR:    ' + unicode(exc)))
