def fieldtype(bound_field): try: return camelcase_to_underscore(bound_field.field.__class__.__name__) except AttributeError: try: return camelcase_to_underscore(bound_field.__class__.__name__) except AttributeError: return ""
def widgettype(bound_field): try: return camelcase_to_underscore(bound_field.field.widget.__class__.__name__) except AttributeError: try: return camelcase_to_underscore(bound_field.widget.__class__.__name__) except AttributeError: return ""
def __init__(cls, name, bases, dct): super(PageBase, cls).__init__(name, bases, dct) if cls._deferred: # this is an internal class built for Django's deferred-attribute mechanism; # don't proceed with all this page type registration stuff return # Add page manager PageManager().contribute_to_class(cls, 'objects') if 'template' not in dct: # Define a default template path derived from the app name and model name cls.template = "%s/%s.html" % (cls._meta.app_label, camelcase_to_underscore(name)) if 'ajax_template' not in dct: cls.ajax_template = None cls._clean_subpage_types = None # to be filled in on first call to cls.clean_subpage_types if not dct.get('is_abstract'): # subclasses are only abstract if the subclass itself defines itself so cls.is_abstract = False if not cls.is_abstract: # register this type in the list of page content types PAGE_MODEL_CLASSES.append(cls)
def __init__(cls, name, bases, dct): super(PageBase, cls).__init__(name, bases, dct) if cls._deferred: # this is an internal class built for Django's deferred-attribute mechanism; # don't proceed with all this page type registration stuff return # Add page manager PageManager().contribute_to_class(cls, 'objects') if 'template' not in dct: # Define a default template path derived from the app name and model name cls.template = "%s/%s.html" % (cls._meta.app_label, camelcase_to_underscore(name)) if 'ajax_template' not in dct: cls.ajax_template = None cls._clean_subpage_types = None # to be filled in on first call to cls.clean_subpage_types cls._clean_parent_page_types = None # to be filled in on first call to cls.clean_parent_page_types if not dct.get('is_abstract'): # subclasses are only abstract if the subclass itself defines itself so cls.is_abstract = False if not cls.is_abstract: # register this type in the list of page content types PAGE_MODEL_CLASSES.append(cls)
def expand_db_attributes(attrs, for_editor): """ Given a dict of attributes from the <embed> tag, return the real HTML representation. """ st = attrs['snippet-type'] if st and '.' in st: st = st.split('.') Model = get_snippet_model(st[0], st[1]) if Model: try: snippet = Model.objects.get(id=attrs['id']) if for_editor: return '<div contenteditable="false" data-id="{0}" data-snippet-type="{1}" data-embedtype="snippet">Snippet: {0} ({1})</div>'.format(attrs['id'], attrs['snippet-type']) else: template_list = [ "%s/%s.html" % (snippet._meta.app_label, camelcase_to_underscore(snippet._meta.object_name)), "wagtailcore/snippet.html" ] return render_to_string(template_list, { 'snippet': snippet }) except Model.DoesNotExist: return '<div class="error-message">Snippet Does Not Exist</div>' return '<div class="error-message">Invalid Snippet</div>'
def get_template(self, request, *args, **kwargs): if request.is_ajax() and self.ajax_template: return self.ajax_template cls = self.__class__ template = "%s/%s/%s.html" % ( cls._meta.app_label, request.flavour, camelcase_to_underscore(cls.__name__), ) return template
def get_template(self, request, mode='', **kwargs): try: return self._path_overrideable_template except AttributeError: if not self.url: return get_template(self.template) path = self.url.strip('/') model_name = camelcase_to_underscore(self.specific_class.__name__) if mode: mode = ':' + mode model_template = model_name + mode + '.html' full_path = os.path.join('default', path + mode + '.html') templates = [full_path] logger.debug("Adding candidate template based on URL: %s", full_path) previous_index = len(path) while True: previous_index = path.rfind('/', 0, previous_index) if previous_index == -1: break candidate = os.path.join('default', path[0:previous_index + 1], model_template) templates.append(candidate) logger.debug( "Adding candidate template for path-based model override: %s", candidate) #templates.append("%s/%s" % (self.specific_class._meta.app_label, model_name)) templates.append( self.template ) # add the default template as the last one to seek logger.debug( "Adding candidate template based on model name only: %s", self.template) selected_template = select_template(templates) try: logger.debug("Selected template: %s", selected_template.name) except AttributeError: # Django 1.8 template refactoring... logger.debug("Selected template: %s", selected_template.template.name) self._path_overrideable_template = selected_template return self._path_overrideable_template
def get_template_name(cl): if not cl.template_name: cl.snake_name = camelcase_to_underscore(cl.__name__) cl.template_name = '{}/sections/{}.html'.format( cl._meta.app_label, cl.snake_name ) if cl.snake_name != 'section_item': from django.template import TemplateDoesNotExist try: from django.template.loader import get_template get_template(cl.template_name) except TemplateDoesNotExist: cl.template_name = 'aircox_cms/sections/section_item.html' return cl.template_name
def get_template(self, request, mode='', **kwargs): try: return self._path_overrideable_template except AttributeError: if not self.url: return get_template(self.template) path = self.url.strip('/') model_name = camelcase_to_underscore(self.specific_class.__name__) if mode: mode = ':'+mode model_template = model_name + mode + '.html' full_path = os.path.join('default', path+mode+'.html') templates = [full_path] logger.debug("Adding candidate template based on URL: %s", full_path) previous_index = len(path) while True: previous_index = path.rfind('/', 0, previous_index) if previous_index == -1: break candidate = os.path.join('default', path[0:previous_index+1], model_template) templates.append(candidate) logger.debug("Adding candidate template for path-based model override: %s", candidate) #templates.append("%s/%s" % (self.specific_class._meta.app_label, model_name)) templates.append(self.template) # add the default template as the last one to seek logger.debug("Adding candidate template based on model name only: %s", self.template) selected_template = select_template(templates) try: logger.debug("Selected template: %s", selected_template.name) except AttributeError: # Django 1.8 template refactoring... logger.debug("Selected template: %s", selected_template.template.name) self._path_overrideable_template = selected_template return self._path_overrideable_template
def field_type(self): return camelcase_to_underscore(self.bound_field.field.__class__.__name__)
def fieldtype(bound_field): return camelcase_to_underscore(bound_field.field.__class__.__name__)
def field_type(self): return camelcase_to_underscore(self.bound_field.field.__class__.__name__)
def snake_name(cl): if not hasattr(cl, '_snake_name'): cl._snake_name = camelcase_to_underscore(cl.__name__) return cl._snake_name
def fieldtype(bound_field): return camelcase_to_underscore(bound_field.field.__class__.__name__)
def widget_type(bound_field): return camelcase_to_underscore(bound_field.field.widget.__class__.__name__)