Example #1
0
 def result_for_item(self, headers, result, djp, nd = 3):
     if isinstance(result, self.model):
         request = djp.request
         path  = djp.http.path_with_query(request)
         first = True
         id    = ('%s-%s') % (self.module_name,result.id)
         display = []
         item = {'id':id,'display':display}
         for field_name in headers:
             result_repr = self.getrepr(field_name, result, nd)
             if force_str(result_repr) == '':
                 result_repr = mark_safe(' ')
             if (first and not self.list_display_links) or field_name in self.list_display_links:
                 first = False
                 url = self.url_for_result(request, result, field_name)
             else:
                 url = None
             
             var = conditional_escape(result_repr)
             if url:
                 if url != path:
                     var = mark_safe('<a href="{0}" title="{1}">{1}</a>'.format(url, var))
                 else:
                     var = mark_safe('<a>{0}</a>'.format(var))
             display.append(var)
         return item
     else:
         return nice_items_id(result, nd = nd)
Example #2
0
 def render(self, form, inputs = None):
     '''Render the uniform layout or *form*.'''
     ctx  = {}
     html = ''
     for field in self._allfields:
         h = field.render(form, self)
         if field.key and self.template:
             ctx[field.key] = h
         else:
             html += h
     
     missing_fields = []
     rendered_fields = get_rendered_fields(form)
     for field in form.fields.keys():
         if not field in rendered_fields:
             missing_fields.append(field)
     
     if missing_fields:
         fset = Fieldset(*missing_fields,**{'css_class':self.default_style})        
         html += fset.render(form,self)
             
     if ctx:
         ctx['inputs'] = inputs
         ctx['html'] = mark_safe(html)
         html = loader.render_to_string(self.template, ctx)
     else:
         html = mark_safe(html)
     
     if self.id:
         return mark_safe('<div id="%s">%s</div>' % (self.id,html))
     else:
         return html
Example #3
0
 def contentbits(self, page):
     b = u''
     if page:
         css = page.cssinfo
         if css and css.container_class_name:
             b = ' class="%s"' % css.container_class_name
     return mark_safe(b)
Example #4
0
 def __init__(self, parent_model, model, legend = None, **kwargs):
     self.parent_model = parent_model
     self.model   = model
     if legend is not False:
         legend = legend or force_str(model._meta.verbose_name_plural)
     self.legend = mark_safe('' if not legend else '<legend>'+legend+'</legend>')
     self.FormSet = inlineformset_factory(parent_model, model, **kwargs)
Example #5
0
 def object_links(self, djp, obj, asbuttons=True, exclude=None):
     """Create permitted object links"""
     css = djp.css
     next = djp.url
     request = djp.request
     post = ("post",)
     posts = []
     gets = []
     exclude = self.exclude_object_links
     content = {"geturls": gets, "posturls": posts, "module_name": self.opts.module_name}
     for view in self.object_views:
         djpv = view(request, instance=obj)
         if view.has_permission(request, djpv.page, obj):
             url = djpv.url
             name = view.name
             if name in exclude:
                 continue
             if not isinstance(view, ViewView):
                 url = "%s?next=%s" % (url, view.nextviewurl(djp))
                 title = ' title="%s %s"' % (name, obj)
                 if view.methods(request) == post:
                     cl = ' class="%s %s"' % (css.ajax, css.nicebutton)
                 else:
                     cl = ' class="%s"' % css.nicebutton
                 posts.append(mark_safe('<a href="%s"%s%s name="%s">%s</a>' % (url, cl, title, name, name)))
             content["%surl" % name] = url
     return content
