MonScoDocEssai/app/scodoc/debug.py

131 lines
3.0 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:
sems = context.Notes.formsemestre_list()
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:
nt = context.Notes._getNotesCache().get_NotesTable(context.Notes, formsemestre_id)
"""
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
2021-06-17 00:08:37 +02:00
import app.scodoc.notesdb as ndb
from app.scodoc.notesdb import * # pylint: disable=unused-wildcard-import
from app.scodoc.notes_log import log
import app.scodoc.sco_utils as scu
from app.scodoc.sco_utils import * # pylint: disable=unused-wildcard-import
2020-09-26 16:19:37 +02:00
from gen_tables import GenTable
import sco_archives
import sco_groups
import sco_evaluations
import sco_formsemestre
import sco_formsemestre_edit
import sco_compute_moy
import sco_parcours_dut
import sco_codes_parcours
import sco_bulletins
import sco_excel
import sco_formsemestre_status
import sco_bulletins_xml
# 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-15 15:38:38 +02:00
def has_permission(self, op, dept):
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"
2020-12-26 00:11:55 +01:00
self.REMOTE_HOST = "localhost"
2020-09-26 16:19:37 +02:00
self.REMOTE_ADDR = "127.0.0.1"
self.HTTP_REFERER = ""
self.REQUEST_METHOD = "get"
self.QUERY_STRING = ""
REQUEST = DummyRequest()
# handful shorcut
pp = pprint.pprint