예제 #1
0
    def post_process_request(self, req, template, data, content_type):
        # Some ticket views do not actually load the data in this way
        # e.g. action=history or action=diff
        if not data or not data.has_key('fields'):
            return template, data, content_type

        newticket = req.path_info.startswith('/newticket')
        if req.path_info.startswith('/ticket/') or newticket:
            for field in data['fields']:
                if 'client' == field['name']:
                    field['options'] = []
                    for client in Client.select(self.env):
                        field['options'].append(client.name)
                    if not field['options']:
                        # Don't show field if there are no clients
                        data['fields'].remove(field)
                    else:
                        field['type'] = 'select'
                        if newticket:
                            default_client = self.config.get('ticket', 'default_client')
                            if default_client:
                                data['ticket']['client'] = default_client
                    break;
        elif req.path_info.startswith('/query'):
            if data['fields'].has_key('client'):
                data['fields']['client']['type'] = 'select'
                data['fields']['client']['options'] = []
                for client in Client.select(self.env):
                    data['fields']['client']['options'].append(client.name)
        return template, data, content_type
예제 #2
0
    def post_process_request(self, req, template, data, content_type):
        # Some ticket views do not actually load the data in this way
        # e.g. action=history or action=diff
        if not data or not data.has_key('fields'):
            return template, data, content_type

        newticket = req.path_info.startswith('/newticket')
        if req.path_info.startswith('/ticket/') or newticket:
            for field in data['fields']:
                if 'client' == field['name']:
                    field['options'] = []
                    for client in Client.select(self.env):
                        field['options'].append(client.name)
                    if not field['options']:
                        # Don't show field if there are no clients
                        data['fields'].remove(field)
                    else:
                        field['type'] = 'select'
                        if newticket:
                            default_client = self.config.get(
                                'ticket', 'default_client')
                            if default_client:
                                data['ticket']['client'] = default_client
                    break
        elif req.path_info.startswith('/query'):
            if data['fields'].has_key('client'):
                data['fields']['client']['type'] = 'select'
                data['fields']['client']['options'] = []
                for client in Client.select(self.env):
                    data['fields']['client']['options'].append(client.name)
        return template, data, content_type
예제 #3
0
    def filter_stream(self, req, method, filename, stream, data):
        # Add Stylesheet here, so that the ticket page gets it too :)
        add_stylesheet(req, "clients/clients.css")

        newticket = req.path_info.startswith('/newticket')
        if req.path_info.startswith('/ticket/') or newticket:
            setdefaultrate = ''
            if newticket:
              setdefaultrate = "$('#field-client').trigger('change');"
            
            script = StringIO()
            script.write("""
              $(document).ready(function() {
                $('#field-client').change(function() {
                  """);
            script.write('var clientrates = new Array();')
            for client in Client.select(self.env):
                script.write('clientrates["%s"] = %s;' % (client.name, client.default_rate or '""'))
            script.write("""
                  try { $('#field-clientrate').attr('value', clientrates[this.options[this.selectedIndex].value]); }
                  catch (er) { }
                });
                %s
             });""" % setdefaultrate);
            stream |= Transformer('.//head').append(tag.script(script.getvalue(), type_='text/javascript'))
        return stream
예제 #4
0
    def filter_stream(self, req, method, filename, stream, data):
        # Add Stylesheet here, so that the ticket page gets it too :)
        add_stylesheet(req, "clients/clients.css")

        newticket = req.path_info.startswith('/newticket')
        if req.path_info.startswith('/ticket/') or newticket:
            setdefaultrate = ''
            if newticket:
                setdefaultrate = "$('#field-client').trigger('change');"

            script = StringIO()
            script.write("""
              $(document).ready(function() {
                $('#field-client').change(function() {
                  """)
            script.write('var clientrates = new Array();')
            for client in Client.select(self.env):
                script.write('clientrates["%s"] = %s;' %
                             (client.name, client.default_rate or '""'))
            script.write("""
                  try { $('#field-clientrate').attr('value', clientrates[this.options[this.selectedIndex].value]); }
                  catch (er) { }
                });
                %s
             });""" % setdefaultrate)
            stream |= Transformer('.//head').append(
                tag.script(script.getvalue(), type_='text/javascript'))
        return stream
