Beispiel #1
0
 def fillresponse(self, model='', objid=0):
     img = XferCompImage('img')
     img.set_value(self.icon_path())
     img.set_location(0, 0, 1, 6)
     self.add_component(img)
     self.model = apps.get_model(model)
     if objid != 0:
         self.item = self.model.objects.get(id=objid)
         fieldnames = []
         for fieldname in self.model.get_default_fields():
             if isinstance(fieldname, tuple):
                 fieldnames.append(fieldname[1])
             else:
                 fieldnames.append(fieldname)
         self.fill_from_model(1, 0, True, desc_fields=fieldnames)
         log_items = LucteriosLogEntry.objects.get_for_object(self.item)
     else:
         content_type = ContentType.objects.get_for_model(self.model)
         lbl = XferCompLabelForm('ModelName')
         lbl.set_value_as_header(six.text_type(content_type))
         lbl.description = _("content type")
         lbl.set_location(1, 0, 2)
         self.add_component(lbl)
         log_items = LucteriosLogEntry.objects.get_for_model(self.model)
     grid = XferCompGrid(self.field_id)
     grid.set_model(log_items, None, self)
     grid.set_location(1, self.get_max_row() + 1, 2)
     grid.set_size(200, 500)
     self.add_component(grid)
Beispiel #2
0
 def show(self, xfer):
     xfer.move_components('lbl_body', 0, 2)
     xfer.move_components('body', 0, 2)
     obj_recipients = xfer.get_components('recipients')
     new_recipients = XferCompGrid('recipient_list')
     new_recipients.set_location(obj_recipients.col, obj_recipients.row, obj_recipients.colspan)
     new_recipients.add_header("model", _('model'))
     new_recipients.add_header("filter", _('filter'))
     compid = 0
     for model_title, filter_desc in self.item.recipients_description:
         new_recipients.set_value(compid, "model", model_title)
         new_recipients.set_value(compid, "filter", filter_desc)
         compid += 1
     if compid > 0:
         nb_contact = len(self.item.get_contacts())
         contact_nb = XferCompLabelForm('contact_nb')
         contact_nb.set_location(obj_recipients.col, obj_recipients.row + 1, obj_recipients.colspan)
         contact_nb.set_value(_("Message defined for %d contacts") % nb_contact)
         xfer.add_component(contact_nb)
     lbl = XferCompLabelForm('sep_body')
     lbl.set_location(obj_recipients.col - 1, obj_recipients.row + 2, 4)
     lbl.set_value("{[hr/]}")
     xfer.add_component(lbl)
     xfer.remove_component('recipients')
     new_recipients.add_action_notified(xfer, 'recipient_list')
     xfer.add_component(new_recipients)
     return LucteriosEditor.show(self, xfer)
Beispiel #3
0
    def fillresponse(self, begin_date, end_date):
        self.item.set_dates(begin_date, end_date)
        date_init = XferCompDate("begin_date")
        date_init.set_needed(True)
        date_init.set_value(self.item.date_begin)
        date_init.set_location(1, 0)
        date_init.description = _('initial date')
        date_init.set_action(self.request, self.get_action(), close=CLOSE_NO, modal=FORMTYPE_REFRESH)
        self.add_component(date_init)
        date_end = XferCompDate("end_date")
        date_end.set_needed(True)
        date_end.set_value(self.item.date_end)
        date_end.set_location(2, 0)
        date_end.description = _('current date')
        date_end.set_action(self.request, self.get_action(), close=CLOSE_NO, modal=FORMTYPE_REFRESH)
        self.add_component(date_end)
        img = XferCompImage('img')
        img.set_value(self.icon_path())
        img.set_location(0, 0, 1, 6)
        self.add_component(img)
        self.fill_from_model(1, 1, True, [((_('name'), 'third'),)])
        grid = XferCompGrid('loadcount')
        grid.set_model(self.item.loadcount_set.all(), None)
        grid.set_location(1, 2, 2)
        self.add_component(grid)

        self.add_action(WrapAction(_('Close'), 'images/close.png'))
Beispiel #4
0
 def fill_grid(self, row, model, field_id, items):
     grid = XferCompGrid(field_id)
     if self.multi_page:
         xfer = self
     else:
         xfer = None
     grid.set_model(items, self.fieldnames, xfer)
     grid.add_action_notified(self, model=model)
     grid.set_location(0, row + 1, 2)
     grid.set_size(200, 500)
     self.add_component(grid)