Example #6
0
 def _getrepr(self, name, instance):
     try:
         f, attr, value = lookup_field(name, instance, self.model_admin)
     except (AttributeError, ObjectDoesNotExist):
         result_repr = self.get_value(instance, name, sites.settings.DJPCMS_EMPTY_VALUE)
     else:
         if f is None:
             allow_tags = getattr(attr, 'allow_tags', False)
             boolean = getattr(attr, 'boolean', False)
             if boolean:
                 allow_tags = True
                 result_repr = _boolean_icon(value)
             else:
                 result_repr = force_str(value)
             # Strip HTML tags in the resulting text, except if the
             # function has an "allow_tags" attribute set to True.
             if not allow_tags:
                 result_repr = escape(result_repr)
             else:
                 result_repr = mark_safe(result_repr)
         else:
             if value is None:
                 result_repr = sites.settings.DJPCMS_EMPTY_VALUE
             if isinstance(f.rel, models.ManyToOneRel):
                 result_repr = escape(getattr(instance, f.name))
             else:
                 result_repr = display_for_field(value, f)
     return result_repr
Example #7
0
def styling():
    murl = sites.settings.MEDIA_URL
    css = ['<link rel="stylesheet" type="text/css" href="%sdjpcms/jquery-ui-css/%s.css"/>' % (murl,DJPCMS_SITE_STYLE),
           '<link rel="stylesheet" type="text/css" href="%sdjpcms/djpcms.css"/>' % murl,
           '<link rel="stylesheet" type="text/css" href="%sdjpcms/jquery-ui-css/%s/jquery-ui-1.7.2.custom.css"/>' % (murl,DJPCMS_SITE_STYLE),
           '<link rel="stylesheet" type="text/css" href="%sdjpcms/jquery-ui-css/%s.css"/>' % (murl,DJPCMS_SITE_STYLE),
           '<link rel="stylesheet" type="text/css" href="%ssite/layout.css"/>' % murl]
    return mark_safe(u'\n'.join(css))
Example #8
0
 def _tohtml(self, text, mkp):
     if not text:
         return u''
     
     if mkp:
         handler = mkp.get('handler')
         text = handler(text)
     
     return mark_safe(text)
Example #9
0
 def flatattr(self):
     attr = []
     for k,v in self.attr.items():
         if v:
             attr.append('%s="%s"' % (k,v))
     if attr:
         return mark_safe(' %s' % ' '.join(attr))
     else:
         return ''
Example #10
0
 def bodybits(self, page):
     b = u''
     if self.editurl:
         b = u'class="edit"'
     elif page:
         css = page.cssinfo
         if css and css.body_class_name:
             b = 'class="%s"' % css.body_class_name
     return mark_safe(b)
Example #11
0
def _css_validator(version = 2, color = ''):
    if version == 1 or version == 2:
        src = "http://www.w3.org/Icons/valid-css%s%s.png" % (version,color)
    else:
        src = "#"
    va = """
    <a href="http://jigsaw.w3.org/css-validator/" title="Validate CSS code">
    <img src="%s" alt="W3C CSS %s"/></a>
    """ % (src,version)
    return mark_safe(va)
Example #12
0
 def _render(self, form, layout):
     css = self._css(layout)
     content = {}
     for i,column in enumerate(self.columns):
         output = u'<div class="%s">' % css
         for field in column:
             output += render_field(field, form, layout, self.css)
         output += u'</div>'
         content['content%s' % i] = mark_safe(output)
     return loader.render_to_string(self.template, content)
Example #13
0
 def _render(self, form, layout):
     if self.css:
         html = u'<fieldset class="%s">' % self.css
     else:
         html = u'<fieldset>'
     html += self.legend_html
     for field in self.fields:
         html += render_field(field, form, layout, self.css)
     html += u'</fieldset>'
     return mark_safe(html)
Example #14
0
 def htmlbody(self):
     text = self.body
     if not text:
         return ''
     mkp = markuplib.get(self.markup)
     if mkp:
         handler = mkp.get('handler')
         text = handler(text)
         text = mark_safe(force_str(text))
     return text
