Exemplo n.º 1
0
    def test_locale_media(self):

        with self.settings(MYMONEY={'USE_L10N_DIST': True}):
            widget = Datepicker()
            self.assertFalse(widget.media._js)

        with self.settings(MYMONEY={
                'USE_L10N_DIST': False,
                "BOOTSTRAP_DATEPICKER_LANGCODE": ''
        }):
            widget = Datepicker()
            self.assertFalse(widget.media._js)

        with self.settings(MYMONEY={
                'USE_L10N_DIST': False,
                "BOOTSTRAP_DATEPICKER_LANGCODE": 'fr'
        }):
            widget = Datepicker()
            self.assertIn(
                'bower_components/bootstrap-datepicker/dist/locales/bootstrap-datepicker.fr.min.js',
                widget.media._js)

        with self.settings(MYMONEY={
                'USE_L10N_DIST': False,
                "BOOTSTRAP_DATEPICKER_LANGCODE": 'fr-CH'
        }):
            widget = Datepicker()
            self.assertIn(
                'bower_components/bootstrap-datepicker/dist/locales/bootstrap-datepicker.fr-CH.min.js',
                widget.media._js)
Exemplo n.º 2
0
class TrendtimeForm(forms.Form):
    """
    Form to display bank transaction sums with a timeline.
    """
    CHART_LINE = 'line'
    CHART_BAR = 'bar'
    CHART_RADAR = 'radar'
    CHART_TYPES = (
        (CHART_LINE, ugettext_lazy('Line')),
        (CHART_BAR, ugettext_lazy('Bar')),
        (CHART_RADAR, ugettext_lazy('Radar')),
    )
    chart = forms.ChoiceField(choices=CHART_TYPES, initial=CHART_LINE)

    GRANULARITY_CHOICES = (
        (GRANULARITY_WEEK, ugettext_lazy('Week')),
        (GRANULARITY_MONTH, ugettext_lazy('Month')),
    )
    granularity = forms.ChoiceField(
        choices=GRANULARITY_CHOICES,
        initial=GRANULARITY_MONTH,
    )

    date = forms.DateField(required=True, widget=Datepicker())

    reconciled = forms.NullBooleanField(required=False)

    def __init__(self, *args, **kwargs):
        super(TrendtimeForm, self).__init__(*args, **kwargs)
        self.fields['reconciled'].widget.choices[0] = ('1', _('Reconciled?'))
        self.fields['date'].initial = formats.date_format(
            datetime.date.today(),
            'SHORT_DATE_FORMAT',
        )
Exemplo n.º 3
0
    def test_attrs(self):

        with self.settings(LANGUAGE_CODE='it'):
            widget = Datepicker()
            attrs = widget.build_attrs()
            self.assertEqual(attrs['data-date-language'], 'it')

        with self.settings(LANGUAGE_CODE='fr-ch'):
            widget = Datepicker()
            attrs = widget.build_attrs()
            self.assertEqual(attrs['data-date-language'], 'fr-CH')

        widget = Datepicker()
        attrs = widget.build_attrs(extra_attrs={
            'placeholder': 'foo',
            'data-date-orientation': 'bottom right',
        })
        self.assertIn('placeholder', attrs)
        self.assertEqual(attrs['data-date-orientation'], 'bottom right')
Exemplo n.º 4
0
    def test_format_value(self):

        with self.settings(LANGUAGE_CODE='en-us',
                           DATE_INPUT_FORMATS=('%Y-%m-%d', )):
            widget = Datepicker()
            self.assertEqual(
                widget._format_value(datetime.date(2015, 6, 22)),
                '2015-06-22',
            )

        with self.settings(LANGUAGE_CODE='fr-fr',
                           DATE_INPUT_FORMATS=('%d/%m/%Y', )):
            widget = Datepicker()
            self.assertEqual(
                widget._format_value(datetime.date(2015, 6, 22)),
                '22/06/2015',
            )
Exemplo n.º 5
0
 def __init__(self, user, *args, **kwargs):
     super(BankTransactionUpdateForm, self).__init__(*args, **kwargs)
     self.fields['tag'].queryset = (
         BankTransactionTag.objects.get_user_tags_queryset(user))
     self.fields['date'].widget = Datepicker()
