ScoDoc/app/scodoc/debug.py

144 lines
3.8 KiB
Python
Raw Normal View History

2020-09-26 16:19:37 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
"""Configuration pour debugguer en mode console
Lancer ScoDoc ainsi: (comme root)
2021-06-17 00:08:37 +02:00
/opt/scodoc/bin/zopectl debug
2020-09-26 16:19:37 +02:00
Puis
from debug import *
2021-06-17 00:08:37 +02:00
context = go(app)
# ou
2020-09-26 16:19:37 +02:00
context = go_dept(app, 'CJ')
authuser = app.acl_users.getUserById('admin')
# ou app.ScoDoc.acl_users.getUserById('toto') pour un utilisateur scodoc
authuser = authuser.__of__(app.acl_users)
Exemple:
2021-06-21 11:22:55 +02:00
sems = sco_formsemestre.do_formsemestre_list.formsemestre_list(context)
2020-09-26 16:19:37 +02:00
formsemestre_id = sems[0]['formsemestre_id']
# Affiche tous les semestres:
for sem in sems:
print sem['formsemestre_id'], sem['titre_num']
# Recupere la table de notes:
2021-06-21 11:22:55 +02:00
nt = sco_core.get_notes_cache(context).get_NotesTable(context, formsemestre_id)
2020-09-26 16:19:37 +02:00
"""
2021-07-09 13:59:01 +02:00
from __future__ import absolute_import
from __future__ import print_function
2021-06-17 00:08:37 +02:00
import pdb # pylint: disable=unused-import
2021-02-03 22:00:41 +01:00
import pprint
2020-12-26 00:11:55 +01:00
import app.scodoc.notesdb as ndb # pylint: disable=unused-import
from app.scodoc.notesdb import * # pylint: disable=wildcard-import,unused-wildcard-import
2021-06-17 00:08:37 +02:00
from app.scodoc.notes_log import log
import app.scodoc.sco_utils as scu
from app.scodoc.sco_utils import * # pylint: disable=wildcard-import, unused-wildcard-import
from app.scodoc.gen_tables import GenTable
from app.scodoc import html_sco_header
from app.scodoc import sco_archives
from app.scodoc import sco_bulletins
from app.scodoc import sco_bulletins_xml
from app.scodoc import sco_codes_parcours
from app.scodoc import sco_compute_moy
from app.scodoc import sco_core
from app.scodoc import sco_edit_matiere
from app.scodoc import sco_edit_module
from app.scodoc import sco_edit_ue
from app.scodoc import sco_excel
from app.scodoc import sco_formations
from app.scodoc import sco_formsemestre
from app.scodoc import sco_formsemestre_edit
from app.scodoc import sco_formsemestre_status
from app.scodoc import sco_formsemestre_validation
from app.scodoc import sco_groups
from app.scodoc import sco_moduleimpl
from app.scodoc import sco_news
from app.scodoc import sco_parcours_dut
from app.scodoc import sco_permissions
from app.scodoc import sco_preferences
from app.scodoc import sco_tag_module
from app.scodoc import sco_etud
2020-09-26 16:19:37 +02:00
# Prend le premier departement comme context
2021-04-23 10:24:45 +02:00
def go(app, n=0, verbose=True):
2020-09-26 16:19:37 +02:00
context = app.ScoDoc.objectValues("Folder")[n].Scolarite
2021-04-23 10:24:45 +02:00
if verbose:
2021-06-15 12:34:33 +02:00
print("context in dept ", scu.get_dept_id())
2020-09-26 16:19:37 +02:00
return context
2021-04-23 10:24:45 +02:00
def go_dept(app, dept, verbose=True):
2020-09-26 16:19:37 +02:00
objs = app.ScoDoc.objectValues("Folder")
for o in objs:
try:
context = o.Scolarite
except AttributeError:
# ignore other folders, like old "icons"
continue
2021-06-15 12:34:33 +02:00
if scu.get_dept_id() == dept:
2021-04-23 10:24:45 +02:00
if verbose:
2021-06-15 12:34:33 +02:00
print("context in dept ", scu.get_dept_id())
2020-09-26 16:19:37 +02:00
return context
raise ValueError("dep %s not found" % dept)
class FakeUser:
def __init__(self, name):
self.name = name
def __str__(self):
return self.name
2021-06-24 10:59:03 +02:00
def has_permission(self, op, dept=None):
2020-09-26 16:19:37 +02:00
return True
2020-12-26 00:11:55 +01:00
def has_role(self, role):
return True
2020-09-26 16:19:37 +02:00
class DummyResponse:
"""Emulation vide de Reponse http Zope"""
def __init__(self):
self.header = {}
self.redirected = ""
def setHeader(self, name, value):
self.header[name] = value
def redirect(self, url):
self.redirected = url
class DummyRequest:
"""Emulation vide de Request Zope"""
def __init__(self):
self.RESPONSE = DummyResponse()
self.AUTHENTICATED_USER = FakeUser("admin")
self.form = {}
self.URL = "http://scodoc/"
self.URL0 = self.URL
self.BASE0 = "localhost"
self.REMOTE_ADDR = "127.0.0.1"
self.HTTP_REFERER = ""
self.REQUEST_METHOD = "get"
self.QUERY_STRING = ""
REQUEST = DummyRequest()
# handful shorcut
pp = pprint.pprint