
from bootstrap3.renderers import FormRenderer
from django.utils.safestring import mark_safe
from django_jinja import library

from shoop.admin.template_helpers import shoop_admin as shoop_admin_template_helpers
from shoop.admin.utils.bs3_renderers import AdminFieldRenderer


class Bootstrap3Namespace(object):
    def field(self, field, **kwargs):
        if not field:
            return ""
        return mark_safe(AdminFieldRenderer(field, **kwargs).render())

    def form(self, form, **kwargs):
        return mark_safe(FormRenderer(form, **kwargs).render())


library.global_function(name="shoop_admin", fn=shoop_admin_template_helpers)
library.global_function(name="bs3", fn=Bootstrap3Namespace())


from bootstrap3.renderers import FormRenderer
from django.utils.safestring import mark_safe
from django_jinja import library

from shoop.admin.template_helpers import shoop_admin as shoop_admin_template_helpers
from shoop.admin.utils.bs3_renderers import AdminFieldRenderer


class Bootstrap3Namespace(object):
    def field(self, field, **kwargs):
        if not field:
            return ""
        return mark_safe(AdminFieldRenderer(field, **kwargs).render())

    def form(self, form, **kwargs):
        return mark_safe(FormRenderer(form, **kwargs).render())

    def datetime_field(self, field, **kwargs):
        kwargs.setdefault("widget_class", "datetime")
        kwargs.setdefault("addon_after", "<span class='fa fa-calendar'></span>")
        return self.field(field, **kwargs)


library.global_function(name="shoop_admin", fn=shoop_admin_template_helpers)
library.global_function(name="bs3", fn=Bootstrap3Namespace())

Add template helper for datetime fields
Admin: Add template helper for datetime fields

Refs SHOOP-1612

  
  from bootstrap3.renderers import FormRenderer
  from django.utils.safestring import mark_safe
  from django_jinja import library
  
  from shoop.admin.template_helpers import shoop_admin as shoop_admin_template_helpers
  from shoop.admin.utils.bs3_renderers import AdminFieldRenderer
  
  
  class Bootstrap3Namespace(object):
      def field(self, field, **kwargs):
          if not field:
              return ""
          return mark_safe(AdminFieldRenderer(field, **kwargs).render())
  
      def form(self, form, **kwargs):
          return mark_safe(FormRenderer(form, **kwargs).render())
  
+     def datetime_field(self, field, **kwargs):
+         kwargs.setdefault("widget_class", "datetime")
+         kwargs.setdefault("addon_after", "<span class='fa fa-calendar'></span>")
+         return self.field(field, **kwargs)
+ 
  
  library.global_function(name="shoop_admin", fn=shoop_admin_template_helpers)
  library.global_function(name="bs3", fn=Bootstrap3Namespace())
  
Add template helper for datetime fields
## Code Before:

from bootstrap3.renderers import FormRenderer
from django.utils.safestring import mark_safe
from django_jinja import library

from shoop.admin.template_helpers import shoop_admin as shoop_admin_template_helpers
from shoop.admin.utils.bs3_renderers import AdminFieldRenderer


class Bootstrap3Namespace(object):
    def field(self, field, **kwargs):
        if not field:
            return ""
        return mark_safe(AdminFieldRenderer(field, **kwargs).render())

    def form(self, form, **kwargs):
        return mark_safe(FormRenderer(form, **kwargs).render())


library.global_function(name="shoop_admin", fn=shoop_admin_template_helpers)
library.global_function(name="bs3", fn=Bootstrap3Namespace())

## Instruction:
Add template helper for datetime fields
## Code After:

from bootstrap3.renderers import FormRenderer
from django.utils.safestring import mark_safe
from django_jinja import library

from shoop.admin.template_helpers import shoop_admin as shoop_admin_template_helpers
from shoop.admin.utils.bs3_renderers import AdminFieldRenderer


class Bootstrap3Namespace(object):
    def field(self, field, **kwargs):
        if not field:
            return ""
        return mark_safe(AdminFieldRenderer(field, **kwargs).render())

    def form(self, form, **kwargs):
        return mark_safe(FormRenderer(form, **kwargs).render())

    def datetime_field(self, field, **kwargs):
        kwargs.setdefault("widget_class", "datetime")
        kwargs.setdefault("addon_after", "<span class='fa fa-calendar'></span>")
        return self.field(field, **kwargs)


library.global_function(name="shoop_admin", fn=shoop_admin_template_helpers)
library.global_function(name="bs3", fn=Bootstrap3Namespace())
