def pre_confirm(self): """ Implementation of a hook method which is executed instead of :py:meth:`handle` when the command is not confirmed. """ if not SourcePackageName.objects.exists_with_name(self.package): if BinaryPackageName.objects.exists_with_name(self.package): binary_package = \ BinaryPackageName.objects.get_by_name(self.package) self.warn('{package} is not a source package.'.format( package=self.package)) self.reply('{package} is the source package ' 'for the {binary} binary package'.format( package=binary_package.main_source_package_name, binary=binary_package.name)) self.package = binary_package.main_source_package_name.name else: self.warn( '{package} is neither a source package ' 'nor a binary package.'.format(package=self.package)) settings = get_or_none(EmailSettings, user_email__email__iexact=self.user_email) if not settings or not settings.is_subscribed_to(self.package): self.error( "{email} is not subscribed, you can't unsubscribe.".format( email=self.user_email) ) return False self.reply('A confirmation mail has been sent to ' + self.user_email) return True
def pre_confirm(self): """ Implementation of a hook method which is executed instead of :py:meth:`handle` when the command is not confirmed. """ settings = get_or_none(EmailSettings, user_email__email__iexact=self.user_email) if settings and settings.is_subscribed_to(self.package): self.warn('{email} is already subscribed to {package}'.format( email=self.user_email, package=self.package)) return False if not SourcePackageName.objects.exists_with_name(self.package): if BinaryPackageName.objects.exists_with_name(self.package): binary_package = \ BinaryPackageName.objects.get_by_name(self.package) self.warn('{package} is not a source package.'.format( package=self.package)) self.reply('{package} is the source package ' 'for the {binary} binary package'.format( package=binary_package.main_source_package_name, binary=binary_package.name)) self.package = binary_package.main_source_package_name.name else: self.warn( '{package} is neither a source package ' 'nor a binary package.'.format(package=self.package)) if PseudoPackageName.objects.exists_with_name(self.package): self.warn('Package {package} is a pseudo package.'.format( package=self.package)) else: self.warn('Package {package} is not even a pseudo ' 'package.'.format(package=self.package)) try: Subscription.objects.create_for( email=self.user_email, package_name=self.package, active=False) except ValidationError as e: self.warn(e.message) return False self.reply('A confirmation mail has been sent to ' + self.user_email) return True