예제 #5
0
    def _save_to_disk(self, clients):
        temp_table_name = self.table_name + '.tmp'
        with open(temp_table_name, mode='w') as f:
            writer = csv.DictWriter(f, fieldnames=Client.schema())
            writer.writerows(clients)

        os.remove(self.table_name)
        os.rename(temp_table_name, self.table_name)
예제 #6
0
파일: commands.py 프로젝트: zilverjk/python
def update(ctx, client_uid):
    """Update client"""
    client_service = ClientService(ctx.obj['clients_table'])

    client_list = client_service.list_clients()

    client = [client for client in client_list if client['uid'] == client_uid]

    if client:
        client = _update_client_flow(Client(**client[0]))
        client_service.update_client(client)

        click.echo('Client updated')
    else:
        click.echo('Client not found')
예제 #7
0
파일: commands.py 프로젝트: zilverjk/python
def create(ctx, name, company, email, position):
    """Creates a new client"""
    client = Client(name, company, email, position)
    client_service = ClientService(ctx.obj['clients_table'])

    client_service.create_client(client)
예제 #8
0
 def do_delete(db):
     for name in sel:
         clnt = Client(self.env, name, db=db)
         clnt.delete(db=db)
예제 #9
0
    def _render_admin_panel(self, req, cat, page, client):
        # Detail view?
        if client:
            clnt = Client(self.env, client)
            events = ClientEvent.select(self.env, client)
            if req.method == 'POST':
                if req.args.get('save'):
                    clnt.name = req.args.get('name')
                    clnt.description = req.args.get('description')
                    clnt.changes_list = req.args.get('changes_list')
                    clnt.changes_period = req.args.get('changes_period')
                    clnt.summary_list = req.args.get('summary_list')
                    clnt.summary_period = req.args.get('summary_period')
                    clnt.default_rate = req.args.get('default_rate')
                    clnt.currency = req.args.get('currency')
                    clnt.update()

                    @self.env.with_transaction()
                    def do_client_event_updates(db):
                        for clev in events:
                            for option in clev.summary_client_options:
                                arg = 'summary-option-%s-%s' % (
                                    clev.md5,
                                    clev.summary_client_options[option]['md5'])
                                clev.summary_client_options[option][
                                    'value'] = req.args.get(arg)
                            for option in clev.action_client_options:
                                arg = 'action-option-%s-%s' % (
                                    clev.md5,
                                    clev.action_client_options[option]['md5'])
                                clev.action_client_options[option][
                                    'value'] = req.args.get(arg)
                            clev.update_options(client, db)

                    req.redirect(req.href.admin(cat, page))
                elif req.args.get('cancel'):
                    req.redirect(req.href.admin(cat, page))

            add_script(req, 'common/js/wikitoolbar.js')
            data = {'view': 'detail', 'client': clnt, 'events': events}

        else:
            if req.method == 'POST':
                # Add Client
                if req.args.get('add') and req.args.get('name'):
                    clnt = Client(self.env)
                    clnt.name = req.args.get('name')
                    clnt.insert()
                    req.redirect(req.href.admin(cat, page))

                # Remove clients
                elif req.args.get('remove') and req.args.get('sel'):
                    sel = req.args.get('sel')
                    sel = isinstance(sel, list) and sel or [sel]
                    if not sel:
                        raise TracError('No client selected')

                    @self.env.with_transaction()
                    def do_delete(db):
                        for name in sel:
                            clnt = Client(self.env, name, db=db)
                            clnt.delete(db=db)

                    req.redirect(req.href.admin(cat, page))

                # Set default client
                elif req.args.get('apply'):
                    if req.args.get('default'):
                        name = req.args.get('default')
                        self.log.info('Setting default client to %s', name)
                        self.config.set('ticket', 'default_client', name)
                        self.config.save()
                        req.redirect(req.href.admin(cat, page))

            default = self.config.get('ticket', 'default_client')
            data = {
                'view': 'list',
                'clients': Client.select(self.env),
                'default': default
            }

        return 'admin_clients.html', data
