Projet

Général

Profil

« Précédent | Suivant » 

Révision 4fa3be27

Ajouté par Josué Kouka il y a plus de 8 ans

restructure sites app static directory (#9437)

Voir les différences:

mandayejs/mandaye/views.py
20 20
import json
21 21
import logging
22 22
import urlparse
23
import urllib 
23
import urllib
24 24

  
25 25
from django.conf import settings
26 26
from django.contrib.auth import views as auth_views
......
58 58

  
59 59
    def get_context_data(self, **kwargs):
60 60
        context = super(Panel, self).get_context_data(**kwargs)
61
        context['login_txt'] = _('login')
62
        context['logout_txt'] = _('logout')
63
        context['site_scripts'] = getattr(settings, 'SITE_SCRIPTS', [])
61
        scripts = getattr(settings, 'SITE_SCRIPTS', [])
62
        static_root_path = getattr(settings, 'SITE_STATIC_ROOT_PATH', '')
63
        context['site_scripts'] = [os.path.join(static_root_path, s) for s in scripts]
64 64
        context['ca_url'] = getattr(settings, 'SITE_CA_URL', '/')
65 65
        context['is_linked'] = self.is_account_linked()
66 66
        return context
......
71 71
        try:
72 72
            User = get_user_model()
73 73
            user = User.objects.get(username=self.request.user.username)
74
            return user.usercredentials_set.get().linked 
74
            return user.usercredentials_set.get().linked
75 75
        except (User.DoesNotExist, UserCredentials.DoesNotExist) as e:
76 76
            return False
77 77

  
......
106 106
    else:
107 107
        form = FormFactory(auto_id=True, locators=settings.SITE_LOCATORS)
108 108
    if not form.is_valid():
109
        site_static_root = getattr(settings, 'SITE_STATIC_ROOT_PATH', '')
110
        associate_static = getattr(settings, 'SITE_ASSOCIATE_STATIC',
111
                                   {'css':'', 'js':''})
112

  
109 113
        response = render(request, 'mandaye/associate.html', {
110
                    'form': form, 
111
                    'submit': _('submit'), 
112
                    'associate': _('associate your account'),
113
                    'associate_static': getattr(settings, 
114
                        'SITE_ASSOCIATE_STATIC', 
115
                        {'css':'', 'js':''})
114
                    'form': form,
115
                    'associate_js': os.path.join(site_static_root, associate_static['js']),
116
                    'associate_css': os.path.join(site_static_root, associate_static['css'])
116 117
                })
117 118
        return response
118
    
119

  
119 120
    return HttpResponseRedirect(resolve_url('post-login'))
120 121

  
121 122
@login_required
......
132 133
@login_required
133 134
def post_login_do(request, *args, **kwargs):
134 135
    credentials = get_object_or_404(UserCredentials, user=request.user)
136
    site_static_root = os.path.join(getattr(settings, 'STATIC_ROOT'), getattr(settings, 'SITE_STATIC_ROOT_PATH', ''))
137
    site_auth_checker = getattr(settings, 'SITE_AUTH_CHECKER', '')
135 138
    login_info = {
136 139
        'address': request.build_absolute_uri(settings.SITE_LOGIN_PATH),
137 140
        'cookies': [],
138 141
        'locators': [ credentials.to_login_info() ],
139 142
        'homepath': getattr(settings, 'SITE_HOME_PATH', '/'),
140
        'auth_checker': os.path.join(settings.STATIC_ROOT, getattr(settings, 'SITE_AUTH_CHECKER'))
143
        'auth_checker': os.path.join(site_static_root, site_auth_checker)
141 144
    }
142 145
    logger.debug(login_info)
143
    result = exec_phantom(login_info) 
146
    result = exec_phantom(login_info)
144 147
    logger.debug(result)
145 148
    if result.get('result') != 'ok':
146 149
        logger.debug('authentication failed')
......
158 161
    template = Template('<script type="text/javascript">\
159 162
                window.top.location = "{{url}}";</script>')
160 163
    context = RequestContext(request, {'url': url})
161
    response = HttpResponse(template.render(context)) 
164
    response = HttpResponse(template.render(context))
162 165
    if result.get('headers',None):
163 166
        response.cookies = cookie_builder(result.get('headers'))
164 167

  
165 168
    return response
166

  

Formats disponibles : Unified diff