# Copyright (c) 2015, InfluxFramework LLC
# License: MIT. See LICENSE

import influxframework
from influxframework.model.document import Document


class EmailGroupMember(Document):
	def after_delete(self):
		email_group = influxframework.get_doc("Email Group", self.email_group)
		email_group.update_total_subscribers()

	def after_insert(self):
		email_group = influxframework.get_doc("Email Group", self.email_group)
		email_group.update_total_subscribers()


def after_doctype_insert():
	influxframework.db.add_unique("Email Group Member", ("email_group", "email"))
