コード例 #1
0
ファイル: rfdocs_tags.py プロジェクト: Chaser/rfdocs
 def render(self, context):
     filepath = self.filepath.resolve(context)
     if not include_is_allowed(filepath):
         if settings.DEBUG:
             return "[Didn't have permission to include file]"
         else:
             return ""  # Fail silently for invalid includes.
     try:
         with open(filepath, "r") as fp:
             tree = etree.parse(StringIO(fp.read()), etree.HTMLParser())
         output = ""
         for child in tree.find(self.locator).iterchildren():
             output += lh.tostring(child)
     except IOError:
         output = ""
     if self.parsed:
         try:
             t = Template(output, name=filepath)
             return t.render(context)
         except TemplateSyntaxError as e:
             if settings.DEBUG:
                 return "[Included template had syntax error: %s]" % e
             else:
                 return ""  # Fail silently for invalid included templates.
     return output
コード例 #2
0
ファイル: rfdocs_tags.py プロジェクト: eduardozamin/rfdocs
 def render(self, context):
     filepath = self.filepath.resolve(context)
     if not include_is_allowed(filepath):
         if settings.DEBUG:
             return "[Didn't have permission to include file]"
         else:
             return ''  # Fail silently for invalid includes.
     try:
         with open(filepath, 'r') as fp:
             tree = etree.parse(StringIO(fp.read()), etree.HTMLParser())
         output = ''
         for child in tree.find(self.locator).iterchildren():
             output += lh.tostring(child)
     except IOError:
         output = ''
     if self.parsed:
         try:
             t = Template(output, name=filepath)
             return t.render(context)
         except TemplateSyntaxError as e:
             if settings.DEBUG:
                 return "[Included template had syntax error: %s]" % e
             else:
                 return ''  # Fail silently for invalid included templates.
     return output
コード例 #3
0
ファイル: views.py プロジェクト: learngest/apps
def render_htm(request, c, base, contents_prefix):
    """
    Render html support
    """
    suffixe = os.path.join( contents_prefix,
                            c.module.slug,
                            c.langue,
                            c.ressource)
    support_path = os.path.join(settings.PROJECT_PATH, suffixe)
    base = os.path.join(base, suffixe)
    if not include_is_allowed(support_path):
        request.user.message_set.create(
                message=_("You are not allowed to browse the requested content."))
        return HttpResponseRedirect(LOGIN_REDIRECT_URL)
    try:
        support = open(support_path).read()
    except IOError:
        if settings.DEBUG:
            support = "Unable to open file %s" % support_path
        else:
            support = "<!-- Unable to open file %s -->\n" % support_path
    return render_to_response('learning/html_support.html',{
                                'title': c.titre,
                                'baselink': base,
                                'breadcrumb': c.module.titre(c.langue),
                                'support' : support,
                                }, context_instance=RequestContext(request))
コード例 #4
0
ファイル: templatetags.py プロジェクト: fingul/pytoolbox
def inline(filepath, msg=True, autoescape=True):
    if filepath in (None, settings.TEMPLATE_STRING_IF_INVALID):
        return settings.TEMPLATE_STRING_IF_INVALID
    if include_is_allowed(filepath):
        return open(filepath, encoding='utf-8').read()
    if settings.DEBUG and msg:
        filepath_escaped = conditional_escape(filepath) if autoescape else filepath
        return _("[Didn't have permission to include file {0}]").format(filepath_escaped)
    return settings.TEMPLATE_STRING_IF_INVALID
コード例 #5
0
def inline(filepath, msg=True, autoescape=True):
    if filepath in (None, settings.TEMPLATE_STRING_IF_INVALID):
        return settings.TEMPLATE_STRING_IF_INVALID
    if include_is_allowed(filepath):
        return open(filepath, encoding='utf-8').read()
    if settings.DEBUG and msg:
        filepath_escaped = conditional_escape(filepath) if autoescape else filepath
        return _("[Didn't have permission to include file {0}]").format(filepath_escaped)
    return settings.TEMPLATE_STRING_IF_INVALID
