-import datetime, random, string
+import datetime, random, string, os
+from flask import request
from sirius.models.db import db
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm.attributes import flag_modified
remote_side=[id])
def senders_formatted(self):
- return ', '.join((s or 'Anonymous') for s in self.senders)
\ No newline at end of file
+ return ', '.join((s or 'Anonymous') for s in self.senders)
+
+ @property
+ def url(self):
+ if 'DEVICE_KEY_DOMAIN' in os.environ:
+ return 'https://%s/%s' % (os.environ['DEVICE_KEY_DOMAIN'], self.secret)
+ else:
+ # if a DEVICE_KEY_DOMAIN is not defined, we need a request object
+ # to get the full URL.
+ return '%sprintkey/%s' % (request.url_root, self.secret)
+
\ No newline at end of file
<img class="device-key-symbol" src="{{url_for('static', filename='device-key-large.svg')}}">
<div class="device-key-label">Device Key:</div>
- <a class="device-key" href="{{request.url}}">{{request.url}}</a>
+ <a class="device-key" href="{{print_key.url}}">{{print_key.url}}</a>
<p class="what-is-this">
A Device Key is a secret URL for a device, containing both
<dd>
Little Printers<br>
<small>
- <a href="{{'co.nordprojects.littleprinter:///printers?add=' + request.url|urlencode}}">Open</a>
+ <a href="{{'co.nordprojects.littleprinter:///printers?add=' + print_key.url|urlencode}}">Open</a>
| <a href="https://itunes.apple.com/us/app/little-printers/id1393105914?ls=1&mt=8"> Download</a>
</small>
</dd>
<p>
You could do this from IFTTT, a Glitch app, your web app, or the command line. For example:
</p>
- <pre><code>curl '{{request.url}}?from=example' \
+ <pre><code>curl '{{print_key.url}}?from=example' \
-H 'content-type: text/plain' \
-d 'boop beep boop'</code></pre>
<code>Content-Type: text/html</code>
</p>
<p>Renders and prints HTML. Surprisingly powerful! Supports HTML elements, CSS styling, and embedded images.</p>
- <pre><code>curl '{{request.url}}?from=htmlexample' \
+ <pre><code>curl '{{print_key.url}}?from=htmlexample' \
-H 'content-type: text/html' \
-d "<h1>Yep, you can do this</h1><small>or this</small>"</code></pre>
<code>Content-Type: image/jpeg</code>
</p>
<p>Prints out the image data from the request body, in a lovely dithered style.</p>
- <pre><code>cat mindblown.gif | curl '{{request.url}}?from=image-example' \
+ <pre><code>cat mindblown.gif | curl '{{print_key.url}}?from=image-example' \
-X POST \
-H 'content-type: image/gif' \
--data-binary @-</code></pre>
<p>
Send HTML using the <tt>html</tt> key or plain text using the <tt>text</tt> key.
</p>
- <pre><code>curl '{{request.url}}?from=jsonexample' \
+ <pre><code>curl '{{print_key.url}}?from=jsonexample' \
-H 'content-type: application/json' \
-d '{"html":"<h1>header!</h1>"}'</code></pre>
<code>Content-Type: text/plain</code>
</p>
<p>Prints out plain text.</p>
- <pre><code>curl '{{request.url}}?from=text-example' \
+ <pre><code>curl '{{print_key.url}}?from=text-example' \
-H 'content-type: text/plain' \
-d "I'm a little teapot"</code></pre>
<p>This URL is also a status API e.g.</p>
- <pre><code>curl '{{request.url}}'</code></pre>
+ <pre><code>curl '{{print_key.url}}'</code></pre>
<p>This returns the status of the printer in JSON format.</p>