@@ -0,0 +1,1542 @@
+%0Afrom uuid import uuid4%0Afrom datetime import datetime%0A%0Afrom twisted.internet.defer import returnValue%0A%0Afrom vumi.persist.model import Model, Manager%0Afrom vumi.persist.fields import (Unicode, ManyToMany, ForeignKey, Timestamp,%0A                                    Dynamic)%0A%0Afrom go.vumitools.account import UserAccount, PerAccountStore%0A%0A%0Aclass OptOut(Model):%0A    %22%22%22An opt_out%22%22%22%0A    user_account = ForeignKey(UserAccount)%0A    created_at = Timestamp(default=datetime.utcnow)%0A%0A%0Aclass OptOutStore(PerAccountStore):%0A    def setup_proxies(self):%0A        self.opt_outs = self.manager.proxy(OptOut)%0A%0A    def opt_out_id(self, addr_type, addr_value):%0A        return %22%25s:%25s%22 %25 (addr_type, addr_value)%0A%0A    @Manager.calls_manager%0A    def new_opt_out(self, addr_type, addr_value):%0A        opt_out_id = self.opt_out_id(addr_type, addr_value)%0A        opt_out = self.opt_outs(%0A            opt_out_id, user_account=self.user_account_key, **fields)%0A        yield opt_out.save()%0A        returnValue(opt_out)%0A%0A    def get_opt_out(self, addr_type, addr_value):%0A        return self.opt_outs.load(self.opt_out_id(addr_type, addr_value)%0A%0A    @Manager.calls_manager%0A    def delete_opt_out(self, addr_type, addr_value):%0A        opt_out = yield self.get_opt_out(addr_type, addr_value)%0A        if opt_out:%0A            yield opt_out.delete()%0A%0A    @Manager.calls_manager%0A    def list_opt_outs(self):%0A        # Not stale, because we're using backlinks.%0A        user_account = yield self.get_user_account()%0A        returnValue(user_account.backlinks.opt_outs(self.manager))%0A

add opt_out store for accounts