def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._people = ControlButton('<i class="icon users"></i>People', css=' circular ', label_visible=False, default='window.location="/app/people/";') self._contracts = ControlButton( '<i class="icon file outline"></i>Contracts', css=' circular ', label_visible=False, default='window.location="/app/contracts/";') self._proposals = ControlButton( '<i class="icon file"></i>Proposals', css=' circular ', label_visible=False, default='window.location="/app/proposals/";') self._orders = ControlButton('<i class="icon dollar"></i>Orders', css=' circular ', label_visible=False, default='window.location="/app/orders/";') self.formset = [ 'h2:Human resources', no_columns('_people', '_contracts', '_proposals'), '-', 'h2:Orders', no_columns('_orders') ]
def __init__(self, *args, **kwargs): super(DefaultApp, self).__init__(*args, **kwargs) self._css_btn = ControlButton( '<i class="icon toggle on" ></i>Toggle css', default=self.__toggle_css_evt, label_visible=False) self._toggle_btn = ControlButton( '<i class="icon eye" ></i>Toggle visibility', default=self.__toggle_visibility_evt, label_visible=False) self._copy_btn = ControlButton( '<i class="icon copy outline" ></i>Copy the text', default=self.__copy_text_evt, label_visible=False) self._input = ControlText( 'Type something here and press the copy button', changed_event=self.__input_changed_evt) self._text = ControlTextArea('Result') self._combo = ControlCombo('Combo', items=[('Item 1', 1), ('Item 2', 2), ('Item 3', 3)]) self._check = ControlCheckBox('Check box') self._list = ControlList('List') self._label = ControlLabel('Label', default='Use the label for a dynamic text') self.formset = [ no_columns('_toggle_btn', '_copy_btn', '_css_btn'), ' ', '_input', '_text', { 'Free text': [ 'h1:Header 1', 'h2:Header 2', 'h3:Header 3', 'h4:Header 4', 'h5:Header 5', 'h1-right:Header 1', 'h2-right:Header 2', 'h3-right:Header 3', 'h4-right:Header 4', 'h5-right:Header 5', '-', 'Free text here', 'msg:Message text', 'info:Info message', 'warning:Warning message', 'alert:Alert message' ], 'Segments': [ 'The next example has a segment', segment('_combo', '_check', css='secondary'), '_list', '_label' ] } ]
def __init__(self, *args, **kwargs): """ :param str title: Title of the app. By default will assume the value in the class variable TITLE. :param django.db.models.Model model: Model the App will manages. By default will assume the value in the class variable MODEL. :param class editform_class: Class used to generate the edition form. By default will assume the value in the class variable EDITFORM_CLASS. :param int parent_pk: (optional) Used to generate the inline interface. Primary key of the parent model :param Model parent_model: (optional) Used to generate the inline interface. Parent model """ title = kwargs.get('title', self.TITLE) self.model = kwargs.get('model', self.MODEL) self.editmodel_class = kwargs.get('editform_class', self.EDITFORM_CLASS) self.addmodel_class = kwargs.get('addform_class', self.ADDFORM_CLASS if self.ADDFORM_CLASS else self.editmodel_class) # Set the class to behave as inline ModelAdmin ######## self.parent_field = None self.parent_pk = kwargs.get('parent_pk', None) self.parent_model = kwargs.get('parent_model', None) if self.parent_model and self.parent_pk: self.set_parent(self.parent_model, self.parent_pk) has_add_permission = self.has_add_permission() and self.addmodel_class is not None has_edit_permission = self.has_edit_permission() and self.editmodel_class is not None BaseWidget.__init__(self, title) ####################################################### self._list = self.CONTROL_LIST( 'List', list_display = self.LIST_DISPLAY if self.LIST_DISPLAY else [], list_filter = self.LIST_FILTER if self.LIST_FILTER else [], search_fields= self.SEARCH_FIELDS if self.SEARCH_FIELDS else [], rows_per_page= self.LIST_ROWS_PER_PAGE, n_pages = self.LIST_N_PAGES ) has_details = (self.USE_DETAILS_TO_ADD or self.USE_DETAILS_TO_EDIT) and (has_add_permission or has_edit_permission) if has_details: self._details = ControlEmptyWidget('Details', visible=False) ############################################## # Check if the add button should be included if has_add_permission: self._add_btn = ControlButton( self.ADD_BTN_LABEL, label_visible=False, default=self.show_create_form ) if self.parent_model: self._add_btn.css = 'tiny basic blue' ############################################## self.toolbar = self.get_toolbar_buttons(has_add_permission=has_add_permission) if self.parent_model: self.formset = [ self.toolbar, '_details' if has_details else None, '_list', ] else: self.formset = [ '_details' if has_details else None, segment( self.toolbar, '_list' ), ] # if the user has edit permission then if has_edit_permission: # events self._list.item_selection_changed_event = self.__list_item_selection_changed_event #if it is a inline app, add the title to the header if self.parent_model and self.title: self.formset = ['h3:'+str(title)]+self.formset self.populate_list()
def __init__(self, *args, **kwargs): """ :param str title: Title of the app. By default will assume the value in the class variable TITLE. :param django.db.models.Model model: Model with the App will represent. By default will assume the value in the class variable MODEL. :param list(ModelAdmin) inlines: Sub models to show in the interface :param list(str) fieldsets: Organization of the fields :param int parent_pk: Parent model key :param django.db.models.Model parent_model: Parent model class :param int pk: Model register to manage """ BaseWidget.__init__(self, *args, **kwargs) self.model = kwargs.get('model', self.MODEL) self.inlines = kwargs.get('inlines', self.INLINES) self.fieldsets = kwargs.get('fieldsets', self.FIELDSETS) self.readonly = kwargs.get('readonly', self.READ_ONLY) self.has_cancel_btn = kwargs.get('has_cancel_btn', self.HAS_CANCEL_BTN) if self.fieldsets is None: self.fieldsets = self.FIELDSETS self._auto_fields = [] self._callable_fields = [] self.edit_fields = [] self.edit_buttons = [] self.inlines_apps = [] self.inlines_controls_name = [] self.inlines_controls = [] self.object_pk = None # used to configure the interface to inline # it will filter the dataset by the foreign key self.parent_field = None self.parent_pk = kwargs.get('parent_pk', None) self.parent_model = kwargs.get('parent_model', None) if self.parent_model and self.parent_pk: self.__set_parent(self.parent_model, self.parent_pk) ####################################################### # buttons self._save_btn = ControlButton(self.SAVE_BTN_LABEL) self._create_btn = ControlButton(self.CREATE_BTN_LABEL) self._remove_btn = ControlButton(self.REMOVE_BTN_LABEL, css='red basic') if self.has_cancel_btn: self._cancel_btn = ControlButton(self.CANCEL_BTN_LABEL, css='gray basic') if self.parent_model: self._save_btn.css += ' tiny' self._create_btn.css += ' tiny' self._remove_btn.css += ' tiny' if self.has_cancel_btn: self._cancel_btn.css += ' tiny' self.edit_buttons.append(self._save_btn) self.edit_buttons.append(self._create_btn) self.edit_buttons.append(self._remove_btn) if self.has_cancel_btn: self.edit_buttons.append(self._cancel_btn) self.edit_fields += self.edit_buttons for field in self.edit_fields: field.hide() # events self._create_btn.value = self.__create_btn_event self._remove_btn.value = self.__remove_btn_event self._save_btn.value = self.__save_btn_event if self.has_cancel_btn: self._cancel_btn.value = self.cancel_btn_event self._create_btn.label_visible = False self._remove_btn.label_visible = False self._save_btn.label_visible = False if self.has_cancel_btn: self._cancel_btn.label_visible = False self.create_model_formfields() pk = kwargs.get('pk', None) if pk: self.object_pk = pk self.show_edit_form() else: self.show_create_form() for inline in self.inlines: self.formset.append(inline.__name__)