Plugin: Custom member data

Most groups will need to save more data about their members than byro does by default.

General

You can save custom member data via a special model class, which must reference byro.members.Member in a OneToOne relation, and the related name must start with “profile”.

Once you have generated this plugin (and have added the migrations, and run them), byro will discover the profile on its own, generate the fitting forms for members’ profile pages, and offer you to include it when configuring your registration form.

The Profile class

If you want to track, for example, if a member has agreed to receive your newsletter, you’d add a models.py file to your plugin, and put this inside:

 1from annoying.fields import AutoOneToOneField
 2from django.db import models
 3
 4class NewsletterProfile(models.Model):
 5    member = AutoOneToOneField(
 6        to='members.Member',
 7        on_delete=models.CASCADE,
 8        related_name='profile_shack',
 9    )
10    receives_newsletter = models.BooleanField(default=True)
11
12    def get_member_data(self):
13         return [
14            "You have opted in to receive our newsletter." if self.receives_newsletter else "",
15         ]

Members will receive occasional emails with all data that is saved about them – you can either return a list of strings, or a list of tuples (of keys and values, such as ("Has agreed to receive the newsletter", "True")). If you do not implement this method, byro will display all relevant data from this profile directly.

Custom views

If you want to add an custom tab to a member’s view related to your new content, you’ll have to write a simple view, add its url in your urls.py, and register it in your signals.py:

 1from django.dispatch import receiver
 2from django.urls import reverse
 3from django.utils.translation import ugettext_lazy as _
 4
 5from byro.office.signals import member_view
 6
 7
 8@receiver(member_view)
 9def newsletter_member_view(sender, signal, **kwargs):
10    member = sender
11    return {
12        'label': _('Newsletter'),
13        'url': reverse('plugins:byro_newsletter:members.newsletter', kwargs={'pk': member.pk}),
14        'url_name': 'plugins:byro_newsletter',
15    }

Every member will now have a tab with the label “Newsletter”. You could also add a general newsletter view to the sidebar:

 1from django.dispatch import receiver
 2from django.urls import reverse
 3from django.utils.translation import ugettext_lazy as _
 4
 5from byro.office.signals import nav_event
 6
 7@receiver(nav_event)
 8def newsletter_sidebar(sender, **kwargs):
 9    request = sender
10    return {
11        'icon': 'envelope-o',
12        'label': _('Newsletter'),
13        'url': reverse('plugins:byro_newsletter:dashboard'),
14        'active': 'byro_newsletter' in request.resolver_match.namespace and 'member' not in request.resolver_match.url_name,
15    }

Configuring your plugin

If you’d like to provide custom configuration options (for example, the name or latest issue of your newsletter), you can add a special configuration related model. If the model class inherits from ByroConfiguration and ends in Configuration, it will be automatically added to the settings page:

 1from django.db import models
 2from django.utils.translation import ugettext_lazy as _
 3
 4from byro.common.models.configuration import ByroConfiguration
 5
 6
 7class NewsletterConfiguration(ByroConfiguration):
 8
 9    url = models.CharField(
10        null=True, blank=True,
11        max_length=300,
12        verbose_name=_('Newsletter information URL'),
13        help_text=_('e.g. https://foo.bar.de/news')
14    )