Exemplo n.º 1
0
	def render(self, reference, *args, **kw):
		output = kw.pop('out', None)
		encoding = kw.pop('encoding', 'utf8')
		
		module, _, function = reference.partition(':')
		module = __import__(module, fromlist=(function, ))
		template = getattr(module, function)(*args, **kw)
		
		if output and output != '-':
			with open(output, 'wb') as fh:
				flatten(template, fh, encoding=encoding)
			
			return '' if 'q' in self.flags else ("Template result written to: " + output)
		
		if pygments and (sys.stdout.isatty() or 'c' in self.flags) and 'C' not in self.flags:
			language = pygments.lexers.get_lexer_by_name('html')
			formatter = pygments.formatters.get_formatter_by_name('256')
			return pygments.highlight(flatten(template), language, formatter)
		
		flatten(template, sys.stdout)
Exemplo n.º 2
0
    def get(self, *arg, **args):
        if len(arg) > 0 and arg[0] != 'requests':
            return "Page not found: {}".format(arg[0])
        if 'view_status' not in args:
            args['view_status'] = 'New/Pending'
        if 'change_status' in args:
            changed_row = self.queries.change_request_status(
                args['id'], args['status'])

            try:
                request_row = cinje.flatten(rr(changed_row))
            except:
                request_row = ''  # Row was deleted

            np_info = self.queries.get_requests_info(
                status=args['view_status'])
            send_update(
                self._ctx.websocket,
                requestbutton=np_info.request_count,
                request_row=request_row,
                new_request_status=args['status'],
                request_id=args['id'])  # Update the request count button
            send_update(self._ctx.websocket_admin,
                        requestbutton=np_info.request_count
                        )  # Update the request count button

        requestlist = self.queries.get_requests(status=args['view_status'])

        try:
            requestinfo = np_info
        except:
            requestinfo = self.queries.get_requests_info(
                status=args['view_status'])

        return requeststemplate(_page,
                                "Requests",
                                self._ctx,
                                requestlist=requestlist,
                                view_status=args['view_status'],
                                requestinfo=requestinfo)
Exemplo n.º 3
0
	def test_flatten_filelike_unicode(self):
		container = StringIO()
		assert flatten(tmpl(), container) == 4
		assert container.getvalue() == 'Zoë\n'
Exemplo n.º 4
0
	def test_flatten_filelike_binary(self):
		container = BytesIO()
		assert flatten(tmpl(), container, encoding='utf8') == 5
		assert container.getvalue() == 'Zoë\n'.encode('utf8')
Exemplo n.º 5
0
	def test_flatten_string_binary(self):
		assert flatten(tmpl(), encoding='utf8') == 'Zoë\n'.encode('utf8')
Exemplo n.º 6
0
	def test_flatten_string_unicode(self):
		assert flatten(tmpl()) == 'Zoë\n'
Exemplo n.º 7
0
                if r[0] == 0: continue
                print('r', r[0], r)
                if djs[dj]['lp_id'] is None:
                    for rq in r.Played.song.new_requests:
                        print(rq.id, rq.msg, rq.name)
                        elements_to_update['request_id'] = rq.id
                        elements_to_update['new_request_status'] = 'played'
                    djs[dj]['lp_id'] = r.Played.played_id
                    # Next 2 lines are just to make testing easier. Will push the last played from the database on script startup
                    #new_row = cinje.flatten(lastplayed_row(context, r, ma=True, played=True))
                    #elements_to_update['lastplay'] = new_row
                elif r.Played.played_id == djs[dj]['lp_id']:
                    pass  # Skip if no change
                else:
                    new_row = cinje.flatten(
                        lastplayed_row(context, r, ma=True, played=True))
                    for rq in r.Played.song.new_requests:
                        elements_to_update['request_id'] = rq.id
                        elements_to_update['new_request_status'] = 'played'
                    elements_to_update['lastplay'] = new_row
                    djs[dj]['lp_id'] = r.Played.played_id
            try:
                listeners_row = db.Session.query(djs[dj]['listeners']).one()
            except:
                pass  # Skip because no listeners info
            else:
                if listeners_row.current != djs[dj]['current_listeners']:
                    djs[dj]['current_listeners'] = listeners_row.current
                    elements_to_update['listeners'] = listeners_row.current
                if listeners_row.max != djs[dj]['current_max_listeners']:
                    djs[dj]['current_max_listeners'] = listeners_row.max
Exemplo n.º 8
0
def test_using(tmpl):
	assert flatten(tmpl()) == "prefix\ncontent\npostfix\n"
Exemplo n.º 9
0
 def post(self, *arg, **args):
     now = datetime.utcnow()
     if not self._ctx.session.sitenick:
         self._ctx.session.sitenick = args['sitenick']
     sn = self._ctx.session.sitenick
     if args['formtype'] == 'request':
         new_row = self._ctx.requestlist(
             song_id=args['tid'],
             t_stamp=now,
             host=self._ctx.response.request.remote_addr,
             msg=args['comment'],
             name=sn,
             code=0,
             eta=now,
             status='new')
         self._ctx.db.add(new_row)
         self._ctx.db.commit()
         newcount = self._ctx.queries.get_requests_info().request_count
         request_row = cinje.flatten(requestrow(self._ctx, new_row))
         admin_request_row = cinje.flatten(
             adminrequestrow(self._ctx, new_row))
         send_update(
             self._ctx.websocket,
             requestbutton=newcount,
             request_row=request_row,
             request_id=args['tid'])  # Update the request count button
         send_update(self._ctx.websocket_admin,
                     requestbutton=newcount,
                     request_row=admin_request_row
                     )  # Update the request count button
         return {
             'html': 'Thank you for your request {}'.format(sn),
             'tid': args['tid'],
             'sitenick': sn,
             'newcount': newcount
         }
     elif args['formtype'] == 'mistag':
         new_row = self._ctx.mistags(track_id=args['tid'],
                                     reported=now,
                                     reported_by=sn,
                                     comments=args['comment'],
                                     title=args['title'],
                                     artist=args['artist'],
                                     album=args['album'])
         self._ctx.db.add(new_row)
         self._ctx.db.commit()
         return {
             'html': 'Thank you for your Mistag report {}'.format(sn),
             'sitenick': sn,
             'tid': args['tid']
         }
     elif args['formtype'] == 'suggestion':
         new_row = self._ctx.suggestions(
             comments="{} {}".format(args['comment'], now),
             title=args['title'],
             artist=args['artist'],
             album=args['album'],
             suggestor=sn,
         )
         self._ctx.db.add(new_row)
         self._ctx.db.commit()
         return {
             'html': "Thank you for your suggestion",
             'sitenick': sn,
         }