예제 #10
0
    def list_clients(self):
        with open(self.table_name, mode='r') as f:
            reader = csv.DictReader(f, fieldnames=Client.schema())

            return list(reader)
예제 #11
0
 def create_client(self, client):
     with open(self.table_name, mode='a') as f:
         writer = csv.DictWriter(f, fieldnames=Client.schema())
         writer.writerow(client.to_dict())
예제 #12
0
파일: admin.py 프로젝트: nyuhuhuu/trachacks
 def do_delete(db):
     for name in sel:
         clnt = Client(self.env, name, db=db)
         clnt.delete(db=db)
예제 #13
0
파일: admin.py 프로젝트: nyuhuhuu/trachacks
    def _render_admin_panel(self, req, cat, page, client):
        # Detail view?
        if client:
            clnt = Client(self.env, client)
            events = ClientEvent.select(self.env, client)
            if req.method == 'POST':
                if req.args.get('save'):
                    clnt.name = req.args.get('name')
                    clnt.description = req.args.get('description')
                    clnt.changes_list = req.args.get('changes_list')
                    clnt.changes_period = req.args.get('changes_period')
                    clnt.summary_list = req.args.get('summary_list')
                    clnt.summary_period = req.args.get('summary_period')
                    clnt.default_rate = req.args.get('default_rate')
                    clnt.currency = req.args.get('currency')
                    clnt.update()

                    @self.env.with_transaction()
                    def do_client_event_updates(db):
                      for clev in events:
                        for option in clev.summary_client_options:
                          arg = 'summary-option-%s-%s' % (clev.md5, clev.summary_client_options[option]['md5'])
                          clev.summary_client_options[option]['value'] = req.args.get(arg)
                        for option in clev.action_client_options:
                          arg = 'action-option-%s-%s' % (clev.md5, clev.action_client_options[option]['md5'])
                          clev.action_client_options[option]['value'] = req.args.get(arg)
                        clev.update_options(client, db)

                    req.redirect(req.href.admin(cat, page))
                elif req.args.get('cancel'):
                    req.redirect(req.href.admin(cat, page))

            add_script(req, 'common/js/wikitoolbar.js')
            data = {'view': 'detail', 'client': clnt, 'events': events}

        else:
            if req.method == 'POST':
                # Add Client
                if req.args.get('add') and req.args.get('name'):
                    clnt = Client(self.env)
                    clnt.name = req.args.get('name')
                    clnt.insert()
                    req.redirect(req.href.admin(cat, page))

                # Remove clients
                elif req.args.get('remove') and req.args.get('sel'):
                    sel = req.args.get('sel')
                    sel = isinstance(sel, list) and sel or [sel]
                    if not sel:
                        raise TracError('No client selected')

                    @self.env.with_transaction()
                    def do_delete(db):
                        for name in sel:
                            clnt = Client(self.env, name, db=db)
                            clnt.delete(db=db)
                    req.redirect(req.href.admin(cat, page))

                # Set default client
                elif req.args.get('apply'):
                    if req.args.get('default'):
                        name = req.args.get('default')
                        self.log.info('Setting default client to %s', name)
                        self.config.set('ticket', 'default_client', name)
                        self.config.save()
                        req.redirect(req.href.admin(cat, page))

            default = self.config.get('ticket', 'default_client')
            data = {'view': 'list',
                    'clients': Client.select(self.env),
                    'default': default}

        return 'admin_clients.html', data