Exemple #1
0
 def _get_meta_comp(self):
     if self.args['Multi']:
         param_cmp = XferCompCheckList(self.name)
         param_cmp.simple = 2
     else:
         param_cmp = XferCompSelect(self.name)
     return param_cmp
Exemple #2
0
    def fillresponse(self):
        XferListEditor.fillresponse(self)
        obj_doc = self.get_components('document')
        self.remove_component('document')
        self.tab = obj_doc.tab
        new_col = obj_doc.col
        new_row = obj_doc.row
        obj_doc.set_location(new_col + 2, new_row + 1, 2, 2)
        self.add_component(obj_doc)

        folder_obj = self.fill_current_folder(new_col, new_row)
        list_folders = []
        if self.current_folder > 0:
            folder_filter = Q(parent__id=self.current_folder)
        else:
            folder_filter = Q(parent=None)
        if notfree_mode_connect() and not self.request.user.is_superuser:
            folder_filter &= Q(viewer__in=self.request.user.groups.all())
        folder_list = Folder.objects.filter(folder_filter).order_by("name").distinct()
        for folder_item in folder_list:
            list_folders.append((folder_item.id, folder_item.name))
        if folder_obj is not None:
            if folder_obj.parent is None:
                parent_id = 0
            else:
                parent_id = folder_obj.parent.id
            list_folders.insert(0, (parent_id, '..'))
        select = XferCompCheckList('current_folder')
        select.simple = True
        select.set_select(list_folders)
        select.set_location(new_col, new_row + 1, 2)
        select.set_action(self.request, self.get_action(), modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        self.add_component(select)

        self.add_folder_buttons(new_col, new_row)
Exemple #3
0
 def edit(self, xfer):
     if (PluginManager.get_instance().count > 0):
         plugin_permission = PluginManager.get_param()
         sel = XferCompCheckList('plugins')
         sel.description = _('plugins')
         sel.set_location(1, 2)
         sel.simple = 2
         sel.set_select([(item.name, item.title)
                         for item in PluginManager.get_instance()])
         sel.set_value([
             item.name for item in PluginManager.get_instance()
             if (item.name in plugin_permission) and (
                 self.item.id in plugin_permission[item.name])
         ])
         xfer.add_component(sel)
Exemple #4
0
 def get_write_comp(self):
     if self.type == 0:  # String
         if self.args['Multi']:
             param_cmp = XferCompMemo(self.name)
             param_cmp.with_hypertext = self.args['HyperText']
         else:
             param_cmp = XferCompEdit(self.name)
         param_cmp.set_value(self.value)
     elif self.type == 1:  # Integer
         param_cmp = XferCompFloat(
             self.name, minval=self.args['Min'], maxval=self.args['Max'], precval=0)
         param_cmp.set_value(self.value)
         param_cmp.set_needed(True)
     elif self.type == 2:  # Real
         param_cmp = XferCompFloat(self.name, minval=self.args['Min'], maxval=self.args[
                                   'Max'], precval=self.args['Prec'])
         param_cmp.set_value(self.value)
         param_cmp.set_needed(True)
     elif self.type == 3:  # Boolean
         param_cmp = XferCompCheck(self.name)
         param_cmp.set_value(six.text_type(self.value))
         param_cmp.set_needed(True)
     elif self.type == 4:  # Select
         param_cmp = XferCompSelect(self.name)
         selection = []
         for sel_idx in range(0, self.args['Enum']):
             selection.append((sel_idx, ugettext_lazy(self.name + ".%d" % sel_idx)))
         param_cmp.set_select(selection)
         param_cmp.set_value(self.value)
         param_cmp.set_needed(True)
     elif self.type == 5:  # password
         param_cmp = XferCompPassword(self.name)
         param_cmp.security = 0
         param_cmp.set_value('')
     elif self.type == 6:  # select in object
         if (self.meta_info[0] != "") and (self.meta_info[1] != ""):
             db_mdl = apps.get_model(self.meta_info[0], self.meta_info[1])
         else:
             db_mdl = None
         if self.args['Multi']:
             param_cmp = XferCompCheckList(self.name)
             param_cmp.simple = 2
         else:
             param_cmp = XferCompSelect(self.name)
         param_cmp.set_needed(self.meta_info[4])
         selection = []
         if not self.meta_info[4]:
             if (self.args['oldtype'] == 1) or (self.args['oldtype'] == 2):
                 selection.append((0, None))
             else:
                 selection.append(('', None))
         if db_mdl is None:
             selection = self.meta_info[2]
         else:
             for obj_item in db_mdl.objects.filter(self.meta_info[2]):
                 selection.append((getattr(obj_item, self.meta_info[3]), six.text_type(obj_item)))
         param_cmp.set_select(selection)
         param_cmp.set_value(self.value)
     param_cmp.description = six.text_type(ugettext_lazy(self.name))
     return param_cmp
Exemple #5
0
 def fillresponse(self, params=(), nb_col=1):
     ParamEdit.fillresponse(self, params=params, nb_col=nb_col)
     comp_fields = self.get_components("member-fields")
     if comp_fields is not None:
         self.remove_component("member-fields")
         new_comp_fields = XferCompCheckList("member-fields")
         new_comp_fields.description = comp_fields.description
         new_comp_fields.simple = 2
         new_comp_fields.set_location(comp_fields.col, comp_fields.row,
                                      comp_fields.colspan,
                                      comp_fields.rowspan)
         new_comp_fields.set_select(Adherent.get_allowed_fields_title())
         new_comp_fields.set_value([
             field[1] if isinstance(field, tuple) else field
             for field in Adherent.get_default_fields()
         ])
         self.add_component(new_comp_fields)
Exemple #6
0
 def fillresponse(self):
     XferListEditor.fillresponse(self)
     self.new_tab(_("Log setting"))
     row = self.get_max_row() + 1
     sel = XferCompCheckList('AuditLogSetting')
     sel.simple = 2
     sel.set_select(Signal.get_packages_of_signal('auditlog_register'))
     sel.set_value(Params.getvalue('CORE-AuditLog').split())
     sel.set_location(1, row, 3)
     sel.description = _('settings')
     self.add_component(sel)
     btn = XferCompButton('ChangeAL')
     btn.set_action(self.request,
                    AudiLogChange.get_action(TITLE_MODIFY,
                                             "images/edit.png"),
                    modal=FORMTYPE_MODAL,
                    close=CLOSE_NO)
     btn.set_location(2, row + 1)
     self.add_component(btn)
Exemple #7
0
    def fillresponse(self):
        XferListEditor.fillresponse(self)
        obj_doc = self.get_components('document')
        self.remove_component('document')
        self.tab = obj_doc.tab
        new_col = obj_doc.col
        new_row = obj_doc.row
        obj_doc.set_location(new_col + 2, new_row + 1, 2, 2)
        self.add_component(obj_doc)
        obj_lbl_doc = self.get_components('nb_document')
        self.remove_component('nb_document')
        obj_lbl_doc.set_location(new_col + 2, new_row + 3, 2, 1)
        self.add_component(obj_lbl_doc)

        folder_obj = self.fill_current_folder(new_col, new_row)
        list_folders = []
        if self.current_folder > 0:
            folder_filter = Q(parent__id=self.current_folder)
        else:
            folder_filter = Q(parent=None)
        if notfree_mode_connect() and not self.request.user.is_superuser:
            folder_filter &= Q(viewer__in=self.request.user.groups.all())
        folder_list = Folder.objects.filter(folder_filter).order_by(
            "name").distinct()
        for folder_item in folder_list:
            list_folders.append((folder_item.id, folder_item.name))
        if folder_obj is not None:
            if folder_obj.parent is None:
                parent_id = 0
            else:
                parent_id = folder_obj.parent.id
            list_folders.insert(0, (parent_id, '..'))
        select = XferCompCheckList('current_folder')
        select.simple = True
        select.set_select(list_folders)
        select.set_location(new_col, new_row + 1, 2)
        select.set_action(self.request,
                          self.get_action(),
                          modal=FORMTYPE_REFRESH,
                          close=CLOSE_NO)
        self.add_component(select)

        self.add_folder_buttons(new_col, new_row)
Exemple #8
0
 def _create_comp_manytomanyfield(self, field_name, dep_field):
     comp = XferCompCheckList(field_name)
     comp.simple = 2
     if self.item.id is not None:
         values = []
         for item in getattr(self.item, field_name).all():
             values.append(item.id)
         comp.set_value(values)
     if hasattr(self.item, field_name + '_query'):
         sub_select = getattr(self.item, field_name + '_query')
     else:
         sub_select = get_dico_from_setquery(
             get_corrected_setquery(
                 dep_field.remote_field.model.objects.all()))
     comp.set_select(sub_select)
     return comp
Exemple #9
0
    def fillresponse_search_values(self):
        comp = XferCompButton("searchButtonAdd")
        comp.is_default = True
        comp.set_is_mini(True)
        comp.set_location(4, 10, 1, 7)
        comp.set_action(self.request,
                        self.get_action("", "images/add.png"),
                        modal=FORMTYPE_REFRESH,
                        close=CLOSE_NO,
                        params={'ACT': 'ADD'})
        self.add_component(comp)

        comp = XferCompDate("searchValueDate")
        comp.set_needed(True)
        comp.set_location(3, 11)
        comp.set_size(20, 200)
        self.add_component(comp)
        comp = XferCompFloat("searchValueFloat")
        comp.set_needed(True)
        comp.set_location(3, 12)
        comp.set_size(20, 200)
        self.add_component(comp)
        comp = XferCompEdit("searchValueStr")
        comp.set_location(3, 13)
        comp.set_size(20, 200)
        self.add_component(comp)
        comp = XferCompCheckList("searchValueList")
        comp.set_location(3, 14)
        comp.set_size(80, 200)
        self.add_component(comp)
        comp = XferCompCheck("searchValueBool")
        comp.set_location(3, 15)
        comp.set_size(20, 200)
        self.add_component(comp)
        comp = XferCompTime("searchValueTime")
        comp.set_needed(True)
        comp.set_location(3, 16)
        comp.set_size(20, 200)
        self.add_component(comp)

        label = XferCompLabelForm('labelsearchSep')
        label.set_value("")
        label.set_size(1, 200)
        label.set_location(3, 17)
        self.add_component(label)
Exemple #10
0
    def fillresponse_header(self):
        row = self.get_max_row() + 1
        team = self.getparam("team", ())
        activity = self.getparam("activity", ())
        genre = self.getparam("genre", 0)
        age = self.getparam("age", ())
        status = self.getparam("status", -1)
        dateref = convert_date(
            self.getparam("dateref", ""), Season.current_season().date_ref)

        if Params.getvalue("member-age-enable"):
            lbl = XferCompLabelForm('lblage')
            lbl.set_value_as_name(_("Age"))
            lbl.set_location(0, row)
            self.add_component(lbl)
            sel = XferCompCheckList('age')
            sel.set_select_query(Age.objects.all())
            sel.set_value(age)
            sel.set_location(1, row, 1, 2)
            self.add_component(sel)

        if Params.getvalue("member-team-enable"):
            lbl = XferCompLabelForm('lblteam')
            lbl.set_value_as_name(Params.getvalue("member-team-text"))
            lbl.set_location(2, row)
            self.add_component(lbl)
            sel = XferCompCheckList('team')
            sel.set_select_query(Team.objects.all())
            sel.set_value(team)
            sel.set_location(3, row, 1, 2)
            self.add_component(sel)

        if Params.getvalue("member-activite-enable"):
            lbl = XferCompLabelForm('lblactivity')
            lbl.set_value_as_name(Params.getvalue("member-activite-text"))
            lbl.set_location(4, row)
            self.add_component(lbl)
            sel = XferCompCheckList('activity')
            sel.set_select_query(Activity.objects.all())
            sel.set_value(activity)
            sel.set_location(5, row, 1, 2)
            self.add_component(sel)

        lbl = XferCompLabelForm('lbldateref')
        lbl.set_value_as_name(_("reference date"))
        lbl.set_location(6, row)
        self.add_component(lbl)

        dtref = XferCompDate('dateref')
        dtref.set_value(dateref)
        dtref.set_needed(True)
        dtref.set_location(7, row, 2)
        self.add_component(dtref)

        if Params.getvalue("member-filter-genre"):
            lbl = XferCompLabelForm('lblgenre')
            lbl.set_value_as_name(_("genre"))
            lbl.set_location(6, row + 1)
            self.add_component(lbl)
            sel = XferCompSelect('genre')
            list_genre = list(self.item.get_field_by_name('genre').choices)
            list_genre.insert(0, (0, '---'))
            sel.set_select(list_genre)
            sel.set_location(7, row + 1)
            sel.set_value(genre)
            self.add_component(sel)

        lbl = XferCompLabelForm('lblstatus')
        lbl.set_value_as_name(_("status"))
        lbl.set_location(6, row + 2)
        self.add_component(lbl)
        sel = XferCompSelect('status')
        list_status = list(Subscription.get_field_by_name('status').choices)
        del list_status[0]
        del list_status[-2]
        del list_status[-1]
        list_status.insert(0, (-1, '%s & %s' % (_('building'), _('valid'))))
        sel.set_select(list_status)
        sel.set_location(7, row + 2)
        sel.set_value(status)
        self.add_component(sel)

        btn = XferCompButton('btndateref')
        btn.set_location(8, row + 1, 1, 2)
        btn.set_action(self.request, self.get_action(_('Refresh'), ''),
                       modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        self.add_component(btn)
Exemple #11
0
    def fillresponse(self, edt1='aaa', flt1=3.1399999, mm1='xyz', dt1='2007-04-23', tm1='12:34:00',
                     ck1=False, slct1='1', flt2=5, cl1=['1', '2'], cl2=['b', 'd', 'f'], stm1='2008-07-12 23:47:31'):
        act_modif = self.get_action('Modify', '')

        lbl = XferCompLabelForm('Lbl2')
        lbl.set_value('editor=' + six.text_type(edt1))
        lbl.set_location(0, 1)
        self.add_component(lbl)
        edt = XferCompEdit('edt1')
        edt.set_value(edt1)

        edt.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        edt.set_location(1, 1)

        self.add_component(edt)

        lbl = XferCompLabelForm('Lbl3')
        lbl.set_value('Real=' + six.text_type(flt1))
        lbl.set_location(0, 2)
        self.add_component(lbl)
        flt = XferCompFloat('flt1')
        flt.set_value(flt1)
        flt.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        flt.set_location(1, 2)
        self.add_component(flt)

        lbl = XferCompLabelForm('Lbl4')
        lbl.set_value('Memo=' + six.text_type(mm1))
        lbl.set_location(0, 3)
        self.add_component(lbl)
        cmm = XferCompMemo('mm1')
        cmm.set_value(mm1)
        cmm.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        cmm.add_sub_menu('Première valeur', 'VALUE_1')
        cmm.add_sub_menu('Deuxième valeur', 'VALUE_2')
        cmm.add_sub_menu('Troisième valeur', 'VALUE_3')
        cmm.set_location(1, 3)
        self.add_component(cmm)

        lbl = XferCompLabelForm('Lbl5')
        lbl.set_value('Date=' + six.text_type(dt1))
        lbl.set_location(0, 4)
        self.add_component(lbl)
        date = XferCompDate('dt1')
        date.set_value(dt1)
        date.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        date.set_location(1, 4)
        self.add_component(date)

        lbl = XferCompLabelForm('Lbl6')
        lbl.set_value('Hour=' + six.text_type(tm1))
        lbl.set_location(0, 5)
        self.add_component(lbl)
        time = XferCompTime('tm1')
        time.set_value(tm1)
        time.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        time.set_location(1, 5)
        self.add_component(time)

        lbl = XferCompLabelForm('Lbl7')
        lbl.set_value('Date Hour=' + six.text_type(stm1))
        lbl.set_location(0, 6)
        self.add_component(lbl)
        datetime = XferCompDateTime('stm1')
        datetime.set_value(stm1)
        datetime.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        datetime.set_location(1, 6)
        self.add_component(datetime)

        lbl = XferCompLabelForm('Lbl8')
        lbl.set_value('Coche=' + six.text_type(ck1))
        lbl.set_location(0, 7)
        self.add_component(lbl)
        check = XferCompCheck('ck1')
        check.set_value(ck1)
        check.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        check.set_location(1, 7)
        self.add_component(check)

        lbl = XferCompLabelForm('Lbl9')
        lbl.set_value('Select=' + six.text_type(slct1))
        lbl.set_location(0, 8)
        self.add_component(lbl)
        slct = XferCompSelect('slct1')
        if (flt2 is not None) and (flt2 < 2):
            slct.set_select({'1': 'abc', '2': 'def'})
        elif (flt2 is not None) and (flt2 < 10):
            slct.set_select({'1': 'abc', '2': 'def', '3': 'ghij'})
        else:
            slct.set_select({'1': 'abc', '2': 'def', '3': 'ghij', '4': 'klmn'})
        slct.set_value(slct1)
        slct.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        slct.set_location(1, 8)
        self.add_component(slct)

        lbl = XferCompLabelForm('Lbl10')
        lbl.set_value('Integer=' + six.text_type(flt2))
        lbl.set_location(0, 9)
        self.add_component(lbl)
        flt = XferCompFloat('flt2', 0, 100, 0)
        flt.set_value(flt2)
        flt.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        flt.set_location(1, 9)
        self.add_component(flt)

        lbl = XferCompLabelForm('Lbl11')
        lbl.set_value('CheckList=' + six.text_type(cl1))
        lbl.set_location(0, 10)
        self.add_component(lbl)
        checklist = XferCompCheckList('cl1')
        checklist.set_select(
            {'1': 'abc', '2': 'def', '3': 'ghij', '4': 'klmn'})
        checklist.set_value(cl1)
        checklist.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        checklist.set_location(1, 10)
        self.add_component(checklist)

        lbl = XferCompLabelForm('Lbl12')
        lbl.set_value('CheckList 2=' + six.text_type(cl2))
        lbl.set_location(0, 11)
        self.add_component(lbl)
        checklist = XferCompCheckList('cl2')
        checklist.simple = 2
        checklist.set_select(
            {'a': '123', 'b': '456', 'c': '789', 'd': '147', 'e': '258', 'f': '369'})
        checklist.set_value(cl2)
        checklist.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        checklist.set_location(1, 11)
        self.add_component(checklist)

        lbl = XferCompLabelForm('Lbl13')
        lbl.set_value('Bouton')
        lbl.set_location(0, 20)
        self.add_component(lbl)
        btn = XferCompButton('btn1')
        btn.set_action(self.request, act_modif, modal=FORMTYPE_REFRESH, close=CLOSE_NO)
        btn.set_location(1, 20)
        self.add_component(btn)

        self.add_action(WrapAction('Fin', 'images/close.png'), modal=FORMTYPE_MODAL, close=CLOSE_YES)
Exemple #12
0
    def get_writing_comp(self, field_name):
        def get_value_from_field(default):
            try:
                val = getattr(self.item, field_name)
            except ObjectDoesNotExist:
                getLogger("lucterios.core").exception(
                    "fieldname '%s' not found", field_name)
                val = None
            if val is None:
                if is_needed:
                    if dep_field.default != NOT_PROVIDED:
                        val = dep_field.default
                    else:
                        val = default
            return val

        from django.db.models.fields import IntegerField, DecimalField, BooleanField, TextField, DateField, TimeField, DateTimeField, CharField
        from django.db.models.fields.related import ForeignKey
        dep_field = self.item.get_field_by_name(field_name)
        is_needed = dep_field.unique or not (dep_field.blank or dep_field.null)
        if isinstance(dep_field, IntegerField):
            if (dep_field.choices
                    is not None) and (len(dep_field.choices) > 0):
                comp = XferCompSelect(field_name)
                comp.set_select(list(dep_field.choices))
                min_value = 0
            else:
                min_value, max_value = get_range_value(dep_field)
                comp = XferCompFloat(field_name, min_value, max_value, 0)
            comp.set_value(get_value_from_field(min_value))
        elif isinstance(dep_field, DecimalField):
            min_value, max_value = get_range_value(dep_field)
            comp = XferCompFloat(field_name, min_value, max_value,
                                 dep_field.decimal_places)
            comp.set_value(get_value_from_field(min_value))
        elif isinstance(dep_field, BooleanField):
            comp = XferCompCheck(field_name)
            comp.set_value(get_value_from_field(False))
        elif isinstance(dep_field, TextField):
            comp = XferCompMemo(field_name)
            comp.set_value(get_value_from_field(""))
        elif isinstance(dep_field, DateField):
            comp = XferCompDate(field_name)
            comp.set_value(get_value_from_field(datetime.date.today()))
        elif isinstance(dep_field, TimeField):
            comp = XferCompTime(field_name)
            comp.set_value(get_value_from_field(datetime.time()))
        elif isinstance(dep_field, DateTimeField):
            comp = XferCompDateTime(field_name)
            comp.set_value(get_value_from_field(datetime.datetime.now()))
        elif isinstance(dep_field, ForeignKey):
            comp = XferCompSelect(field_name)
            try:
                value = self.item
                for fieldname in field_name.split('.'):
                    value = getattr(value, fieldname)
            except ObjectDoesNotExist:
                value = None
            if value is None:
                comp.set_value(0)
            else:
                comp.set_value(value.id)
            if hasattr(self.item, fieldname + '_query'):
                sub_select = getattr(self.item, fieldname + '_query')
            else:
                sub_select = dep_field.remote_field.model.objects.all()
            comp.set_needed(not dep_field.null)
            comp.set_select_query(sub_select)
        elif (dep_field is not None
              ) and dep_field.is_relation and dep_field.many_to_many:
            comp = XferCompCheckList(field_name)
            comp.simple = 2
            if self.item.id is not None:
                values = []
                for item in getattr(self.item, field_name).all():
                    values.append(item.id)
                comp.set_value(values)
            if hasattr(self.item, field_name + '_query'):
                sub_select = getattr(self.item, field_name + '_query')
            else:
                sub_select = get_dico_from_setquery(
                    get_corrected_setquery(
                        dep_field.remote_field.model.objects.all()))
            comp.set_select(sub_select)
        else:
            comp = XferCompEdit(field_name)
            comp.set_value(get_value_from_field(""))
            if isinstance(dep_field, CharField):
                comp.size = dep_field.max_length
        comp.set_needed(is_needed)
        return comp
Exemple #13
0
    def fillresponse(self,
                     edt1='aaa',
                     flt1=3.1399999,
                     mm1='xyz',
                     dt1='2007-04-23',
                     tm1='12:34:00',
                     ck1=False,
                     slct1='1',
                     flt2=5,
                     cl1=['1', '2'],
                     cl2=['b', 'd', 'f'],
                     stm1='2008-07-12 23:47:31'):
        act_modif = self.return_action('Modify', '')

        lbl = XferCompLabelForm('Lbl2')
        lbl.set_value('editor=' + six.text_type(edt1))
        lbl.set_location(0, 1)
        self.add_component(lbl)
        edt = XferCompEdit('edt1')
        edt.set_value(edt1)

        edt.set_action(self.request,
                       act_modif,
                       modal=FORMTYPE_REFRESH,
                       close=CLOSE_NO)
        edt.set_location(1, 1)

        self.add_component(edt)

        lbl = XferCompLabelForm('Lbl3')
        lbl.set_value('Real=' + six.text_type(flt1))
        lbl.set_location(0, 2)
        self.add_component(lbl)
        flt = XferCompFloat('flt1')
        flt.set_value(flt1)
        flt.set_action(self.request,
                       act_modif,
                       modal=FORMTYPE_REFRESH,
                       close=CLOSE_NO)
        flt.set_location(1, 2)
        self.add_component(flt)

        lbl = XferCompLabelForm('Lbl4')
        lbl.set_value('Memo=' + six.text_type(mm1))
        lbl.set_location(0, 3)
        self.add_component(lbl)
        cmm = XferCompMemo('mm1')
        cmm.set_value(mm1)
        cmm.set_action(self.request,
                       act_modif,
                       modal=FORMTYPE_REFRESH,
                       close=CLOSE_NO)
        cmm.add_sub_menu('Première valeur', 'VALUE_1')
        cmm.add_sub_menu('Deuxième valeur', 'VALUE_2')
        cmm.add_sub_menu('Troisième valeur', 'VALUE_3')
        cmm.set_location(1, 3)
        self.add_component(cmm)

        lbl = XferCompLabelForm('Lbl5')
        lbl.set_value('Date=' + six.text_type(dt1))
        lbl.set_location(0, 4)
        self.add_component(lbl)
        date = XferCompDate('dt1')
        date.set_value(dt1)
        date.set_action(self.request,
                        act_modif,
                        modal=FORMTYPE_REFRESH,
                        close=CLOSE_NO)
        date.set_location(1, 4)
        self.add_component(date)

        lbl = XferCompLabelForm('Lbl6')
        lbl.set_value('Hour=' + six.text_type(tm1))
        lbl.set_location(0, 5)
        self.add_component(lbl)
        time = XferCompTime('tm1')
        time.set_value(tm1)
        time.set_action(self.request,
                        act_modif,
                        modal=FORMTYPE_REFRESH,
                        close=CLOSE_NO)
        time.set_location(1, 5)
        self.add_component(time)

        lbl = XferCompLabelForm('Lbl7')
        lbl.set_value('Date Hour=' + six.text_type(stm1))
        lbl.set_location(0, 6)
        self.add_component(lbl)
        datetime = XferCompDateTime('stm1')
        datetime.set_value(stm1)
        datetime.set_action(self.request,
                            act_modif,
                            modal=FORMTYPE_REFRESH,
                            close=CLOSE_NO)
        datetime.set_location(1, 6)
        self.add_component(datetime)

        lbl = XferCompLabelForm('Lbl8')
        lbl.set_value('Coche=' + six.text_type(ck1))
        lbl.set_location(0, 7)
        self.add_component(lbl)
        check = XferCompCheck('ck1')
        check.set_value(ck1)
        check.set_action(self.request,
                         act_modif,
                         modal=FORMTYPE_REFRESH,
                         close=CLOSE_NO)
        check.set_location(1, 7)
        self.add_component(check)

        lbl = XferCompLabelForm('Lbl9')
        lbl.set_value('Select=' + six.text_type(slct1))
        lbl.set_location(0, 8)
        self.add_component(lbl)
        slct = XferCompSelect('slct1')
        if (flt2 is not None) and (flt2 < 2):
            slct.set_select({'1': 'abc', '2': 'def'})
        elif (flt2 is not None) and (flt2 < 10):
            slct.set_select({'1': 'abc', '2': 'def', '3': 'ghij'})
        else:
            slct.set_select({'1': 'abc', '2': 'def', '3': 'ghij', '4': 'klmn'})
        slct.set_value(slct1)
        slct.set_action(self.request,
                        act_modif,
                        modal=FORMTYPE_REFRESH,
                        close=CLOSE_NO)
        slct.set_location(1, 8)
        self.add_component(slct)

        lbl = XferCompLabelForm('Lbl10')
        lbl.set_value('Integer=' + six.text_type(flt2))
        lbl.set_location(0, 9)
        self.add_component(lbl)
        flt = XferCompFloat('flt2', 0, 100, 0)
        flt.set_value(flt2)
        flt.set_action(self.request,
                       act_modif,
                       modal=FORMTYPE_REFRESH,
                       close=CLOSE_NO)
        flt.set_location(1, 9)
        self.add_component(flt)

        lbl = XferCompLabelForm('Lbl11')
        lbl.set_value('CheckList=' + six.text_type(cl1))
        lbl.set_location(0, 10)
        self.add_component(lbl)
        checklist = XferCompCheckList('cl1')
        checklist.set_select({
            '1': 'abc',
            '2': 'def',
            '3': 'ghij',
            '4': 'klmn'
        })
        checklist.set_value(cl1)
        checklist.set_action(self.request,
                             act_modif,
                             modal=FORMTYPE_REFRESH,
                             close=CLOSE_NO)
        checklist.set_location(1, 10)
        self.add_component(checklist)

        lbl = XferCompLabelForm('Lbl12')
        lbl.set_value('CheckList 2=' + six.text_type(cl2))
        lbl.set_location(0, 11)
        self.add_component(lbl)
        checklist = XferCompCheckList('cl2')
        checklist.simple = 2
        checklist.set_select({
            'a': '123',
            'b': '456',
            'c': '789',
            'd': '147',
            'e': '258',
            'f': '369'
        })
        checklist.set_value(cl2)
        checklist.set_action(self.request,
                             act_modif,
                             modal=FORMTYPE_REFRESH,
                             close=CLOSE_NO)
        checklist.set_location(1, 11)
        self.add_component(checklist)

        lbl = XferCompLabelForm('Lbl13')
        lbl.set_value('Bouton')
        lbl.set_location(0, 20)
        self.add_component(lbl)
        btn = XferCompButton('btn1')
        btn.set_action(self.request,
                       act_modif,
                       modal=FORMTYPE_REFRESH,
                       close=CLOSE_NO)
        btn.set_location(1, 20)
        self.add_component(btn)

        self.add_action(WrapAction('Fin', 'images/close.png'),
                        modal=FORMTYPE_MODAL,
                        close=CLOSE_YES)
Exemple #14
0
    def selector_from_model(self, col, row, field_name):

        dep_field = self.item._meta.get_field(
            field_name)
        if (not dep_field.auto_created or dep_field.concrete) and (dep_field.is_relation and dep_field.many_to_many):
            if hasattr(self.item, field_name + "__titles"):
                title_available, title_chosen = getattr(
                    self.item, field_name + "__titles")
            else:
                title_available, title_chosen = _("Available"), _("Chosen")
            availables = get_corrected_setquery(
                dep_field.remote_field.model.objects.all())
            java_script_init, java_script_treat = self._get_scripts_for_selectors(
                field_name, availables)

            lbl = XferCompLabelForm('hd_' + field_name + '_available')
            lbl.set_location(col + 1, row, 1, 1)
            lbl.set_value_as_header(title_available)
            self.add_component(lbl)

            lista = XferCompCheckList(field_name + '_available')
            lista.set_location(col + 1, row + 1, 1, 5)
            lista.set_size(200, 250)
            self.add_component(lista)

            lbl = XferCompLabelForm('hd_' + field_name + '_chosen')
            lbl.set_location(col + 3, row, 1, 1)
            lbl.set_value_as_header(title_chosen)
            self.add_component(lbl)

            listc = XferCompCheckList(field_name + '_chosen')
            listc.set_location(col + 3, row + 1, 1, 5)
            listc.set_size(200, 250)
            self.add_component(listc)

            btn_idx = 0
            for (button_name, button_title, button_script) in [("addall", ">>", """
if (%(comp)s_current !== null) {
    %(comp)s_valid ='';
    for (var key in %(comp)s_dico) {
        if (%(comp)s_valid !== '')
            %(comp)s_valid +=';';
        %(comp)s_valid +=key;
    }
    parent.mContext.put('%(comp)s',%(comp)s_valid);
}
"""), ("add", ">", """
if (%(comp)s_current !== null) {
    var value = parent.get('%(comp)s_available').getValue();
    if (%(comp)s_valid !== '')
        %(comp)s_valid +=';';
    %(comp)s_valid +=value;
parent.mContext.put('%(comp)s',%(comp)s_valid);
}
"""), ("del", "<", """
if (%(comp)s_current !== null) {
    var values = parent.get('%(comp)s_chosen').getValue().split(';');
    var valid_list = %(comp)s_valid.split(';');
    %(comp)s_valid ='';
    for (var key in valid_list) {
        selected_val = valid_list[key];
        if (values.indexOf(selected_val) === -1) {
            if (%(comp)s_valid !== '')
                %(comp)s_valid +=';';
            %(comp)s_valid +=selected_val;
        }
    }
    parent.mContext.put('%(comp)s',%(comp)s_valid);
}
"""), ("delall", "<<", """
if (%(comp)s_current !== null) {
    %(comp)s_valid ='';
    parent.mContext.put('%(comp)s',%(comp)s_valid);
}
""")]:
                btn = XferCompButton(field_name + '_' + button_name)
                btn.set_action(
                    self.request, WrapAction(button_title, ""), {'close': CLOSE_NO})
                btn.set_location(col + 2, row + 1 + btn_idx, 1, 1)
                btn.set_is_mini(True)
                btn.java_script = java_script_init + \
                    button_script % {'comp': field_name} + java_script_treat
                self.add_component(btn)
                btn_idx += 1
Exemple #15
0
 def get_writing_comp(self, field_name):
     from django.db.models.fields import IntegerField, DecimalField, BooleanField, TextField, DateField, TimeField, DateTimeField, CharField
     from django.db.models.fields.related import ForeignKey
     comp = None
     dep_field = self.item.get_field_by_name(field_name)
     for field_type in (IntegerField, DecimalField, BooleanField, TextField,
                        DateField, TimeField, DateTimeField, ForeignKey):
         if isinstance(dep_field, field_type):
             fct = getattr(self,
                           "_create_comp_%s" % field_type.__name__.lower(),
                           None)
             if fct is not None:
                 comp = fct(field_name, dep_field)
                 break
     if comp is None:
         if (dep_field is not None
             ) and dep_field.is_relation and dep_field.many_to_many:
             comp = XferCompCheckList(field_name)
             comp.simple = 2
             if self.item.id is not None:
                 values = []
                 for item in getattr(self.item, field_name).all():
                     values.append(item.id)
                 comp.set_value(values)
             if hasattr(self.item, field_name + '_query'):
                 sub_select = getattr(self.item, field_name + '_query')
             else:
                 sub_select = get_dico_from_setquery(
                     get_corrected_setquery(
                         dep_field.remote_field.model.objects.all()))
             comp.set_select(sub_select)
         else:
             comp = XferCompEdit(field_name)
             comp.set_value(
                 self._get_value_from_field(field_name, dep_field, ""))
             if isinstance(dep_field, CharField):
                 comp.size = dep_field.max_length
     comp.set_needed(dep_field.unique
                     or not (dep_field.blank or dep_field.null))
     return comp