def get_form(self, request, obj=None, **kwargs): form = super(ChannelAdmin, self).get_form(request, obj, **kwargs) try: template = get_template_path( u'containers/{}/channel.json'.format(obj.slug)) f = open(template) channel_json = json.loads(f.read().replace('\n', '')) f.close() except: channel_json = [] if u'layout' in channel_json: layout_list = ['default'] + [l for l in channel_json['layout']] layout_choices = ( (n, n.title()) for n in layout_list) form.base_fields['layout'].choices = layout_choices return form
def _get_template_path(_path): template = get_template_path(_path) with open(template) as f: _jsonData = f.read().replace('\n', '') return json.loads(_jsonData)