Ejemplo n.º 1
0
 def render(self):
     clients = self.context.__parent__
     if not self.context.projects:
         del clients[self.context.id]
         self.flash(_(u'Client deleted.'), type=u'message')
         return self.redirect(self.url(clients))
     else:
         self.flash(_(u'This client cannot be deleted because it has '
                       'projects associated'), type=u'message')
         return self.redirect(self.url(self.context))
Ejemplo n.º 2
0
 def handle_login(self, **data):
     authenticated = not IUnauthenticatedPrincipal.providedBy(
         self.request.principal,
     )
     if authenticated:
         self.redirect(self.request.form.get('camefrom',
                                             self.url(grok.getSite())))
         self.flash(_(u'You are logged in.'), type=u'message')
     else:
         self.status = _(u'Login failed.')
         self.errors += (Invalid(u'Invalid username and/or password'),)
         self.form_reset = False
Ejemplo n.º 3
0
    def render(self):
        if not IUnauthenticatedPrincipal.providedBy(self.request.principal):
            auth = component.getUtility(IAuthentication)
            ILogout(auth).logout(self.request)

        self.flash(_(u'You are now logged out'), type=u'message')
        return self.redirect(self.application_url())
Ejemplo n.º 4
0
    def render(self):
        userfolder = self.context.__parent__
        users = component.getUtility(IAuthenticatorPlugin, 'users')
        users.removeUser(self.context.id)

        self.flash(_(u'User deleted.'), type=u'message')
        return self.redirect(self.url(userfolder))
Ejemplo n.º 5
0
 def edit(self, **data):
     password = self.request.form.get('form.password')
     if password:
         self.context.setPassword(password)
     self.context.real_name = self.request.form.get('form.real_name')
     self.flash(_(u'Changes saved.'), type=u'message')
     return self.redirect(self.url(self.context.__parent__))
Ejemplo n.º 6
0
    def __call__(self, context=None):
        site = grok.getSite()
        users = site['users'].values()
        users = [SimpleTerm(u.id, u.id, u.real_name) for u in users]

        all_users = (u'all', u'all', _(u'All users'))
        users.insert(0, SimpleTerm(*all_users))

        return SimpleVocabulary(users)
Ejemplo n.º 7
0
    def render(self):
        users = getUtility(IAuthenticatorPlugin, 'users')
        intids = getUtility(IIntIds, name='intids')

        user = users.getAccount(self.request.principal.id)
        intid = intids.getId(self.context)

        starred_tasks = ifaces.IStarredTasks(user)

        if intid in starred_tasks.getStarredTasks():
            starred_tasks.removeStarredTask(intid)
            msg = _("You've removed the star from the task")
        else:
            starred_tasks.addStarredTask(intid)
            msg = _("You've marked the task with a star")

        self.flash(msg, type=u'message')
        url = self.request.get('camefrom', self.url(self.context))
        return self.redirect(url)
Ejemplo n.º 8
0
 def matchingPasswords(form):
     """Check that the password and the password confirmation fields
     match.
     """
     # XXX: we need to find out why form.password turns to be
     # something of type 'object' when we leave the field empty
     # in the edit form.
     if type(form.password) != object and \
        form.confirm_password != form.password:
         raise Invalid(_('Passwords does not match'))
Ejemplo n.º 9
0
    def render(self):
        project_container = self.context.__parent__

        # Delete the contained tasks from the user starred lists
        for task in self.context.values():
            if ifaces.ITask.providedBy(task):
                task.deleteFromStarredLists()

        del project_container[self.context.id]
        self.flash(_(u'Project deleted.'), type=u'message')
        return self.redirect(self.url(project_container))
Ejemplo n.º 10
0
    def __call__(self, context=None):
        site = grok.getSite()
        path = getUtility(IObjectPath).path

        projects = [i for i in site['projects'].values() if \
                    ifaces.IProject.providedBy(i)]
        title = lambda p: '%s (%s)' % (p.title, p.client.to_object.title)

        projects = [SimpleTerm(path(p), path(p), title(p)) for p in projects]

        all_projects = (u'all', u'all', _(u'All projects'))
        projects.insert(0, SimpleTerm(*all_projects))

        return SimpleVocabulary(projects)
