def __init__(self, *args, **kwargs): # Set view_name choices to url pattern names self.declared_fields['view_name'].choices = [('', '-- Select --'), ] + \ get_view_choices() super(LinkAdminForm, self).__init__(*args, **kwargs) instance = kwargs.get('instance', None) if (instance is not None) and instance.target: self.fields['target'].initial = instance.target
def __init__(self, *args, **kwargs): super(TileEditAjaxForm, self).__init__(*args, **kwargs) # Target choices choices = [] for klass in (Menu, Navbar, Listing): ctid = ContentType.objects.get(app_label='foundry', model=klass.__name__.lower()).id for o in klass.objects.filter(sites__in=kwargs['instance'].column.row.page.sites.all()).distinct(): title = o.title subtitle = getattr(o, 'subtitle', None) if subtitle: title = '%s (%s)' % (title, subtitle) choices.append( ('%s_%s' % (ctid, o.id), '%s: %s' % (klass.__name__, title)) ) self.fields['target'].choices = [('', '-- Select --')] + choices # Initial target if self.instance and self.instance.target: self.fields['target'].initial = '%s_%s' % \ (self.instance.target_content_type.id, self.instance.target_object_id) self.fields['view_name'].widget.choices = [('', '-- Select --')] + get_view_choices()
def __init__(self, *args, **kwargs): super(TileEditAjaxForm, self).__init__(*args, **kwargs) # Target choices choices = [] # xxx: revert until lookups work correctly #tileproviders = [ # m for m in models.get_models() if classImplements(m, ITileProvider) #] tileproviders = [ m for m in models.get_models() if "ITileProvider" in [ interface.getName() for interface in implementedBy(m) ] ] for klass in tileproviders: ctid = ContentType.objects.get( app_label='foundry', model=klass.__name__.lower() ).id for o in klass.objects.filter(sites__in=kwargs['instance'].column.row.page.sites.all()).distinct(): title = o.title subtitle = getattr(o, 'subtitle', None) if subtitle: title = '%s (%s)' % (title, subtitle) choices.append( ('%s_%s' % (ctid, o.id), '%s: %s' % (klass.__name__, title)) ) self.fields['target'].choices = [('', '-- Select --')] + choices # Initial target if self.instance and self.instance.target: self.fields['target'].initial = '%s_%s' % ( self.instance.target_content_type.id, self.instance.target_object_id ) self.fields['view_name'].widget.choices = [('', '-- Select --')] + get_view_choices()
def __init__(self, *args, **kwargs): super(PageViewForm, self).__init__(*args, **kwargs) self.fields['view_name'].widget = forms.widgets.Select( choices=[('', '')] + get_view_choices() )
def __init__(self, *args, **kwargs): super(ViewProxyAdminForm, self).__init__(*args, **kwargs) self.fields["view_name"].widget.choices = get_view_choices()