source: arma2/idCentral/idcentral/idcentral.py @ 03d5364592543369d35b1ad6fcae67be27c5c4d9

Revision 03d5364592543369d35b1ad6fcae67be27c5c4d9, 5.1 KB checked in by TiN <tin@…>, 3 years ago (diff)

PluginTrac? => daemon_xmlrpc => steroides, conectados

  • Property mode set to 100644
Line 
1#!/usr/bin/env python
2#-*- coding: utf-8 -*-
3#############################################################################
4# idcentral plugin
5# Copyright (C) by USLA Team <-> devel-team usla org ar 2010
6#
7# new_project is free software: you can redistribute it and/or modify it
8# under the terms of the GNU General Public License as published by the
9# Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# idcentral.py is distributed in the hope that it will be useful, but
13# WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15# See the GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program.  If not, see <http://www.gnu.org/licenses/>.
19#############################################################################
20
21import re
22import xmlrpclib
23
24from genshi.builder import tag
25
26from trac.core import Component, implements
27from trac.web import IRequestHandler
28from trac.web.chrome import ITemplateProvider, add_stylesheet
29from trac.perm import IPermissionRequestor, PermissionSystem
30from trac.config import Option, IntOption
31from trac.util.datefmt import utc
32
33class IdCentralPlugin(Component):
34    implements(IRequestHandler, ITemplateProvider, IPermissionRequestor)
35
36    project_id_validator = re.compile("[a-z]+[_\-0-9]*[a-z]*$")
37    sug_project_name = Option('NewProject', 'sug_project_name',
38            doc=u'Sugerencias para el nombre del proyecto')
39    sug_project_id = Option('NewProject', 'sug_project_id',
40            doc=u'Sugerencias para el Id del proyecto')
41    intro = Option('NewProject', 'intro',
42            doc=u'Introducción del formulario de nuevo Proyecto')
43    script = Option('NewProject', 'script',
44            doc=u'Script báshico al que llama luego de parsear los datos '\
45                    u'ingresados, el script debe aceptar los siguientes '\
46                    u'parámetros repo_type project_id titulo owner')
47    max_cant_proj = IntOption('NewProject', 'width', 5,
48                    """Cantidad de proyectos por persona""")
49    project_list_cache = []
50    clear_cache = True
51    repo_type_supported = ['svn', 'hg', 'bzr', 'git']
52    daemon_idCentral = xmlrpclib.ServerProxy("http://localhost:8008", allow_none=1)
53    texcha = ""
54
55    # IRequestHandler methods
56    def match_request(self, req):
57        return re.match(r'/(nuevo_usuario)(?:_trac)?(?:/.*)?$', req.path_info)
58
59    def process_request(self, req):
60        add_stylesheet(req, 'nuldap/css/password.css')
61        self.data = {'intro': self.intro}
62        action = req.args.get('action')
63        format = req.args.get('format')
64        path_info = req.path_info[1:]
65        if req.method == 'GET':
66            self.data['texcha'] = self.texcha = self.daemon_idCentral.getTexcha()
67        elif req.method == 'POST' and action == 'newuser':
68            self._parser(req)
69                #self.create_project()
70                #return 'project_created.html', self.data, None
71            #add_stylesheet(req, 'common/css/trac.css')
72        return 'nuevo_usuario.html', self.data, None
73
74    def _parser(self, req):
75        u"""Método encargado de analizar las entradas del usuario y determinar
76        su validez. Le aclara al usuario lo que ha ingresado erróneamente"""
77        valid = True
78        self.data['name_lastname'] = req.args.get('name_lastname')
79        self.data['user_put'] = req.args.get('user_put').lower()
80        self.data['lug'] = req.args.get('lug')
81        self.data[self.data['lug']] = {"selected" : "True"}
82        self.data['passwd'] = req.args.get('passwd')
83        self.data['confirm_passwd'] = req.args.get('confirm_passwd')
84        self.data['texcha_put'] = req.args.get('texcha_put')
85        if self.data['passwd'] != self.data['confirm_passwd']:
86            self.data['error_passwd'] = u'Las contraseñas no coinciden'
87            valid = False
88        if not self.daemon_idCentral.validateTexcha(self.texcha, self.data['texcha_put']):
89            self.data['error_texcha'] = u'Tu respuesta al texto es incorrecta'
90            self.data['texcha'] = texcha = self.daemon_idCentral.getTexcha()
91            valid = False
92        return valid
93
94    # ITemplateProvider methods
95    # Used to add the plugin's templates and htdocs
96    def get_templates_dirs(self):
97        from pkg_resources import resource_filename
98        return [resource_filename(__name__, 'templates')]
99
100    def get_htdocs_dirs(self):
101        """Return a list of directories with static resources (such as style
102        sheets, images, etc.)
103
104        Each item in the list must be a `(prefix, abspath)` tuple. The
105        `prefix` part defines the path in the URL that requests to these
106        resources are prefixed with.
107
108        The `abspath` is the absolute path to the directory containing the
109        resources on the local file system.
110        """
111        from pkg_resources import resource_filename
112        return [('common', resource_filename('trac', 'htdocs')),
113                ('nuldap', resource_filename(__name__, 'htdocs'))]
114
115
116    # IPermissionRequestor methods
117    def get_permission_actions(self):
118        yield 'CREATE_PROJECT'
Note: See TracBrowser for help on using the repository browser.