Projet

Général

Profil

« Précédent | Suivant » 

Révision dd9903d6

Ajouté par Frédéric Péters il y a plus de 7 ans

update to "new" tracking code mechanism (#13875)

This now requires the theme to declare the "include-tracking-code-form"
keyword.

Voir les différences:

extra/modules/root.py
767 767
            'accessibility', 'contact', 'help',
768 768
            'myspace', 'services', 'agenda', 'categories', 'user',
769 769
            ('tmp-upload', 'tmp_upload'), 'json', '__version__',
770
            'themes', 'pages', 'payment', 'invoices', 'accesscode', 'roles',
770
            'themes', 'pages', 'payment', 'invoices', 'roles',
771 771
            'api', 'code', 'fargo', 'tryauth', 'auth', 'preview',
772 772
            ('reload-top', 'reload_top'), 'static',
773 773
            ('i18n.js', 'i18n_js')]
......
1094 1094
        r = TemplateIO(html=True)
1095 1095
        root_url = get_publisher().get_root_url()
1096 1096

  
1097
        if self.has_anonymous_access_codes():
1098
            r += htmltext('<form id="follow-form" action="%saccesscode">') % root_url
1099
            r += htmltext('<h3>%s</h3>') % _('Tracking')
1100
            r += htmltext('<label>%s</label> ') % _('Code:')
1101
            r += htmltext('<input name="code" size="10"/>')
1097
        if self.has_anonymous_access_codes() and path == [''] and (
1098
                'include-tracking-code-form' in get_response().filter.get('keywords', [])):
1099
            r += htmltext('<form id="follow-form" action="%scode/load">') % root_url
1100
            r += htmltext('<h3>%s</h3>') % _('Tracking code')
1101
            r += htmltext('<input size="12" name="code" placeholder="%s"/>') % _('ex: RPQDFVCD')
1102
            r += htmltext('<input type="submit" value="%s"/>') % _('Load')
1102 1103
            r += htmltext('</form>')
1103 1104

  
1104 1105
        r += self.links()
......
1143 1144
        return None
1144 1145

  
1145 1146
    def has_anonymous_access_codes(self):
1146
        for workflow in Workflow.select():
1147
            for wfstatus in workflow.possible_status:
1148
                for wfitem in wfstatus.items:
1149
                    if wfitem.key == 'create-anonymous-access-code':
1150
                        return True
1151
        return False
1152

  
1153
    def accesscode(self):
1154
        code = get_request().form.get('code')
1155
        if not code:
1156
            return redirect(get_publisher().get_root_url())
1157
        try:
1158
            token = Token.get(code)
1159
        except KeyError:
1160
            return redirect(get_publisher().get_root_url())
1161
        if token.type != 'anonymous-access-code':
1162
            return redirect(get_publisher().get_root_url())
1163
        formdef_urlname, formdata_id = token.formdata_reference
1164
        try:
1165
            formdata = FormDef.get_by_urlname(formdef_urlname).data_class().get(formdata_id)
1166
        except KeyError:
1167
            return redirect(get_publisher().get_root_url())
1168
        session = get_session()
1169
        if not hasattr(session, '_wf_anonymous_access_authorized'):
1170
            session._wf_anonymous_access_authorized = []
1171
        session._wf_anonymous_access_authorized.append(formdata.get_url())
1172
        return redirect(formdata.get_url() + 'access/')
1147
        return any((x for x in FormDef.select() if x.enable_tracking_codes))
1173 1148

  
1174 1149
    def links(self):
1175 1150
        links = Link.select()

Formats disponibles : Unified diff