1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

# Copyright 2013 The Distro Tracker Developers 

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

# at https://deb.li/DTAuthors 

# 

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

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

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

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

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

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

# Re-export some objects of django_email_accounts 

from django_email_accounts.models import ( # noqa 

AddEmailConfirmation, 

MergeAccountConfirmation, 

ResetPasswordConfirmation, 

UserEmail, 

UserRegistrationConfirmation 

) 

from django_email_accounts.models import User as EmailAccountsUser 

 

 

class User(EmailAccountsUser): 

""" 

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

with some Distro Tracker specific methods. 

""" 

class Meta: 

proxy = True 

 

def is_subscribed_to(self, package): 

""" 

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

considered subscribed if at least one of its associated emails is 

subscribed. 

 

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

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

""" 

from distro_tracker.core.models import PackageName 

if not isinstance(package, PackageName): 

try: 

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

except PackageName.DoesNotExist: 

return False 

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

return qs.exists() 

 

def unsubscribe_all(self, email=None): 

""" 

Terminate the user's subscription associated to the given 

email. Uses the main email if not specified. 

""" 

if not email: 

email = self.main_email 

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

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

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