Example #15
0
 def render(self):
     '''Render the Block by looping over all the content block items
     '''
     edit = '' if not self.view.editurl else 'sortable-block '
     id   = block_htmlid(self.page.id,self.b)
     html = ['<div id="{0}" class="{1}djpcms-block">'.format(id,edit)]
     for ht in self.blocks():
         if ht:
             html.append(ht)
     html.append('%s</div>' % self.empty())
     return mark_safe(force_str('\n'.join(html)))
Example #16
0
def lloogg_analytics():
    if sites.settings.LLOOGG_ANALYTICS_ID:
        an = """
    <script type="text/javascript">
        lloogg_clientid = "%s";
    </script>
    <script type="text/javascript" src="http://lloogg.com/l.js?c=%s">
    </script>
        """ % (sites.settings.LLOOGG_ANALYTICS_ID,sites.settings.LLOOGG_ANALYTICS_ID)
        return mark_safe(an)
    else:
        return ''
Example #17
0
 def render(self, djp, wrapper, prefix, site_content = None, **kwargs):
     if site_content:
         try:
             site_content = SiteContent.objects.get(id = int(site_content))
             return mark_safe('\n'.join(['<div class="djpcms-text-content">',
                                         site_content.htmlbody(),
                                         '</div>']))
         except Exception, e:
             if djp.settings.DEBUG:
                 return u'%s' % e 
             else:
                 return u''
Example #18
0
 def __init__(self, columns, fixed):
     self.fixed  = fixed
     self.clear  = mark_safe('<div class="clear"></div>')
     c4 = columns/4
     c6 = columns/6
     c3 = 2*c6
     self.container_class = 'container_%s' % columns
     self.column1 = 'grid_%s' % columns
     self.column_1_2 = 'grid_%s' % (2*c4,)
     self.column_3_4 = 'grid_%s' % (3*c4,)
     self.column_1_4 = 'grid_%s' % c4
     self.column_1_3 = 'grid_%s' % c3
     self.column_1_6 = 'grid_%s' % c6
     self.column_2_3 = 'grid_%s' % (2*c3,)
     self.column_5_6 = 'grid_%s' % (5*c6,)
Example #19
0
def google_analytics():
    if sites.settings.GOOGLE_ANALYTICS_ID:
        an = """
    <script type="text/javascript">
        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
        document.write(unescape("%%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%%3E%%3C/script%%3E"));
    </script>
    <script type="text/javascript">
        var pageTracker = _gat._getTracker("%s");
        pageTracker._initData();
        pageTracker._trackPageview();
    </script>
        """ % sites.settings.GOOGLE_ANALYTICS_ID
        return mark_safe(an)
    else:
        return u''
Example #20
0
 def links(self, djp, asbuttons=True, exclude=None):
     """Create a list of application links available to the user"""
     css = djp.css
     next = djp.url
     request = djp.request
     post = ("post",)
     posts = []
     gets = []
     exclude = exclude or []
     for ex in self.exclude_links:
         if ex not in exclude:
             exclude.append(ex)
     content = {"geturls": gets, "posturls": posts}
     kwargs = djp.kwargs
     for view in self.views.itervalues():
         if view.object_view:
             continue
         name = view.name
         if name in exclude:
             continue
         djpv = view(request, **kwargs)
         if view.has_permission(request):
             url = "%s?next=%s" % (djpv.url, view.nextviewurl(djp))
             title = ' title="%s"' % name
             if asbuttons:
                 if view.methods(request) == post:
                     cl = ' class="%s %s"' % (css.ajax, css.nicebutton)
                 else:
                     cl = ' class="%s"' % css.nicebutton
             else:
                 if view.methods(request) == post:
                     cl = ' class="%s"' % css.ajax
                 else:
                     cl = " "
             posts.append(mark_safe('<a href="{0}"{1}{2} name="{3}">{3}</a>'.format(url, cl, title, name)))
             content["%surl" % name] = url
     return content
