示例#1
0
文件: members.py 项目: lemoer/byro
    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        obj = self.get_object()
        if not obj.memberships.count():
            return context
        first = obj.memberships.first().start
        delta = now().date() - first
        context["member_since"] = {
            "days": int(delta.total_seconds() / (60 * 60 * 24)),
            "years": round(delta.days / 365, 1),
            "first": first,
        }
        context["current_membership"] = {
            "amount": obj.memberships.last().amount,
            "interval": obj.memberships.last().get_interval_display(),
        }
        context["statute_barred_debt"] = {"now": obj.statute_barred_debt()}
        context["statute_barred_debt"]["in1year"] = (
            obj.statute_barred_debt(relativedelta(years=1)) -
            context["statute_barred_debt"]["now"])

        context["tiles"] = []
        for __, response in member_dashboard_tile.send(self.request,
                                                       member=obj):
            if not response:
                continue
            if isinstance(response, collections.Mapping):
                context["tiles"].append(response)

        return context
示例#2
0
    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        obj = context['member']
        config = Configuration.get_solo()

        context['config'] = config
        context['bookings'] = self.get_bookings(obj)
        context['member_view_level'] = MemberViewLevel

        _now = now()
        memberships = obj.memberships.order_by('-start').all()
        if not memberships:
            return context

        first = memberships[0].start
        delta = timedelta()
        for ms in memberships:
            delta += (ms.end or _now.date()) - ms.start
            if not ms.end or ms.end <= _now.date():
                context['current_membership'] = ms
        context['memberships'] = memberships
        context['member_since'] = {
            'days': int(delta.total_seconds() / (60 * 60 * 24)),
            'years': round(delta.days / 365, 1),
            'first': first,
        }
        context['tiles'] = []
        for __, response in member_dashboard_tile.send(self.request,
                                                       member=obj):
            if not response:
                continue
            if isinstance(response, collections.Mapping) and response.get(
                    'public', False):
                context['tiles'].append(response)
        return context
示例#3
0
    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        obj = self.get_object()
        if not obj.memberships.count():
            return context
        first = obj.memberships.first().start
        delta = now().date() - first
        context['member_since'] = {
            'days': int(delta.total_seconds() / (60 * 60 * 24)),
            'years': round(delta.days / 365, 1),
            'first': first,
        }
        context['current_membership'] = {
            'amount': obj.memberships.last().amount,
            'interval': obj.memberships.last().get_interval_display()
        }
        context['statute_barred_debt'] = {
            'now': obj.statute_barred_debt(),
        }
        context['statute_barred_debt']['in1year'] = obj.statute_barred_debt(
            relativedelta(years=1)) - context['statute_barred_debt']['now']

        context['tiles'] = []
        for __, response in member_dashboard_tile.send(self.request,
                                                       member=obj):
            if not response:
                continue
            if isinstance(response, collections.Mapping):
                context['tiles'].append(response)

        return context
示例#4
0
    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
        obj = context["member"]
        config = Configuration.get_solo()

        context["config"] = config
        context["bookings"] = self.get_bookings(obj)
        context["member_view_level"] = MemberViewLevel

        _now = now()
        memberships = obj.memberships.order_by("-start").all()
        if not memberships:
            return context

        member_fields = obj.get_fields()
        for field in context["form"]:
            field.meta = (
                member_fields[field.name].getter(obj)
                if field.name in member_fields
                else ""
            ) or ""
        first = memberships[0].start
        delta = timedelta()
        for ms in memberships:
            delta += (ms.end or _now.date()) - ms.start
            if not ms.end or ms.end <= _now.date():
                context["current_membership"] = ms
        context["memberships"] = memberships
        context["member_since"] = {
            "days": int(delta.total_seconds() / (60 * 60 * 24)),
            "years": int(round(delta.days / 365, 1)),
            "first": first,
        }
        context["tiles"] = []
        for __, response in member_dashboard_tile.send(self.request, member=obj):
            if not response:
                continue
            if isinstance(response, collections.Mapping) and response.get(
                "public", False
            ):
                context["tiles"].append(response)
        return context