Beispiel #5
0
def show_contact_degree(contact, xfer):
    if WrapAction.is_permission(xfer.request, 'event.change_degree') and (Params.getvalue("event-degree-enable") == 1):
        up_contact = contact.get_final_child()
        if isinstance(up_contact, Adherent):
            degrees = Degree.objects.filter(adherent=up_contact)
            xfer.new_tab(_("Degree"))
            grid = XferCompGrid('degrees')
            grid.set_model(degrees, None, xfer)
            grid.add_action_notified(xfer, Degree)
            grid.set_location(0, xfer.get_max_row() + 1, 2)
            grid.set_size(200, 500)
            xfer.add_component(grid)
Beispiel #6
0
 def add_legalentities(self, legal_entities):
     self.new_tab(_("Legal entities"))
     grid = XferCompGrid('legal_entity')
     grid.set_model(legal_entities, LegalEntity.get_default_fields())
     grid.add_action(self.request,
                     CurrentLegalEntityShow.get_action(
                         _("Edit"), "images/show.png"),
                     modal=FORMTYPE_MODAL,
                     close=CLOSE_NO,
                     unique=SELECT_SINGLE)
     grid.set_location(1, 1, 2)
     grid.set_size(200, 500)
     self.add_component(grid)
Beispiel #7
0
 def filltab_from_model(self, col, row, readonly, field_names, prefix=''):
     maxsize_of_lines = self.get_maxsize_of_lines(field_names)
     for line_field_name in field_names:
         if not isinstance(line_field_name, tuple):
             line_field_name = line_field_name,
         offset = 0
         height = 1
         comp_col_addon = 0
         for field_name in line_field_name:
             if field_name is None:
                 continue
             colspan = self.get_current_offset(maxsize_of_lines,
                                               len(line_field_name), offset)
             if field_name[-4:] == '_set':  # field is one-to-many relation
                 child = getattr(self.item, field_name).all()
                 if hasattr(self.item, field_name[:-4] + '_query'):
                     child = child.filter(
                         getattr(self.item, field_name[:-4] + '_query'))
                 comp = XferCompGrid(field_name[:-4])
                 comp.set_model(child, None, self)
                 comp.add_action_notified(self, model=child.model)
                 comp.set_location(col + comp_col_addon + offset, row,
                                   colspan, 1)
                 comp.description = six.text_type(
                     child.model._meta.verbose_name)
                 self.add_component(comp)
                 offset += 1 + comp_col_addon
             else:
                 if isinstance(field_name, tuple):
                     verbose_name, field_name = field_name
                 else:
                     verbose_name = None
                 dep_field = self.item.get_field_by_name(field_name)
                 # field real in model
                 if (dep_field is None
                     ) or not dep_field.auto_created or dep_field.concrete:
                     # field not many-to-many
                     if readonly:
                         comp = self.get_reading_comp(field_name, prefix)
                     else:
                         comp = self.get_writing_comp(field_name)
                     comp.set_location(col + comp_col_addon + offset, row,
                                       colspan, 1)
                     if verbose_name is None:
                         comp.description = six.text_type(
                             dep_field.verbose_name)
                     else:
                         comp.description = six.text_type(verbose_name)
                     self.add_component(comp)
                     offset += 1 + comp_col_addon
         row += height
Beispiel #8
0
 def define_gridheader(self):
     self.grid = XferCompGrid('report_%d' % self.item.id)
     self.grid.add_header('design', _('Designation'))
     if self.item.last_fiscalyear is not None:
         self.grid.add_header('year_n_1', _('year N-1'))
     self.grid.add_header('budget_n', _('budget N'))
     self.grid.add_header('year_n', _('year N'))
     if self.next_year is not None:
         self.grid.add_header('budget_n1', _('budget N+1'))
     if self.next_year_again is not None:
         self.grid.add_header('budget_n2', _('budget N+2'))
     self.grid.set_location(0, 10, 6)
     self.grid.no_pager = True
     self.add_component(self.grid)
Beispiel #9
0
 def define_gridheader(self):
     self.grid = XferCompGrid('report_%d' % self.item.id)
     self.grid.add_header('left', _('Designation'))
     if self.item.last_fiscalyear is not None:
         self.grid.add_header('left_n_1', _('year N-1'))
     self.grid.add_header('left_n', _('year N'))
     self.grid.add_header('space', '')
     self.grid.add_header('right', _('Designation'))
     if self.item.last_fiscalyear is not None:
         self.grid.add_header('right_n_1', _('year N-1'))
     self.grid.add_header('right_n', _('year N'))
     self.grid.set_location(0, 10, 6)
     self.grid.no_pager = True
     self.add_component(self.grid)