Exemplo n.º 6
0
class BankTransactionListForm(forms.Form):

    label = forms.CharField(
        max_length=255,
        required=False,
        widget=forms.TextInput(attrs={
            'placeholder': ugettext_lazy('Label'),
        }))

    date_start = forms.DateField(
        required=False,
        widget=Datepicker(attrs={
            'placeholder': ugettext_lazy('Date start'),
        }),
    )
    date_end = forms.DateField(
        required=False,
        widget=Datepicker(attrs={
            'placeholder': ugettext_lazy('Date end'),
        }),
    )

    amount_min = forms.DecimalField(
        max_digits=10,
        decimal_places=2,
        localize=True,
        required=False,
        widget=forms.NumberInput(
            attrs={
                'placeholder': ugettext_lazy('Minimum amount'),
            }),
    )
    amount_max = forms.DecimalField(
        max_digits=10,
        decimal_places=2,
        localize=True,
        required=False,
        widget=forms.NumberInput(
            attrs={
                'placeholder': ugettext_lazy('Maximum amount'),
            }),
    )

    status = forms.ChoiceField(
        choices=(('', ugettext_lazy('Status?')), ) + BankTransaction.STATUSES,
        initial='',
        required=False,
    )
    reconciled = forms.NullBooleanField(required=False)
    tags = forms.ModelMultipleChoiceField(
        queryset=BankTransactionTag.objects.none(), required=False)

    operation = forms.ChoiceField(
        choices=(),
        required=False,
    )

    def __init__(self, user, bt_ids, submit, *args, **kwargs):
        super(BankTransactionListForm, self).__init__(*args, **kwargs)

        self.fields['tags'].queryset = (
            BankTransactionTag.objects.get_user_tags_queryset(user))
        self.fields['reconciled'].widget.choices[0] = ('1', _('Reconciled?'))

        for pk in bt_ids:
            self.fields['banktransaction_' + str(pk)] = forms.BooleanField(
                required=False,
                widget=forms.CheckboxInput(attrs={'data-id': pk}))

        choices = ()
        if user.has_perm('banktransactions.change_banktransaction'):
            choices += (
                ('reconcile', _('Reconcile')),
                ('unreconcile', _('Unreconcile')),
            )
        if user.has_perm('banktransactions.delete_banktransaction'):
            choices += (('delete', _('Delete')), )
        if choices:
            self.fields['operation'].choices = choices

        self._submit = submit

    def clean(self):
        cleaned_data = super(BankTransactionListForm, self).clean()

        if self._submit == 'filter':
            date_start = cleaned_data.get('date_start')
            date_end = cleaned_data.get('date_end')
            if date_start and date_end and date_start > date_end:
                raise forms.ValidationError(
                    _("Date start could not be greater than date end."),
                    code='date_start_greater',
                )

            amount_min = cleaned_data.get('amount_min', None)
            amount_max = cleaned_data.get('amount_max', None)
            if (amount_min is not None and amount_max is not None
                    and amount_min > amount_max):

                raise forms.ValidationError(
                    _("Minimum amount could not be greater than maximum "
                      "amount."),
                    code='amount_min_greater',
                )

        if self._submit == 'action' and cleaned_data['operation']:
            ids = set()
            for name, value in cleaned_data.items():
                if name.startswith('banktransaction_') and value:
                    ids.add(int(name[len('banktransaction_'):]))
            if not ids:
                raise forms.ValidationError(
                    _('To apply operations, you need to select some bank '
                      'transactions.'),
                    code='no_id',
                )
            cleaned_data['banktransactions'] = ids

        return cleaned_data
Exemplo n.º 7
0
class RatioForm(forms.Form):
    """
    Form to display bank transaction sums grouped by tags.
    """

    SINGLE_CREDIT = 'single_credit'
    SINGLE_DEBIT = 'single_debit'
    SUM_CREDIT = 'sum_credit'
    SUM_DEBIT = 'sum_debit'
    TYPES = (
        (ugettext_lazy('Sum'), (
            (SUM_DEBIT, ugettext_lazy('Expenses')),
            (SUM_CREDIT, ugettext_lazy('Income')),
        )),
        (ugettext_lazy('Single'), (
            (SINGLE_DEBIT, ugettext_lazy('Expenses')),
            (SINGLE_CREDIT, ugettext_lazy('Income')),
        )),
    )
    type = forms.ChoiceField(choices=TYPES, initial=SUM_DEBIT)

    CHART_DOUGHNUT = 'doughtnut'
    CHART_PIE = 'pie'
    CHART_POLAR = 'polar'
    CHART_TYPES = (
        (CHART_DOUGHNUT, ugettext_lazy('Doughnut')),
        (CHART_PIE, ugettext_lazy('Pie')),
        (CHART_POLAR, ugettext_lazy('Polar area')),
    )
    chart = forms.ChoiceField(
        choices=CHART_TYPES,
        initial=CHART_DOUGHNUT,
        required=False,
    )

    date_start = forms.DateField(
        widget=Datepicker(attrs={
            'placeholder': ugettext_lazy('Date start'),
        }),
    )
    date_end = forms.DateField(
        widget=Datepicker(attrs={
            'placeholder': ugettext_lazy('Date end'),
        }),
    )

    reconciled = forms.NullBooleanField(required=False)

    tags = forms.ModelMultipleChoiceField(
        queryset=BankTransactionTag.objects.none(),
        required=False
    )

    sum_min = forms.DecimalField(
        max_digits=10,
        decimal_places=2,
        localize=True,
        required=False,
        widget=forms.NumberInput(attrs={
            'placeholder': _('Minimum sum'),
        }),
    )
    sum_max = forms.DecimalField(
        max_digits=10,
        decimal_places=2,
        localize=True,
        required=False,
        widget=forms.NumberInput(attrs={
            'placeholder': _('Maximum sum'),
        }),
    )

    def __init__(self, user, *args, **kwargs):
        super(RatioForm, self).__init__(*args, **kwargs)

        self.fields['tags'].queryset = (
            BankTransactionTag.objects.get_user_tags_queryset(user)
        )
        self.fields['reconciled'].widget.choices[0] = ('1', _('Reconciled?'))

    def clean(self):
        cleaned_data = super(RatioForm, self).clean()

        date_start = cleaned_data.get('date_start')
        date_end = cleaned_data.get('date_end')
        if date_start and date_end and date_start > date_end:
            raise forms.ValidationError(
                _("Date start could not be greater than date end."),
                code='date_start_greater',
            )

        sum_min = cleaned_data.get('sum_min', None)
        sum_max = cleaned_data.get('sum_max', None)
        if sum_min is not None and sum_max is not None and sum_min > sum_max:
            raise forms.ValidationError(
                _("Minimum sum could not be greater than maximum sum."),
                code='sum_min_greater',
            )

        return cleaned_data
Exemplo n.º 8
0
 def __init__(self, *args, **kwargs):
     super(BankTransactionSchedulerUpdateForm,
           self).__init__(*args, **kwargs)
     self.fields['date'].widget = Datepicker()