[slack] Change qid_or_uuid -> qid and update Document2.DoesNotExist try/except
@@ -92,23 +92,23 @@ def handle_on_message(channel_id, bot_id, text, user_id):
def handle_on_link_shared(channel_id, message_ts, links):
for item in links:
path = urlsplit(item['url'])[2]
- id_type, qid_or_uuid = urlsplit(item['url'])[3].split('=')
+ id_type, qid = urlsplit(item['url'])[3].split('=')
try:
if path == '/hue/editor' and id_type == 'editor':
- doc = Document2.objects.get(id=qid_or_uuid)
+ doc = Document2.objects.get(id=qid)
elif path == '/hue/gist' and id_type == 'uuid' and ENABLE_GIST_PREVIEW.get():
- doc = _get_gist_document(uuid=qid_or_uuid)
+ doc = _get_gist_document(uuid=qid)
else:
raise PopupException(_("Cannot unfurl link"))
+ except Document2.DoesNotExist:
+ msg = "Document with {key}={value} does not exist".format(key='uuid' if id_type == 'uuid' else 'id', value=qid)
+ raise PopupException(_(msg))
doc_data = json.loads(doc.data)
statement = doc_data['snippets'][0]['statement_raw'] if id_type == 'editor' else doc_data['statement_raw']
dialect = doc_data['dialect'].capitalize() if id_type == 'editor' else doc.extra.capitalize()
created_by = doc.owner.get_full_name() or doc.owner.username
- except Document2.DoesNotExist:
- msg = "Document with {key}={value} does not exist".format(key='uuid' if id_type == 'uuid' else 'id', value=qid_or_uuid)
- raise PopupException(_(msg))
payload = _make_unfurl_payload(item['url'], statement, dialect, created_by)
response = slack_client.chat_unfurl(channel=channel_id, ts=message_ts, unfurls=payload)