Beispiel #10
0
    def fill_tasks(self):
        self.new_tab(_('Tasks'))
        grid = XferCompGrid('tasks')
        grid.no_pager = True
        grid.add_header('name', _('name'))
        grid.add_header('trigger', _('trigger'))
        grid.add_header('nextdate', _('next date'), 'datetime')
        for job_desc in LucteriosScheduler.get_list():
            grid.set_value(job_desc[0], 'name', job_desc[1])
            grid.set_value(job_desc[0], 'trigger', '%s' % job_desc[2])
            grid.set_value(job_desc[0], 'nextdate', job_desc[3])

        grid.set_location(0, self.get_max_row() + 1, 2)
        grid.set_size(200, 500)
        self.add_component(grid)
Beispiel #11
0
 def fillresponse(self, legal_entity=0, name_filter=''):
     self.item.legal_entity = LegalEntity.objects.get(id=legal_entity)
     img = XferCompImage('img')
     img.set_value(self.icon_path())
     img.set_location(0, 0, 1, 3)
     self.add_component(img)
     self.fill_from_model(1, 0, True, ['legal_entity'])
     comp = XferCompEdit('filter')
     comp.set_value(name_filter)
     comp.set_action(self.request,
                     self.get_action(),
                     modal=FORMTYPE_REFRESH,
                     close=CLOSE_NO)
     comp.set_location(1, 2)
     comp.description = _('Filtrer by name')
     comp.is_default = True
     self.add_component(comp)
     identfilter = []
     if name_filter != "":
         identfilter = [
             Q(firstname__icontains=name_filter)
             | Q(lastname__icontains=name_filter)
         ]
     items = Individual.objects.filter(*identfilter).distinct()
     grid = XferCompGrid('individual')
     grid.set_model(items, None, self)
     grid.set_location(1, 3)
     grid.description = _('individual')
     grid.add_action(self.request,
                     ResponsabilityModify.get_action(
                         _("Select"), "images/ok.png"),
                     modal=FORMTYPE_MODAL,
                     close=CLOSE_YES,
                     unique=SELECT_SINGLE,
                     params={"SAVE": "YES"})
     grid.add_action(self.request,
                     IndividualShow.get_action(_("Show"),
                                               "images/edit.png"),
                     modal=FORMTYPE_MODAL,
                     close=CLOSE_NO,
                     unique=SELECT_SINGLE)
     grid.add_action(self.request,
                     IndividualAddModify.get_action(TITLE_CREATE,
                                                    "images/new.png"),
                     modal=FORMTYPE_MODAL,
                     close=CLOSE_NO)
     self.add_component(grid)
Beispiel #12
0
def thirdaddon_expense(item, xfer):
    if WrapAction.is_permission(xfer.request, 'condominium.change_expense'):
        try:
            status_filter = xfer.getparam('status_filter',
                                          Expense.STATUS_BUILDING)
            date_filter = xfer.getparam('date_filter', 0)
            current_year = FiscalYear.get_current()
            item.get_account(current_year,
                             current_system_account().get_provider_mask())
            xfer.new_tab(_('Expenses'))
            edt = XferCompSelect("status_filter")
            edt.set_select(list(Expense.get_field_by_name('status').choices))
            edt.set_value(status_filter)
            edt.description = _('Filter by type')
            edt.set_location(0, 1)
            edt.set_action(xfer.request,
                           xfer.return_action(),
                           modal=FORMTYPE_REFRESH,
                           close=CLOSE_NO)
            xfer.add_component(edt)
            edt = XferCompSelect("date_filter")
            edt.set_select([(0, _('only current fiscal year')),
                            (1, _('all expenses'))])
            edt.set_value(date_filter)
            edt.set_location(0, 2)
            edt.description = _('Filter by date')
            edt.set_action(xfer.request,
                           xfer.return_action(),
                           modal=FORMTYPE_REFRESH,
                           close=CLOSE_NO)
            xfer.add_component(edt)
            expense_filter = Q(status=status_filter) & Q(third=item)
            if date_filter == 0:
                expense_filter &= Q(date__gte=current_year.begin) & Q(
                    date__lte=current_year.end)
            expenses = Expense.objects.filter(expense_filter).distinct()
            expense_grid = XferCompGrid('expense')
            expense_grid.set_model(expenses,
                                   Expense.get_default_fields(status_filter),
                                   xfer)
            expense_grid.add_action_notified(xfer, Expense)
            expense_grid.set_location(0, 3, 2)
            xfer.add_component(expense_grid)
        except LucteriosException:
            pass
