0

I'm using django DateTimePicker widget -- AdminSplitDateTime() -- in event creating app, every thing goes fine when the loged in user has superuser permissions, but when normal user tries to access the creating form the widget don't show up.

I don't know why it acts like this? and how to overcome this behavior?

this is the the scripts included in my page

<script type="text/javascript" src="/admin/jsi18n/"></script>
<script type="text/javascript" src="/static/admin/js/core.js"></script>
<script type="text/javascript" src="/static/admin/js/admin/RelatedObjectLookups.js"></script>
<script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/admin/js/jquery.init.js"></script>
<script type="text/javascript" src="/static/admin/js/actions.min.js"></script>
<script type="text/javascript" src="/static/admin/js/calendar.js"></script>
<script type="text/javascript" src="/static/admin/js/admin/DateTimeShortcuts.js"></script>

her is my form code

class Form(ModelForm):
    """

    """

    class Meta:
        model = Model
        exclude = ('creator')
    def __init__(self, *args, **kwargs):
        super(Form, self).__init__(*args, **kwargs)
        self.fields['start'].widget = widgets.AdminSplitDateTime()
        self.fields['end'].widget = widgets.AdminSplitDateTime()
UXE
  • 2,374
  • 2
  • 18
  • 17

1 Answers1

0

I guess /admin/jsi18n/ is unaccessible for non-staff users. You should add a JS script before the first widget and define there some vars:

var catalog = {}
function pluralidx(count) { return (count == 1) ? 0 : 1; }
function gettext(msgid) { return msgid; }
function ngettext(singular, plural, count) { return count == 1 ? singular : plural; }
function gettext_noop(msgid) { return msgid; }
function interpolate(fmt, obj, named) {
  if (named) {
    return fmt.replace(/%\(\w+\)s/g, function(match){return String(obj[match.slice(2,-2)])});
  } else {
    return fmt.replace(/%s/g, function(match){return String(obj.shift())});
  }
}

These are taken from django's /admin/jsi18n/ under admin user.

P.S. You can find JS errors in JS console of your browser, it may give you the direction.

ilvar
  • 5,718
  • 1
  • 20
  • 17