Esempio n. 1
0
	def get(self,identifier):
		# le model d'un Theme côté js correspond au field 'info' du Theme() qui correspond à 'info.json'
		# on ne retourne donc que le field 'info' marshalé
		theme = get_theme(identifier)
		# on enrichi la resource avec la liste des fichiers du dossier static/img
		theme.info['options']['files'] = get_img_files(theme)
		return marshal(theme.info, theme_info_fields)
Esempio n. 2
0
def render(template, **context):
    '''
    Render a template with uData frontend specifics

        * Theme
    '''
    theme = current_app.config['THEME']
    return render_theme_template(get_theme(theme), template, **context)
Esempio n. 3
0
def main_live(id):
    race = races.find_one({'_id': ObjectId(id) })
    theme = request.args.get('theme', race['theme'])
    try:
        t = get_theme(theme)
    except KeyError:
        flash(u"Thème introuvable: %s" % theme, "error")
        theme = "default"

    return render_theme_template(theme, "index.html", race_id=str(id), home_timeline=[])
Esempio n. 4
0
    def test_get_helpers(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            cool = app.theme_manager.themes['cool']
            plain = app.theme_manager.themes['plain']
            assert get_theme('cool') is cool
            assert get_theme('plain') is plain
            tl = get_themes_list()
            assert tl[0] is cool
            assert tl[1] is plain
            try:
                get_theme('notthis')
            except KeyError:
                pass
            else:
                raise AssertionError("Getting a nonexistent theme should "
                                     "raise KeyError")
Esempio n. 5
0
    def test_get_helpers(self):
        app = Flask(__name__)
        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
        Themes(app, app_identifier='testing')

        with app.test_request_context('/'):
            cool = app.theme_manager.themes['cool']
            plain = app.theme_manager.themes['plain']
            assert get_theme('cool') is cool
            assert get_theme('plain') is plain
            tl = get_themes_list()
            assert tl[0] is cool
            assert tl[1] is plain
            try:
                get_theme('notthis')
            except KeyError:
                pass
            else:
                raise AssertionError("Getting a nonexistent theme should "
                                     "raise KeyError")
Esempio n. 6
0
	def put(self, identifier):
		# pas de champs libres pour l'instant
		# if current_user.is_admin():
		args = parser_theme.parse_args()
		theme = get_theme(identifier)

		args['options'] = parser_theme_options.parse_args(req=args)
		args['options']['styles'] = parser_theme_styles.parse_args(req=args['options'])
		preview = args['options']['preview'] = parser_theme_preview.parse_args(req=args['options'])
		logo = args['options']['logo'] = parser_theme_logo.parse_args(req=args['options'])

		if args['options']['styles'] != theme.options['styles']:
			lessok = write_less_file(args['options']['styles'], theme)
			if not lessok:
				return {'error': "Erreur pendant la compilation. Verifiez et modifiez votre thème puis relancez la compilation.", "code": "compil"}, 400
		
		info = write_json_file(args, theme.path)

		app.theme_manager.refresh()

		racelist = races.find({'theme': identifier})
		shout_rooms = ["dash"]

		if preview != theme.options['preview'] or args['options']['styles'] != theme.options['styles'] or logo != theme.options['logo']:
			if racelist.count():
				# preview avec une race ayant le bon thème
				make_preview("/%s" % racelist[0]['_id'], theme, preview['width'], preview['height'])
				shout_rooms.extend([ 'play_%s' % r['_id'] for r in racelist])
			else:
				arace = races.find_one()
				if arace:
					# preview avec passage du thème en param (pas de race avec le thème voulu)
					# on ne propage pas l'event l'event sur les live potentiellement ouvert
					race_param = "/%s?theme=%s" % (arace['_id'], theme.identifier)
					make_preview(race_param, theme, preview['width'], preview['height'])
				else:
					try:
						# FIXME
						# preview de ... la page de login :) 
						# Puisque cette vue est en login_required (et le restera)
						# et que Phantom n'est pas authentifié (et ne devrait pas le devenir)...
						user = TW_Client.api.verify_credentials()
						make_preview("?theme=%s" % theme.identifier, theme, preview['width'], preview['height'])
					except TweepError:
						print "Aucune Race et pas de compte twitter"

		ShoutNamespace.broadcast_room(shout_rooms, 'theme_updated', {'theme': identifier })

		# Liste des fichiers images
		args['options']['files'] = get_img_files(theme)
		
		return marshal(json.loads(json.dumps(args)), theme_info_fields)
Esempio n. 7
0
def favicon() :
    """
        App favicon
    """
    default = app.config['DEFAULT_THEME']
    theme_id = app.config.get(u'THEME', default)
    theme = get_theme(theme_id)
    path = op.join(theme.static_path, 'img', 'favicon.png')
    if op.exists(path) :
        url = static_file_url(theme, 'img/favicon.png')
    else :
        url = url_for('static', filename='img/favicon.png')
    return redirect(url)
Esempio n. 8
0
def get_theme_files(identifier):
	theme = get_theme(identifier)
	files_list = []
	for root, dirs, files in os.walk(theme.path):
		path = os.path.relpath(root, theme.path).split(os.sep)
		if len(path) == 1 and path[0] == ".":
			path.pop(0)
		for file in files:
			files_list.append({
				'filename': file, 
				'localpath': os.path.join(root, file), 
				'remotepath': os.path.join( identifier, os.path.join(*path), file) if len(path) else os.path.join(identifier, file)
			})
	return files_list
Esempio n. 9
0
	def get(self, identifier):
		args = parser_s3.parse_args()
		try:
			theme = get_theme(identifier)
		except KeyError:
			scafold_theme(identifier)

		try:
			if args['download']:
				path = os.path.join(app.config['ROOT_PATH'], 'themes')
				return download_handler(identifier, path)
			else:
				return list_key(identifier)
		except ValueError:
			return {"error": "ValueError", 'code': "pb de configuration"}, 200
Esempio n. 10
0
	def post(self, identifier):
		# @todo:
		# en dur juste pour le logo et avec un pb d'attributs très certainement ('url' vs 'path')
		theme = get_theme(identifier)
		args = parser_upload.parse_args()
		file = args['image']
		if file and allowed_file(file.filename):
			filename = secure_filename(file.filename)
			pathfile = os.path.join('img', filename)
			file.save(os.path.join(theme.static_path, pathfile))
			theme.info['options']['logo']['url'] = pathfile

			return redirect(os.path.join("/admin/#themes/edit", identifier)) 
		else:
			return {"error": "pas de fichier ou fichier non autorisé", 'code': "upload"}, 403
Esempio n. 11
0
def render_themed(template, **context):
    ident = current_app.config.get('DEFAULT_THEME', 'plain')
    return render_theme_template(get_theme(ident), template, **context)
Esempio n. 12
0
    def post(self):
    	themes = get_all_themes()
    	default_theme = get_theme('default')
    	args = parser_theme.parse_args()
    	
    	if 'identifier' not in args or args['identifier'] is None:
    		args['identifier'] = slugify( args['name'].decode('utf-8'), delim=u'_')

    	req_ident = [th for th in themes if th.identifier == args['identifier']]
    	if not len(req_ident):
    		path_theme = scafold_theme(args['identifier'])

    		args['options'] = parser_theme_options.parse_args(req=args)
    		# args['options']['styles'] = parser_theme_styles.parse_args(req=args['options'])
    		# Pour le hash 'styles' on pioche dans le thème par défaut
    		args['options']['styles'] = default_theme.options['styles']

    		# Liste des fichiers images
    		default_img = get_img_files(default_theme)
    		for img in default_img:
    			f = img['path'].split('/')[-1:][0]
    			src_path = os.path.join(default_theme.path, 'static/img', f)
    			dest_path = os.path.join(path_theme, 'static/img', f)
    			local('cp %s %s' % (src_path, dest_path))

    		preview = args['options']['preview'] = parser_theme_preview.parse_args(req=args['options'])
    		args['options']['logo'] = parser_theme_logo.parse_args(req=args['options'])
    		# nom du logo en dur, où mettre ca ?
    		args['options']['logo']['path'] = os.path.join("/themes", args['identifier'], 'img', 'logo.png')

    		info = write_json_file(args, path_theme)

			# FIXME
    		# Copie du contenu des fichiers less du thème par défaut, VRAIMENT pas terrible
    		# Procéder comme pour les .html plus bas avec des 'templates' less dans les statics de l'app ?
    		less_styles_path = os.path.join(default_theme.path, 'less', 'styles.less')
    		with open(less_styles_path, 'r') as o:
    			content = o.read()
	    		with open(os.path.join(path_theme, 'less', 'styles.less'), 'w') as f:
	    			f.write(content)

	    	# autant styles ca peut encore passer, autant là on a un problème. 
    		less_base_path = os.path.join(default_theme.path, 'less', 'base.less')
    		with open(less_base_path, 'r') as o:
    			content = o.read()
	    		with open(os.path.join(path_theme, 'less', 'base.less'), 'w') as f:
	    			f.write(content)

    		tpl_index_src, tpl_index_src_path, tpl_index_src_func = app.jinja_env.loader.get_source(app.jinja_env,'public/_index.html')
    		with open(os.path.join(path_theme, 'templates', 'index.html'), 'w') as f:
    			f.write(tpl_index_src)

    		tpl_info_src, tpl_info_src_path, tpl_info_src_func = app.jinja_env.loader.get_source(app.jinja_env,'public/_info.html')
    		with open(os.path.join(path_theme, 'templates', 'info.html'), 'w') as f:
    			f.write(tpl_info_src)

    		# refresh de la liste des thèmes
    		app.theme_manager.refresh()

    		# recup du thèmes nouvellement créé
    		theme = get_theme(args['identifier'])

    		# Liste des fichiers images (copiés plus haut)
    		args['options']['files'] = get_img_files(theme)

    		# création du fichier variables.less et compilation des fichiers less
    		lessok = write_less_file(args['options']['styles'], theme)

    		try:
    			# FIXME
    			# preview de ... la page de login :) 
    			# Puisque cette vue est en login_required (et le restera sans doute)
    			# et que Phantom n'est pas authentifié (et ne devrait pas le devenir)...
    			user = TW_Client.api.verify_credentials()
    			return_call = make_preview("?theme=%s" % theme.identifier, theme, preview['width'], preview['height'])
    		except TweepError:
    			print "Aucune Race et pas de compte twitter"

    		# theme.info['options']['files'] = get_img_files(theme)
    		return marshal(theme.info, theme_info_fields)

    	return marshal(args, theme_info_fields)
Esempio n. 13
0
	def delete(self, identifier):
		theme = get_theme(identifier)
		local('rm -rf %s' % theme.path)
		app.theme_manager.refresh()
		return [], 200
Esempio n. 14
0
def get_current_theme(app, g):
    if g.theme is not None:
        ident = g.theme
    else:
        ident = app.config.get('DEFAULT_THEME')
    return get_theme(ident)
Esempio n. 15
0
def render_admin(template, **context):
    return render_theme_template(get_theme('admin'), template, **context)