Beispiel #13
0
 def _show_initial_csv(self):
     tbl = XferCompGrid('CSV')
     for fieldname in self.spamreader.fieldnames:
         if fieldname != '':
             tbl.add_header(fieldname, fieldname)
     row_idx = 1
     for row in self.spamreader:
         if row[self.spamreader.fieldnames[0]] is not None:
             for fieldname in self.spamreader.fieldnames:
                 if fieldname != '':
                     tbl.set_value(row_idx, fieldname, row[fieldname])
             row_idx += 1
     tbl.set_location(1, 1, 2)
     self.add_component(tbl)
     lbl = XferCompLabelForm('nb_line')
     lbl.set_value(_("Total number of items: %d") % (row_idx - 1))
     lbl.set_location(1, 2, 2)
     self.add_component(lbl)
Beispiel #14
0
 def fillresponse(self):
     self.fields_desc.initial(self.item)
     self.read_criteria_from_params()
     self.fillresponse_add_title()
     self.fillresponse_search_select()
     self.fillresponse_search_values()
     self.fillresponse_show_criteria()
     row = self.get_max_row()
     self.filter_items()
     grid = XferCompGrid(self.field_id)
     grid.set_model(self.items, self.fieldnames, self)
     grid.add_action_notified(self)
     grid.set_location(0, row + 4, 6)
     grid.set_size(200, 500)
     self.add_component(grid)
     for act, opt in ActionsManage.get_actions(
             ActionsManage.ACTION_IDENT_LIST, self, key=action_list_sorted):
         self.add_action(act, **opt)
     self.add_action(WrapAction(_('Close'), 'images/close.png'))
Beispiel #15
0
    def fillresponse(self):

        grid = XferCompGrid('grid')
        grid.set_location(0, 0)

        grid.add_header('col1', "Integer", 'int')
        grid.add_header('col2', "Float", 'float')
        grid.add_header('col3', "Boolean", 'bool')
        grid.add_header('col4', "String", 'str')

        grid.set_value(1, "col1", 25)
        grid.set_value(1, "col2", 7.54)
        grid.set_value(1, "col3", True)
        grid.set_value(1, "col4", "foo")

        grid.set_value(5, "col1", 0)
        grid.set_value(5, "col2", 789.644)
        grid.set_value(5, "col3", False)
        grid.set_value(5, "col4", "string")

        # grid.add_action(self.get_action('Reopen', ''),-1, {'modal':FORMTYPE_REFRESH})
        self.add_component(grid)
Beispiel #16
0
    def fillresponse(self):

        grid = XferCompGrid('grid')
        grid.set_location(0, 0)

        grid.add_header('col1', "Integer", 'N0')
        grid.add_header('col2', "Float", 'N3')
        grid.add_header('col3', "Boolean", 'B')
        grid.add_header('col4', "String", None, 0, "{[b]}%s{[/b]}")

        grid.set_value(1, "col1", 2500)
        grid.set_value(1, "col2", 7.54)
        grid.set_value(1, "col3", True)
        grid.set_value(1, "col4", "foo")

        grid.set_value(5, "col1", 4)
        grid.set_value(5, "col2", 789.644)
        grid.set_value(5, "col3", False)
        grid.set_value(5, "col4", "string")

        # grid.add_action(self.return_action('Reopen', ''),-1, {'modal':FORMTYPE_REFRESH})
        self.add_component(grid)
