1# Copyright 2013 The Distro Tracker Developers 

2# See the COPYRIGHT file at the top-level directory of this distribution and 

3# at https://deb.li/DTAuthors 

4# 

5# This file is part of Distro Tracker. It is subject to the license terms 

6# in the LICENSE file found in the top-level directory of this 

7# distribution and at https://deb.li/DTLicense. No part of Distro Tracker, 

8# including this file, may be copied, modified, propagated, or distributed 

9# except according to the terms contained in the LICENSE file. 

10"""Models for the :mod:`distro_tracker.accounts` app.""" 

11# Re-export some objects of django_email_accounts 

12from django_email_accounts.models import ( # noqa 

13 AddEmailConfirmation, 

14 MergeAccountConfirmation, 

15 ResetPasswordConfirmation, 

16 UserEmail, 

17 UserRegistrationConfirmation 

18) 

19from django_email_accounts.models import User as EmailAccountsUser 

20 

21 

22class User(EmailAccountsUser): 

23 """ 

24 Proxy model for :class:`django_email_accounts.models.User` extending it 

25 with some Distro Tracker specific methods. 

26 """ 

27 class Meta: 

28 proxy = True 

29 

30 def is_subscribed_to(self, package): 

31 """ 

32 Checks if the user is subscribed to the given package. The user is 

33 considered subscribed if at least one of its associated emails is 

34 subscribed. 

35 

36 :param package: The name of the package or a package instance 

37 :type package: string or :class:`distro_tracker.core.models.PackageName` 

38 """ 

39 from distro_tracker.core.models import PackageName 

40 if not isinstance(package, PackageName): 

41 try: 

42 package = PackageName.objects.get(name=package) 

43 except PackageName.DoesNotExist: 

44 return False 

45 qs = package.subscriptions.filter(user_email__in=self.emails.all()) 

46 return qs.exists() 

47 

48 def unsubscribe_all(self, email=None): 

49 """ 

50 Terminate the user's subscription associated to the given 

51 email. Uses the main email if not specified. 

52 """ 

53 if not email: 

54 email = self.main_email 

55 user_email = UserEmail.objects.get(email=email) 

56 if self.emails.filter(pk=user_email.id).exists(): 56 ↛ exitline 56 didn't return from function 'unsubscribe_all', because the condition on line 56 was never false

57 user_email.emailsettings.subscription_set.all().delete()