~ubuntuone-hackers/ubuntu-rest-scopes/trunk

« back to all changes in this revision

Viewing changes to src/scopes/reddit.py

  • Committer: Facundo Batista
  • Date: 2016-06-07 14:01:21 UTC
  • mfrom: (508.2.9 ubuntu-rest-scopes)
  • mto: This revision was merged to the branch mainline in revision 527.
  • Revision ID: facundo@taniquetil.com.ar-20160607140121-id1tzsnaa1lwtrb8
MergedĀ lp:~jamesh/ubuntu-rest-scopes/multi-column

Show diffs side-by-side

added added

removed removed

Lines of Context:
253
253
        """Do the preview."""
254
254
        result = kwargs['result']
255
255
        locale = kwargs['locale']
256
 
        mascot = None
 
256
        art = header = buttons = None
257
257
        if result['cat_id'] == "posts":
 
258
            mascot = None
258
259
            if result['media_type'] == "rich" \
259
260
                    and result['media_preview'] \
260
261
                    and not result['media_preview'].endswith('.gif'):
261
 
                yield dict(widget={
 
262
                art = dict(widget={
262
263
                    'id': 'image',
263
264
                    'type': 'image',
264
265
                    'source': result['media_preview'],
265
266
                })
266
267
            elif result['media_type'] == "video":
267
 
                yield dict(widget={
 
268
                art = dict(widget={
268
269
                    'id': 'video',
269
270
                    'type': 'video',
270
271
                    'source': result['target'],
272
273
                })
273
274
            else:
274
275
                mascot = result['mascot']
275
 
            # yield a 'header' widget
276
 
            yield dict(widget={
 
276
            # create a 'header' widget
 
277
            header = dict(widget={
277
278
                'id': 'header',
278
279
                'type': 'header',
279
280
                'title': result['title'],
288
289
                actions.append({'label': translator('View', locale),
289
290
                                'uri': result['target'],
290
291
                                'id': 'action2'})
291
 
            yield dict(widget={
 
292
            buttons = dict(widget={
292
293
                'id': 'buttons',
293
294
                'type': 'actions',
294
295
                'actions': actions,
295
296
            })
296
297
        else:
297
298
            if result['art']:
298
 
                # yield an 'image' widget
299
 
                yield dict(widget={
 
299
                # create an 'image' widget
 
300
                art = dict(widget={
300
301
                    'id': 'image',
301
302
                    'type': 'image',
302
303
                    'source': result['art'],
303
304
                    })
304
 
            # yield a 'header' widget
305
 
            yield dict(widget={
 
305
            # create a 'header' widget
 
306
            header = dict(widget={
306
307
                'id': 'header',
307
308
                'type': 'header',
308
309
                'title': result['title'],
312
313
            actions = [{'label': '/r/' + result['subreddit'],
313
314
                        'uri': result['uri'],
314
315
                        'id': 'action1'}]
315
 
            yield dict(widget={
 
316
            buttons = dict(widget={
316
317
                'id': 'buttons',
317
318
                'type': 'actions',
318
319
                'actions': actions,
319
320
            })
 
321
 
 
322
        # column layouts
 
323
        single = [[]]
 
324
        double =[[], []]
 
325
        if art:
 
326
            single[0].append(art['widget']['id'])
 
327
            double[0].append(art['widget']['id'])
 
328
        single[0].append('header')
 
329
        double[0].append('header')
 
330
        single[0].append('buttons')
 
331
        double[0].append('buttons')
 
332
        single[0].append('text')
 
333
        double[1].append('text')
 
334
        yield dict(columns=[single, double])
 
335
 
 
336
        # yield previously created widgets
 
337
        if art:
 
338
            yield art
 
339
        yield header
 
340
        yield buttons
 
341
 
320
342
        # yield a 'text' widget
321
343
        yield dict(widget={
322
344
            'id': 'text',