Example #1
0
    def display_unicode(self, value, for_viewing_only=False):
        """Take a value and format it for output use. The way to
        display it depends on the type of the inputfield (e.g. a float
        and an date interval are both floats, but displayed very
        differently).

        Note: this function is used for scenarios that are _already
        imported_, not for the to-be-imported scenarios here in
        importtool. So we can't use the IntervalValue etc classes
        above.

        If for_viewing_only is True, we can do some more conversions
        that aren't possible in cases where the displayed value has to
        be imported again (like in Excel files). It means that we can expand
        'select' input fields.
        """

        if value is None:
            return u''

        if self.type == InputField.TYPE_INTERVAL:
            return unicode(get_intervalstring_from_dayfloat(value))

        if self.type == InputField.TYPE_SELECT:
            try:
                value_object = self.build_value_object(value)
                value = (value_object if for_viewing_only
                         else value_object.value)
            except ValueError:
                pass

        if self.type == InputField.TYPE_BOOLEAN and for_viewing_only:
            return "Ja" if value else "Nee"

        return unicode(value)
Example #2
0
    def get_editor_dict(self):
        item = self.inputfield.get_editor_dict()

        item["defaultValue"] = self.getValue()
        if self.inputfield.type == InputField.TYPE_BOOLEAN:
            if self.getValue() == 0:
                item["defaultValue"] = False
            else:
                item["defaultValue"] = True

        if self.inputfield.type == InputField.TYPE_INTERVAL:
            item["defaultValue"] = get_intervalstring_from_dayfloat(
                self.getValue())
        if self.inputfield.type == InputField.TYPE_DATE:
            a = self.getValue()
            try:
                item["defaultValue"] = (a[8:10] + '/' + a[5:7] +
                                        '/' + a[0:4] + ' 3:00')
            except:
                pass
        elif self.inputfield.type == InputField.TYPE_FILE:
            item["type"] = "StaticTextItem"
            item["required"] = False
        return item
Example #3
0
 def testNegative(self):
     self.assertEquals(
         dates.get_intervalstring_from_dayfloat(-0.5),
         '-1 d 12:00')
Example #4
0
 def testTrivialCorrect(self):
     self.assertEquals(
         dates.get_intervalstring_from_dayfloat(5.4375),
         '5 d 10:30')
Example #5
0
 def to_excel(self):
     return get_intervalstring_from_dayfloat(self.value)
Example #6
0
 def testNegative(self):
     self.assertEquals(dates.get_intervalstring_from_dayfloat(-0.5),
                       '-1 d 12:00')
Example #7
0
 def testTrivialCorrect(self):
     self.assertEquals(dates.get_intervalstring_from_dayfloat(5.4375),
                       '5 d 10:30')