Unverified Commit f95c142d authored by Joost Rijneveld's avatar Joost Rijneveld
Browse files

Create models for mailinglists

parent f2950417
from django.contrib import admin
from .models import MailingList, VerbatimAddress, ListAlias
class VerbatimAddressInline(admin.TabularInline):
model = VerbatimAddress
class ListAliasInline(admin.TabularInline):
model = ListAlias
@admin.register(MailingList)
class GeneralMeetingAdmin(admin.ModelAdmin):
inlines = (VerbatimAddressInline, ListAliasInline)
from django.apps import AppConfig
class MailinglistsConfig(AppConfig):
name = 'mailinglists'
# -*- coding: utf-8 -*-
# Generated by Django 1.10b1 on 2016-07-31 10:23
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('committees', '0004_auto_20160727_2253'),
('members', '0003_merge_20160727_2333'),
]
operations = [
migrations.CreateModel(
name='ListAlias',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('alias', models.EmailField(max_length=254)),
],
),
migrations.CreateModel(
name='MailingList',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.EmailField(max_length=254)),
('prefix', models.CharField(max_length=200)),
('archived', models.BooleanField(default=True)),
('moderated', models.BooleanField(default=False)),
('committees', models.ManyToManyField(blank=True, to='committees.Committee')),
('members', models.ManyToManyField(blank=True, to='members.Member')),
],
),
migrations.CreateModel(
name='VerbatimAddress',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('address', models.EmailField(max_length=254)),
('mailinglist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='addresses', to='mailinglists.MailingList')),
],
),
migrations.AddField(
model_name='listalias',
name='mailinglist',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='aliasses', to='mailinglists.MailingList'),
),
]
from django.db import models
from members.models import Member
from committees.models import Committee
class MailingList(models.Model):
name = models.EmailField()
prefix = models.CharField(max_length=200)
archived = models.BooleanField(default=True)
moderated = models.BooleanField(default=False)
members = models.ManyToManyField(Member, blank=True)
committees = models.ManyToManyField(Committee, blank=True)
def all_addresses(self):
for member in self.members.all():
yield member.email
for committee in self.committees.all().prefetch_related("members"):
for member in committee.members.all():
yield member.email
for address in self.addresses.all():
yield address
def __str__(self):
return self.name
class VerbatimAddress(models.Model):
address = models.EmailField()
mailinglist = models.ForeignKey(MailingList, related_name='addresses')
class ListAlias(models.Model):
alias = models.EmailField()
mailinglist = models.ForeignKey(MailingList, related_name='aliasses')
# Consider replacing this completely;
# - either by a cronjob Python script that queries the database directly
# - or by a __save__ handler that updates mailman when MailingList changes
def API(request):
pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment