Exemple #1
0
 def tags(self, **kw):
     pname = request.environ['PATH_INFO'].split('/')[1]
     userid = request.identity['repoze.who.userid']
     alltags = [tag for tag in DBSession.query(Tags).order_by('name').all()]
     if kw:
         try:
             usun = kw['button1']
         except Exception:
             usun = None
         if usun:
             try:
                 if isinstance(kw['deltags'], basestring):
                     tagi = [DBSession.query(Tags).get(int(kw['deltags']))]
                 else:
                     tagi = [
                         DBSession.query(Tags).get(int(id))
                         for id in kw['deltags']
                     ]
             except Exception:
                 tagi = None
             if tagi:
                 for tag in tagi:
                     for compound in DBSession.query(Compound).all():
                         if tag in compound.tags:
                             compound.tags.remove(tag)
                             history = History()
                             history.user = userid
                             history.status = u'Usuwanie tagu'
                             history.changes = u'Usunieto tag %s ' % tag.name
                             compound.history += [history]
                             DBSession.add(history)
                     DBSession.delete(tag)
                     DBSession.flush()
                 flash(l_(u'Task completed successfully'))
                 alltags = [
                     tag for tag in DBSession.query(Tags).order_by(
                         'name').all()
                 ]
         else:
             try:
                 if kw['addtag'] != '':
                     tagname = kw['addtag']
                 else:
                     tagname = None
             except Exception:
                 tagname = None
             if tagname:
                 tag = Tags()
                 tag.name = tagname
                 flash(l_(u'Task completed successfully'))
                 DBSession.add(tag)
                 DBSession.flush()
                 alltags = [
                     tg
                     for tg in DBSession.query(Tags).order_by('name').all()
                 ]
             else:
                 flash(l_(u'Name required'), 'warning')
     return dict(alltags=alltags, page='kierownik', pname=pname)
Exemple #2
0
 def tags(self, **kw):
     pname = request.environ['PATH_INFO'].split('/')[1]
     userid = request.identity['repoze.who.userid']
     alltags =[tag for tag in DBSession.query(Tags).order_by('name').all() ]
     if kw:
         try:
             usun = kw['button1']
         except Exception:
             usun = None
         if usun:
             try:
                 if isinstance(kw['deltags'], basestring):
                     tagi = [DBSession.query( Tags ).get(int(kw['deltags']))]
                 else:
                     tagi = [DBSession.query( Tags ).get(int(id)) for id in kw['deltags']]
             except Exception:
                 tagi = None
             if tagi:
                 for tag in tagi:
                     for compound in DBSession.query(Compound).all():
                         if tag in compound.tags:
                             compound.tags.remove(tag)
                             history = History()
                             history.user = userid
                             history.status = u'Usuwanie tagu'
                             history.changes = u'Usunieto tag %s ' % tag.name
                             compound.history += [history]
                             DBSession.add(history)
                     DBSession.delete(tag)
                     DBSession.flush()
                 flash(l_(u'Task completed successfully'))
                 alltags =[tag for tag in DBSession.query(Tags).order_by('name').all() ]
         else:
             try:
                 if kw['addtag'] != '':
                     tagname = kw['addtag']
                 else:
                     tagname = None
             except Exception:
                 tagname = None
             if tagname:
                 tag = Tags()
                 tag.name = tagname
                 flash(l_(u'Task completed successfully'))
                 DBSession.add(tag)
                 DBSession.flush()
                 alltags =[tg for tg in DBSession.query(Tags).order_by('name').all() ]
             else:
                 flash(l_(u'Name required'), 'warning')
     return dict(alltags=alltags, page='kierownik', pname=pname)
Exemple #3
0
 def removelist(self, *args, **kw):
     """Let the user know that's visiting a protected controller."""
     userid = request.identity['repoze.who.userid']
     user = DBSession.query(User).filter(User.user_name == userid).first()
     id = args[0]
     mylist = DBSession.query(UserLists).get(id)
     if mylist.tg_user_id != user.user_id:
         flash(l_(u'Permission denied'), 'error')
         redirect(request.headers['Referer'])
     assert mylist.tg_user_id == user.user_id, u"Brak uprawnien usuwania"
     if mylist:
         DBSession.delete(mylist)
         DBSession.flush()
         flash(l_(u'Task completed successfully'))
         redirect(request.headers['Referer'])
     else:
         flash(l_(u'List is required'), 'warning')
         redirect(request.headers['Referer'])
Exemple #4
0
    def delete_project(self, *args, **kw):
        try:
            project_id = args[0]
        except Exception:
            redirect("/error")
        try:
            come_from = request.headers['Referer']
        except Exception:
            come_from = request.path_url
        project = DBSession.query(Projects).get(project_id)
        if project:
            DBSession.delete(project)
        else:
            flash(l_(u'Project error'), 'error')
            redirect(come_from)

        flash(l_(u'Task completed successfully'))
        redirect(come_from)
Exemple #5
0
 def removelist(self, *args, **kw):
     """Let the user know that's visiting a protected controller."""
     userid = request.identity['repoze.who.userid']
     user = DBSession.query(User).filter(User.user_name == userid).first()
     id = args[0]
     mylist = DBSession.query(UserLists).get(id)
     if mylist.tg_user_id != user.user_id:
         flash(l_(u'Permission denied'), 'error')
         redirect(request.headers['Referer'])
     assert mylist.tg_user_id == user.user_id, u"Brak uprawnien usuwania"
     if mylist:
         DBSession.delete(mylist)
         DBSession.flush()
         flash(l_(u'Task completed successfully'))
         redirect(request.headers['Referer'])
     else:
         flash(l_(u'List is required'), 'warning')
         redirect(request.headers['Referer'])
Exemple #6
0
    def delete_user(self, *args, **kw):
        try:
            user_id = args[0]
        except Exception:
            redirect("/error")
        try:
            come_from = request.headers['Referer']
        except Exception:
            come_from = request.path_url
        user = DBSession.query(User).get(user_id)
        if user:
            for group in user.groups:
                group.users.remove(user)
            DBSession.delete(user)
        else:
            flash(l_(u'User error'), 'error')
            redirect(come_from)

        flash(l_(u'Task completed successfully'))
        redirect(come_from)