Clean up the forge_zephyr workflow.

(imported from commit c559cfde267bc537cf554705a9750dcfe76f88ce)
This commit is contained in:
Tim Abbott 2012-09-27 14:54:57 -04:00
parent 699e05383f
commit 6394a54db7
1 changed files with 16 additions and 10 deletions

View File

@ -179,21 +179,27 @@ def forge_zephyr(request):
if "time" not in request.POST:
return json_error("Missing time")
# Create a user for the sender of the message
user = create_user_if_needed(user_profile.realm, email, "test",
strip_html(request.POST['fullname']),
strip_html(request.POST['shortname']))
if (request.POST['type'] == 'personal' and ',' in request.POST['recipient']):
# Huddle message, need to make sure we're not syncing it twice!
if Zephyr.objects.filter(sender__user__email=email,
content=request.POST['new_zephyr'],
pub_date__gt=datetime.datetime.utcfromtimestamp(float(request.POST['time']) - 1).replace(tzinfo=utc),
pub_date__lt=datetime.datetime.utcfromtimestamp(float(request.POST['time']) + 1).replace(tzinfo=utc)):
# This is a duplicate huddle message, deduplicate!
return json_success()
# Don't send duplicate copies of forwarded messages
if Zephyr.objects.filter(sender__user__email=email,
content=request.POST['new_zephyr'],
pub_date__gt=datetime.datetime.utcfromtimestamp(float(request.POST['time']) - 1).replace(tzinfo=utc),
pub_date__lt=datetime.datetime.utcfromtimestamp(float(request.POST['time']) + 1).replace(tzinfo=utc)):
return json_success()
# Now confirm all the other recipients exist in our system
for user_email in request.POST["recipient"].split(","):
if request.POST['type'] == 'personal':
if ',' in request.POST['recipient']:
# Huddle message
for user_email in [e.strip() for e in request.POST["recipient"].split(",")]:
create_user_if_needed(user_profile.realm, user_email, "test",
user_email.split('@')[0],
user_email.split('@')[0])
else:
user_email = request.POST["recipient"].strip()
create_user_if_needed(user_profile.realm, user_email, "test",
user_email.split('@')[0],
user_email.split('@')[0])