コード例 #1
0
ファイル: module.py プロジェクト: vituocgia/wshop
def get_taxes_of_effective_rules(taxing_context, tax_rules):
    """
    Get taxes grouped by priority from effective tax rules.

    Effective tax rules is determined by first limiting the scope to the
    rules that match the given taxing context (see `TaxRule.match`) and
    then further limiting the matching rules by selecting only the rules
    in the highest numbered override group.

    The `Tax` objects in the effective rules will be grouped by the
    priority of the rules.  The tax groups are returned as list of tax
    lists.

    :type taxing_context: wshop.core.taxing.TaxingContext
    :param tax_rules:
      Tax rules to filter from.  These should be ordered desceding by
      override group and then ascending by priority.
    :type tax_rules: Iterable[TaxRule]
    :rtype: list[list[wshop.core.models.Tax]]
    """
    # Limit our scope to only matching rules
    matching_rules = (tax_rule for tax_rule in tax_rules
                      if tax_rule.matches(taxing_context))

    # Further limit our scope to the highest numbered override group
    grouped_by_override = groupby(matching_rules, attrgetter('override_group'))
    highest_override_group = first(grouped_by_override, (None, []))[1]

    # Group rules by priority
    grouped_rules = groupby(highest_override_group, attrgetter('priority'))
    tax_groups = [[rule.tax for rule in rules] for (_, rules) in grouped_rules]

    return tax_groups
コード例 #2
0
 def decode(self, obj):
     if len(obj) == 1:
         tag, val = first(obj.items())
         info = self.tags.get(tag)
         if info:
             return info["decoder"](val)
     return obj
コード例 #3
0
ファイル: utils.py プロジェクト: vituocgia/wshop
def get_first_day_of_the_current_week(today_start):
    locale = i18n.get_current_babel_locale()
    first_day_of_the_week = today_start
    if today_start.weekday() == locale.first_week_day:
        return first_day_of_the_week

    def get_prospect(i):
        return (today_start - datetime.timedelta(days=i))

    return iterables.first([
        get_prospect(i) for i in range(1, 7)
        if get_prospect(i).weekday() == locale.first_week_day
    ])
コード例 #4
0
    def get_method_checkout_phase_object(self):
        """
        :rtype: wshop.front.checkout.CheckoutPhaseViewMixin|None
        """
        if hasattr(self, "_checkout_phase_object"):
            return self._checkout_phase_object

        method = self.get_method()
        if not method:
            return None
        phases = get_checkout_phases_for_service(self.checkout_process, method)
        phase = first(phases)
        if not phase:
            return None
        self._checkout_phase_object = phase
        return phase
コード例 #5
0
    def get_context_data(self, **kwargs):
        context = super(AddonUploadConfirmView, self).get_context_data(**kwargs)

        with zipfile.ZipFile(self.get_addon_path()) as zf:
            context["filenames"] = sorted(zf.namelist())
            pkg_info_path = first(filename for filename in context["filenames"] if filename.endswith("PKG-INFO"))
            if pkg_info_path:
                context["pkg_info"] = zf.read(pkg_info_path).decode("UTF-8", "replace")

        context["toolbar"] = Toolbar([
            PostActionButton(
                icon="fa fa-download",
                form_id="install_form",
                text=_("Install Addon"),
                extra_css_class="btn-success",
            )
        ])
        return context
コード例 #6
0
ファイル: forms.py プロジェクト: vituocgia/wshop
 def get_by_object(self, obj):
     return first(form_info for form_info in self.values()
                  if isinstance(obj, form_info.model))
コード例 #7
0
 def current_pane(self):
     pane_id = self.request.POST.get("pane_id")
     return first(filter(lambda x: x.identifier == pane_id, self.panes),
                  None)