Example #21
0
def box(hd = None, bd = None, ft = None, minimize = False, rounded = True,
        collapsable = False, collapsed = False, classes = None,  id = None,
        delurl = None):
    from djpcms.template import loader, mark_safe
    classes = classes or []
    menulist = []
    if collapsed:
        classes.append('collapsed')
        collapsable = True
    if collapsable:
        classes.append('collapsable')
        menulist.append(mark_safe('<a class="collapse" href="#">COLLAPSE</a>'))
    if delurl:
        menulist.append(mark_safe('<a class="deletable ajax" href="%s">DELETE</a>' % delurl))
    c = {'id': id,
         'title': None if not hd else mark_safe(hd),
         'hd': True,
         'bd': None if not bd else mark_safe(bd),
         'ft': None if not ft else mark_safe(ft),
         'menulist': menulist,
         'classes': mark_safe(' '.join(classes))}
    return loader.render_to_string(['box.html',
                                    'content/box.html',
                                    'djpcms/content/box.html'], c)
Example #22
0
        kind = args[1]
        if not kind in ['css', 'js']:
            raise template.TemplateSyntaxError("%r's argument must be 'js' or 'css'." % args[0])

        return CompressorNode(nodelist, kind)
    else:
        return DummyCompressorNode(nodelist)
    
@register.filter
def cleanjs(media):
    try:
        media._js.remove('%sjs/jquery.min.js' % sites.settings.ADMIN_MEDIA_PREFIX)
    except Exception, e:
        pass
    jss = media.render_js()
    return mark_safe(u'\n'.join(jss))

#@register.filter
#def djplugin(name,args = None):
#    '''
#    display a plugin
#    '''
#    plugin = get_plugin(name)
#    if plugin:
#        return plugin.render()
#    else:
#        return ''


def google_analytics():
    if sites.settings.GOOGLE_ANALYTICS_ID:
Example #23
0
 def render(self):
     return mark_safe(u'\n'.join(['<%s%s>' % (self.tag,self.flatatt()),
                                  self.inner,
                                  '</%s>' % self.tag]))
Example #24
0
 def __init__(self, html, **kwargs):
     self.html = mark_safe(html)
Example #25
0
 def bodybits(self):
     if self.editurl:
         return mark_safe(u'class="edit documentation"')
     else:
         return mark_safe(u'class="documentation"')
Example #26
0
def _boolean_icon(val):
    v = BOOLEAN_MAPPING.get(val,'unknown')
    return mark_safe(u'<span class="ui-icon %(icon)s" title="%(name)s">%(name)s</span>' % v)
Example #27
0
 def render_inputs(self):
     if self.inputs:
         c = {'inputs':(mark_safe(s) for s in self.inputs)}
         return loader.render_to_string('djpcms/uniforms/inputs.html',c)
     else:
         return ''
Example #28
0
 def render(self):
     return mark_safe(u'\n'.join(chain(*[getattr(self, 'render_' + name)() for name in MEDIA_TYPES])))
Example #29
0
 def _make_messages(self, cname, mlist):
     if mlist:
         return mark_safe('<ul class="%s"><li>%s</li></ul>' % (cname,'</li><li>'.join(mlist)))
     else:
         return u''
Example #30
0

inlineLabels   = 'inlineLabels'
inlineLabels2  = 'inlineLabels fullwidth'
inlineLabels3  = 'inlineLabels auto'
blockLabels    = 'blockLabels'
blockLabels2   = 'blockLabels2'
inlineFormsets = 'blockLabels2'
nolabel        = 'nolabel'
default_style  = inlineLabels

def default_csrf():
    return 'django.middleware.csrf.CsrfViewMiddleware' in sites.settings.MIDDLEWARE_CLASSES

#_required_tag = mark_safe('<em>*</em>')
_required_tag = mark_safe('')

#default renderer for forms
def_renderer = lambda x: x


def render_field(field, form, layout, css_class):
    if isinstance(field, str):
        return render_form_field(field, form, layout, css_class)
    else:
        return field.render(form, layout)
    
def get_rendered_fields(form):
    rf = getattr(form, 'rendered_fields', [])
    form.rendered_fields = rf
    return rf