コード例 #6
0
ファイル: views.py プロジェクト: learngest/apps
def render_swf(request, c, base, contents_prefix):
    """
    Render swf (flash) support
    """
    suffixe = os.path.join( contents_prefix,
                            c.module.slug,
                            c.langue,
                            'flash',
                            c.ressource)
    support_path = os.path.join(settings.PROJECT_PATH, suffixe)
    base = os.path.join(base, suffixe)
    if not include_is_allowed(support_path):
        request.user.message_set.create(
                message=_("You are not allowed to browse the requested content."))
        return HttpResponseRedirect(LOGIN_REDIRECT_URL)
    return render_to_response('learning/swf_support.html',{
                                'title': c.titre,
                                'baselink': base,
                                'contents_prefix': contents_prefix,
                                'breadcrumb': c.module.titre(c.langue),
                                'support' : suffixe,
                                }, context_instance=RequestContext(request))
コード例 #7
0
ファイル: views.py プロジェクト: learngest/lg
def support(request, slug=None, **kwargs):
    """View: html course content.
    The new_visitor_may_see_module decorator checks that:
    - the module is part of at least one course the visitor's
      group is subscribed to

    Returns the html content embedded in user's template.
    """
    # on a besoin de la langue dans laquelle afficher le contenu
    # elle peut être passée en GET (param l) sinon langue défaut du visiteur
    # calcul du nom absolu du fichier à rendre
    # si aucun contenu type 'htm' trouvé pour ce module, redirection /home/
    # sinon, recherche d'un contenu dans la langue demandée
    # s'il n'existe pas, recherche d'un contenu en français
    if not slug:
        return HttpResponseRedirect(reverse('l_dashboard'))
    v = request.session['v']
    ltyp = kwargs['ltyp']
    langue = request.GET.get('l',request.session['django_language'])
    #try:
    #    m = Module.objects.get(slug=slug)
    #except Module.DoesNotExist:
    #    return HttpResponseRedirect(reverse('l_dashboard'))
    m = get_object_or_404(Module, slug=slug)
    lc = Contenu.objects.filter(module=m,type=ltyp)
    if not lc:
        return HttpResponseRedirect(reverse('l_dashboard'))
    try:
        c = lc.get(langue=langue)
        msg = None
    except Contenu.DoesNotExist:
        try:
            c = lc.get(langue='fr')
            msg = _('We are sorry, this content is not available in your preferred language.') 
        except Contenu.DoesNotExist:
            return HttpResponseRedirect(reverse('l_dashboard'))
    except AssertionError:
        c = lc[0]
#    base = ''
#    if 'HTTP_X_FORWARDED_HOST' in request.META:
#        base =''.join(('http://',request.META['HTTP_X_FORWARDED_HOST']))
#    else:
#        if 'HTTP_REFERER' in request.META:
#            base = '/'.join(request.META['HTTP_REFERER'].split('/')[:3])
#        else:
#            return HttpResponseRedirect(reverse('v_home'))
    site_id = getattr(settings, 'SITE_ID', 1)
    site = Site.objects.get(id=site_id)
    base = ''.join(('http://', site.domain))
    contents_url = getattr(settings, 'LG_CONTENTS_URL', 'contents')
    v.lastw = datetime.datetime.now()
    request.session['v'] = v
    v.save()
    if ltyp == 'htm':
        support_path = os.path.normpath(os.path.join(
                                settings.LG_CONTENTS_ROOT,
                                c.module.slug,
                                c.langue,
                                c.ressource))
        base = os.path.join(
                base,
                contents_url,
                c.module.slug,
                c.langue,
                c.ressource)
        if not include_is_allowed(support_path):
            return HttpResponseRedirect(reverse('l_dashboard'))
        try:
            support = open(support_path).read()
        except IOError:
            if settings.DEBUG:
                support = "Unable to open file %s" % support_path
            else:
                support = "<!-- Unable to open file %s -->\n" % support_path
        return render_to_response('learning/support.html',
                                    {'visiteur': v.prenom_nom(),
                                     'client': v.groupe.client,
                                     'administrateur': v.status>COACH,
                                     'vgroupe': v.groupe,
                                     'admin': v.status,
                                     'baselink': base,
                                     'msg': msg,
                                     'support': support})
    else:
        support = os.path.join('/',
                contents_url,
                c.module.slug,
                c.langue,
                'flash',
                c.ressource)
        base = os.path.join(
                base,
                contents_url,
                c.module.slug,
                c.langue,
                'flash',
                c.ressource)
        return render_to_response('learning/anim.html',
                                    {'visiteur': v.prenom_nom(),
                                     'client': v.groupe.client,
                                     'administrateur': v.status>COACH,
                                     'vgroupe': v.groupe,
                                     'admin': v.status,
                                     'baselink': base,
                                     'msg': msg,
                                     'support': support})