Beispiel #17
0
 def fillresponse(self, field_id):
     self.items = self.model.objects.filter(id__in=self.getparam(field_id, ())).distinct()
     if len(self.items) < 2:
         raise LucteriosException(IMPORTANT, _("Impossible: you must to select many records!"))
     item_id = self.getparam('mrg_' + self.field_id, 0)
     if item_id != 0:
         self.item = self.model.objects.get(id=item_id)
     if (self.item is None) or (self.item.id is None):
         self.item = self.items[0]
     if self.getparam("CONFIRME") is None:
         dlg = self.create_custom()
         lbl = XferCompLabelForm('title')
         lbl.set_value_as_title(self.caption)
         lbl.set_location(1, 0)
         dlg.add_component(lbl)
         grid = XferCompGrid('mrg_' + self.field_id)
         grid.add_header('value', _('designation'))
         grid.add_header('select', _('is main?'), 'B')
         for item in self.items:
             grid.set_value(item.id, 'value', six.text_type(item))
             grid.set_value(item.id, 'select', item.id == self.item.id)
         grid.set_location(1, 1)
         grid.add_action(self.request, self.get_action(_("Edit"), "images/show.png"),
                         modal=FORMTYPE_MODAL, close=CLOSE_NO, unique=SELECT_SINGLE, params={"CONFIRME": 'OPEN'})
         grid.add_action(self.request, self.get_action(_("Select"), "images/ok.png"),
                         modal=FORMTYPE_REFRESH, close=CLOSE_NO, unique=SELECT_SINGLE)
         dlg.add_component(grid)
         dlg.add_action(self.get_action(_('Ok'), "images/ok.png"), close=CLOSE_YES, modal=FORMTYPE_MODAL,
                        params={'CONFIRME': 'YES', 'mrg_' + self.field_id: self.item.id})
         dlg.add_action(WrapAction(_("Cancel"), "images/cancel.png"))
     elif self.getparam("CONFIRME") == 'YES':
         alias_objects = []
         for item in self.items:
             if item.id != self.item.id:
                 alias_objects.append(item.get_final_child())
         self.item.get_final_child().merge_objects(alias_objects)
         self.redirect_action(ActionsManage.get_action_url(self.model.get_long_name(), 'Show', self), params={field_id: self.item.id})
     else:
         self.redirect_action(ActionsManage.get_action_url(self.model.get_long_name(), 'Show', self), params={field_id: self.item.id})
Beispiel #18
0
    def fillresponse(self, modelname, quotechar="'", delimiter=";", encoding="utf-8", dateformat="%d/%m/%Y", step=0):
        def add_item_if_not_null(new_item):
            if new_item is not None:
                self.items_imported[new_item.id] = new_item

        if modelname is not None:
            self.model = apps.get_model(modelname)
        self.quotechar = quotechar
        self.delimiter = delimiter
        self.encoding = encoding
        self.dateformat = dateformat

        img = XferCompImage('img')
        img.set_value(self.icon_path())
        img.set_location(0, 0, 1, 6)
        self.add_component(img)
        if step == 0:
            lbl = self._select_csv_parameters()
            step = 1
        elif step == 1:
            lbl = XferCompLabelForm('modelname')
            lbl.set_value(self.model._meta.verbose_name.title())
            lbl.set_location(1, 0)
            lbl.description = _('model')
            self.add_component(lbl)
            self._read_csv()
            self.new_tab(_("Fields"))
            self._select_fields()
            self.new_tab(_("Current content"))
            self._show_initial_csv()
            step = 2
        elif step == 2:
            lbl = XferCompLabelForm('modelname')
            lbl.set_value(self.model._meta.verbose_name.title())
            lbl.set_location(1, 0)
            lbl.description = _('model')
            self.add_component(lbl)
            fields_description, csv_readed = self._read_csv_and_convert()
            tbl = XferCompGrid('CSV')
            for field_description in fields_description:
                tbl.add_header(field_description[0], field_description[1], field_description[2], formatstr=field_description[3])
            row_idx = 1
            for row in csv_readed:
                for field_description in fields_description:
                    tbl.set_value(row_idx, field_description[0], row[field_description[0]])
                row_idx += 1
            tbl.set_location(1, 1, 2)
            self.add_component(tbl)
            lbl = XferCompLabelForm('nb_line')
            lbl.set_value(_("Total number of items: %d") % (row_idx - 1))
            lbl.set_location(1, 2, 2)
            self.add_component(lbl)
            step = 3
        elif step == 3:
            fields_description, csv_readed = self._read_csv_and_convert()
            self.model.initialize_import()
            self.items_imported = {}
            for rowdata in csv_readed:
                add_item_if_not_null(self.model.import_data(rowdata, dateformat))
            add_item_if_not_null(self.model.finalize_import())
            lbl = XferCompLabelForm('result')
            lbl.set_value_as_header(_("%d items are been imported") % len(self.items_imported))
            lbl.set_location(1, 2, 2)
            self.add_component(lbl)
            step = 4
        if step < 4:
            if step > 1:
                self.add_action(self.get_action(_('Back'), "images/left.png"),
                                close=CLOSE_NO, modal=FORMTYPE_REFRESH, params={'step': step - 2})
            self.add_action(self.get_action(_('Ok'), "images/ok.png"),
                            close=CLOSE_NO, modal=FORMTYPE_REFRESH, params={'step': step})
            self.add_action(WrapAction(_("Cancel"), "images/cancel.png"))
        else:
            self.add_action(WrapAction(_("Close"), "images/close.png"))