Ejemplo n.º 11
0
    def add(self, **data):
        client = Client()
        client.creator = self.request.principal.title
        client.creation_date = datetime.datetime.now()
        client.modification_date = datetime.datetime.now()
        self.applyData(client, **data)

        id = str(self.context.next_id)
        client.id = id
        self.context.next_id = self.context.next_id + 1
        self.context[id] = client

        self.flash(_(u'Client added.'), type=u'message')
        return self.redirect(self.url(self.context))
Ejemplo n.º 12
0
    def add(self, **data):
        """Add a project"""
        project = Project()
        project.creator = self.request.principal.title
        project.creation_date = datetime.datetime.now()
        project.modification_date = datetime.datetime.now()
        self.applyData(project, **data)

        title = data['title']
        suffix = 1
        id = normalize(title)
        while id in self.context:
            title += str(suffix)
            suffix += 1
            id = normalize(title)

        project.id = id
        self.context[id] = project
        self.flash(_(u'Project added.'), type=u'message')
        return self.redirect(self.url(self.context[id]))
Ejemplo n.º 13
0
    def add(self, **data):
        """Add a log inside the current task"""
        log = Log()
        log.creator = self.request.principal.title
        log.creation_date = datetime.datetime.now()
        log.modification_date = datetime.datetime.now()
        log.user = self.request.principal.id
        self.applyData(log, **data)

        id = str(self.context.next_id)
        log.id = id
        self.context.next_id = self.context.next_id + 1
        self.context[id] = log
        if data['remaining'] is not None:
            if data['remaining'] == 0:
                self.context.status = u'Completed'
            self.context.remaining = data['remaining']

        self.flash(_(u'Log added.'), type=u'message')
        return self.redirect(self.url(self.context))
Ejemplo n.º 14
0
    def add(self, **data):
        """Add a task inside the current project"""
        task = Task()
        task.creator = self.request.principal.title
        task.creation_date = datetime.datetime.now()
        task.modification_date = datetime.datetime.now()
        task.remaining = data['estimate']
        self.applyData(task, **data)

        title = data['title']
        suffix = 1
        id = normalize(title)
        while id in self.context:
            title += str(suffix)
            suffix += 1
            id = normalize(title)

        task.id = id
        self.context[id] = task
        self.flash(_(u'Task added.'), type=u'message')
        return self.redirect(self.url(self.context))
Ejemplo n.º 15
0
 def render(self):
     project = self.context.__parent__
     self.context.deleteFromStarredLists()
     del project[self.context.id]
     self.flash(_(u'Task deleted.'), type=u'message')
     return self.redirect(self.url(project))
Ejemplo n.º 16
0
 def handle_add(self, **data):
     users = component.getUtility(IAuthenticatorPlugin, 'users')
     users.addUser(data['id'], data['password'], data['real_name'])
     self.flash(_(u'User added.'), type=u'message')
     self.redirect(self.url(self.context))
Ejemplo n.º 17
0
 def startBeforeEnd(task):
     """Check that the start date is prior to the end date"""
     if task.end_date and task.start_date:
         if task.end_date < task.start_date:
             raise Invalid(_('Start date must preceed end date'))
Ejemplo n.º 18
0
 def render(self):
     task = self.context.__parent__
     del task[self.context.id]
     self.flash(_(u'Log deleted.'), type=u'message')
     return self.redirect(self.url(task))
Ejemplo n.º 19
0
 def edit(self, **data):
     """Make the changes persistent"""
     self.context.modification_date = datetime.datetime.now()
     self.applyData(self.context, **data)
     self.flash(_(u'Changes saved.'), type=u'message')
     return self.redirect(self.url(self.context.__parent__))
Ejemplo n.º 20
0
 def startBeforeEnd(project):
     """Check that the start date is prior to the end date"""
     if project.end_date and project.start_date:
         if project.end_date < project.start_date:
             raise Invalid(_('Start date must preceed end date'))
Ejemplo n.º 21
0
 def edit(self, **data):
     """Update the task attributes"""
     self.context.modification_date = datetime.datetime.now()
     self.applyData(self.context, **data)
     self.flash(_(u'Changes saved.'), type=u'message')
     return self.redirect(self.url(self.context))
Ejemplo n.º 22
0
 def validUsername(form):
     """Check that the user name is valid"""
     if not re.compile('^[a-z0-9]+$').match(form.id):
         raise Invalid(_('Invalid user name, only characters in [a-z0-9] '
                         'are allowed'))