@require_GET
def set_subscription(request, token, subscribe):
 try:
  username = UsernameCipher().decrypt(token.encode())
  user = User.objects.get(username=username)
 except UnicodeDecodeError:
  raise Http404('base64url')
 except UsernameDecryptionException as exn:
  raise Http404(exn.message)
 except User.DoesNotExist:
  raise Http404('username')
 if subscribe:
  UserPreference.objects.get_or_create(user=user, key=NOTIFICATION_PREF_KEY, defaults={'value': UsernameCipher.encrypt(user.username)})
  return render_to_response('resubscribe.html', {'token': token})
 else:
  UserPreference.objects.filter(user=user, key=NOTIFICATION_PREF_KEY).delete()
  return render_to_response('unsubscribe.html', {'token': token})

@ require_GET def set_subscription ( request , token , subscribe ) : try : username = UsernameCipher ( ) . decrypt ( token . encode ( ) ) user = User . objects . get ( username = username ) except UnicodeDecodeError : raise Http404 ( 'base64url' ) except UsernameDecryptionException as exn : raise Http404 ( exn . message ) except User . DoesNotExist : raise Http404 ( 'username' ) if subscribe : UserPreference . objects . get_or_create ( user = user , key = NOTIFICATION_PREF_KEY , defaults = { 'value' : UsernameCipher . encrypt ( user . username ) } ) return render_to_response ( 'resubscribe.html' , { 'token' : token } ) else : UserPreference . objects . filter ( user = user , key = NOTIFICATION_PREF_KEY ) . delete ( ) return render_to_response ( 'unsubscribe.html' , { 'token' : token } )
a view that disables or re-enables notifications for a user who may not be authenticated this view is meant to be the target of an unsubscribe link .