Allow overwriting of APNS as iOS will send it on each startup

(imported from commit 4a22f9f37d550b6c2e06f543434466453e196458)
This commit is contained in:
Leo Franchi 2013-10-16 14:57:12 -04:00
parent 1d82704b8d
commit 507a3ecab3
1 changed files with 6 additions and 5 deletions

View File

@ -2705,11 +2705,12 @@ def add_apns_device_token(request, user_profile, token=REQ):
if token == '' or len(token) > 255: if token == '' or len(token) > 255:
return json_error('Empty or invalid length APNS token') return json_error('Empty or invalid length APNS token')
try: # The iOS app receives the token on each startup, so overwrite with our
apns_token = AppleDeviceToken(user=user_profile, token=token) # latest value
apns_token.save() token, created = AppleDeviceToken.objects.get_or_create(user=user_profile, token=token)
except IntegrityError: if not created:
return json_error("APNS token already exists") token.last_updated = now()
token.save(update_fields=['last_updated'])
return json_success() return json_success()