def memberpage_primary(sender, **kwargs): request = sender if request.resolver_match and request.resolver_match.view_name.startswith( "public:memberpage"): secret_token = request.resolver_match.kwargs.get('secret_token') if secret_token: kwargs = {'secret_token': secret_token} config = Configuration.get_solo() result = [{ 'label': _('Member page'), 'url': reverse('public:memberpage:member.dashboard', kwargs=kwargs), 'active': request.resolver_match.view_name == 'public:memberpage.dashboard', }] if config.can_see_other_members in ( MemberViewLevel.NAME_ONLY, MemberViewLevel.NAME_AND_CONTACT): member = Member.all_objects.filter( profile_memberpage__secret_token=secret_token).first() if member.is_active: result.append({ 'label': _('Member list'), 'url': reverse('public:memberpage:member.list', kwargs=kwargs), 'active': request.resolver_match.view_name == 'public:memberpage:member.list', }) return result return {}
def update_liabilites(self): from byro.bookkeeping.models import Account, VirtualTransaction config = Configuration.get_solo() booking_date = now() cutoff = (booking_date - relativedelta(months=config.liability_interval)).date() account = Account.objects.filter( account_category='member_fees').first() for membership in self.memberships.all(): date = membership.start if date < cutoff: date = cutoff end = membership.end or booking_date.date() while date <= end: vt = VirtualTransaction.objects.filter( source_account=account, value_datetime=date, member=self, ).first() if vt: if vt.amount != membership.amount: vt.amount = membership.amount vt.save() else: VirtualTransaction.objects.create( source_account=account, value_datetime=date, amount=membership.amount, member=self, ) date += relativedelta(months=membership.interval)
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
def configuration(): config = Configuration.get_solo() config.name = "Der Verein e.V." config.backoffice_mail = "*****@*****.**" config.mail_from = "*****@*****.**" config.save() return config
def configuration(): config = Configuration.get_solo() config.name = 'Association Name' config.backoffice_mail = '*****@*****.**' config.mail_from = '*****@*****.**' config.save() return config
def balance(self) -> Decimal: config = Configuration.get_solo() cutoff = now() - relativedelta(months=config.liability_interval) qs = self.transactions.filter(value_datetime__lte=now(), value_datetime__gte=cutoff) liability = qs.filter(source_account__account_category='member_fees').aggregate(liability=models.Sum('amount'))['liability'] or Decimal('0.00') asset = qs.filter(destination_account__account_category='member_fees').aggregate(asset=models.Sum('amount'))['asset'] or Decimal('0.00') return asset - liability
def configuration(): config = Configuration.get_solo() config.name = "Association Name" config.backoffice_mail = "*****@*****.**" config.mail_from = "*****@*****.**" config.can_see_other_members = MemberViewLevel.NAME_AND_CONTACT config.save() return config
def get_url(self): config = Configuration.get_solo() relative_url = reverse('public:memberpage:member.dashboard', kwargs={'secret_token': self.secret_token}) if config.public_base_url: return urljoin(config.public_base_url, relative_url) else: return relative_url
def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) config = Configuration.get_solo() context['config'] = config context['member_view_level'] = MemberViewLevel context['member_undisclosed'] = Member.objects.exclude( profile_memberpage__is_visible_to_members=True).count() return context
def form_valid(self, form): form.save() messages.success(self.request, _('The config was saved successfully.')) LogEntry.objects.create( content_object=Configuration.get_solo(), user=self.request.user, action_type="byro.settings.registration.changed") return super().form_valid(form)
def __call__(self, request): url = resolve(request.path_info) if not request.user.is_anonymous and url.url_name not in self.ALLOWED_URLS: config = Configuration.get_solo() values = ('name', 'backoffice_mail', 'mail_from') if not all(getattr(config, value, None) for value in values): return redirect('office:settings.initial') return self.get_response(request)
def __call__(self, request): url = resolve(request.path_info) translation.activate(settings.DEFAULT_LANGUAGE) if not request.user.is_anonymous and url.url_name not in self.ALLOWED_URLS: config = Configuration.get_solo() values = ("name", "backoffice_mail", "mail_from") if not all(getattr(config, value, None) for value in values): return redirect("office:settings.initial") return self.get_response(request)
def get_url(self): config = Configuration.get_solo() relative_url = reverse( "public:memberpage:member.dashboard", kwargs={"secret_token": self.secret_token}, ) if config.public_base_url: return urljoin(config.public_base_url, relative_url) else: return urljoin(settings.SITE_URL, relative_url)
def create_configs(self): config = Configuration.get_solo() config.name = 'Der Verein DER VEREIN' config.address = 'Erich-Weinert-Straße 53\n39104 Magdeburg' config.url = 'https://dervereindervere.in' config.language = 'de' config.currency = 'EUR' config.mail_from = '*****@*****.**' config.backoffice_mail = '*****@*****.**' config.save()
def get_form(self): config_models = [ model for model in apps.get_models() if issubclass(model, ByroConfiguration) ] data = self.request.POST if self.request.method == "POST" else None return [ ConfigurationForm( prefix=Configuration.__name__, instance=Configuration.get_solo(), data=data, ) ] + [ forms.modelform_factory(model, fields="__all__")( prefix=model.__name__, instance=model.get_solo(), data=data) for model in config_models if not issubclass(model, Configuration) ]
def create_configs(self): config = Configuration.get_solo() config.name = 'Der Verein e.V.' config.address = 'Erich-Weinert-Straße 53\n39104 Magdeburg' config.url = 'https://dervereindervere.in' config.language = 'de' config.currency = 'EUR' config.mail_from = '*****@*****.**' config.backoffice_mail = '*****@*****.**' config.registration_form = [ { "name": "member__number", "position": 1 }, { "name": "member__name", "position": 2 }, { "name": "member__address", "position": 3 }, { "name": "member__email", "position": 4 }, { "name": "membership__start", "position": 5, "default_date": "beginning_month", }, { "name": "membership__interval", "default": "1", "position": 6 }, { "name": "membership__amount", "default": "23", "position": 7 }, ] config.save() config.log(SOURCE_TEST_DATA, '.changed')
def record_disclosure_email(self): config = Configuration.get_solo() template = config.record_disclosure_template data = get_member_data(self) for profile in self.profiles: data += get_member_data(profile) key_value_data = [d for d in data if len(d) == 2 and not isinstance(d, str)] text_data = [d for d in data if isinstance(d, str)] key_length = min(max(len(d[0]) for d in key_value_data), 20) key_value_text = '\n'.join((key + ':').ljust(key_length) + ' ' + value for key, value in key_value_data) if text_data: key_value_text += '\n' + '\n'.join(text_data) context = { 'association_name': config.name, 'data': key_value_text, 'number': self.number, 'balance': '{currency} {balance}'.format(currency=config.currency, balance=self.balance) } return template.to_mail(self.email, context=context, save=False)
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
def get_queryset(self): config = Configuration.get_solo() if config.can_see_other_members not in ( MemberViewLevel.NAME_ONLY, MemberViewLevel.NAME_AND_CONTACT): raise Http404("Page does not exist") secret_token = self.kwargs.get('secret_token') if not secret_token: raise Http404("Page does not exist") member = Member.all_objects.filter( profile_memberpage__secret_token=secret_token).first() if not member: raise Http404("Page does not exist") if not member.is_active: raise Http404("Page does not exist") return Member.objects.filter( profile_memberpage__is_visible_to_members=True).order_by('name')
def memberpage_primary(sender, **kwargs): request = sender if request.resolver_match and request.resolver_match.view_name.startswith( "public:memberpage"): secret_token = request.resolver_match.kwargs.get("secret_token") if secret_token: kwargs = {"secret_token": secret_token} config = Configuration.get_solo() result = [{ "label": _("Member page"), "url": reverse("public:memberpage:member.dashboard", kwargs=kwargs), "active": request.resolver_match.view_name == "public:memberpage.dashboard", }] if config.can_see_other_members in ( MemberViewLevel.NAME_ONLY, MemberViewLevel.NAME_AND_CONTACT, ): member = Member.all_objects.filter( profile_memberpage__secret_token=secret_token).first() if member.is_active: result.append({ "label": _("Member list"), "url": reverse("public:memberpage:member.list", kwargs=kwargs), "active": request.resolver_match.view_name == "public:memberpage:member.list", }) return result return {}
def statute_barred_debt(self, future_limit=relativedelta()) -> Decimal: limit = relativedelta(months=Configuration.get_solo().liability_interval) - future_limit last_unenforceable_date = now().replace(month=12, day=31) - limit - relativedelta(years=1) return max(Decimal('0.00'), -self._calc_balance(last_unenforceable_date))
def get_form_kwargs(self): form_kwargs = super().get_form_kwargs() form_kwargs["instance"] = Configuration.get_solo() return form_kwargs