1
0
forked from ScoDoc/ScoDoc
ScoDoc-Front/app/scodoc/debug.py

143 lines
3.8 KiB
Python

# -*- mode: python -*-
# -*- coding: utf-8 -*-
"""Configuration pour debugguer en mode console
Lancer ScoDoc ainsi: (comme root)
/opt/scodoc/bin/zopectl debug
Puis
from debug import *
context = go(app)
# ou
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 = sco_formsemestre.do_formsemestre_list.formsemestre_list(context)
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 = sco_core.get_notes_cache(context).get_NotesTable(context, formsemestre_id)
"""
from __future__ import print_function
import pdb # pylint: disable=unused-import
import pprint
import app.scodoc.notesdb as ndb # pylint: disable=unused-import
from app.scodoc.notesdb import * # pylint: disable=wildcard-import,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=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
# Prend le premier departement comme context
def go(app, n=0, verbose=True):
context = app.ScoDoc.objectValues("Folder")[n].Scolarite
if verbose:
print("context in dept ", scu.get_dept_id())
return context
def go_dept(app, dept, verbose=True):
objs = app.ScoDoc.objectValues("Folder")
for o in objs:
try:
context = o.Scolarite
except AttributeError:
# ignore other folders, like old "icons"
continue
if scu.get_dept_id() == dept:
if verbose:
print("context in dept ", scu.get_dept_id())
return context
raise ValueError("dep %s not found" % dept)
class FakeUser(object):
def __init__(self, name):
self.name = name
def __str__(self):
return self.name
def has_permission(self, op, dept=None):
return True
def has_role(self, role):
return True
class DummyResponse(object):
"""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(object):
"""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