Beispiel #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)
Beispiel #2
0
    def addlist(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()
        users = DBSession.query(User).order_by(User.display_name).all()
        allproj = DBSession.query(Projects).order_by('id').all()
        if args and len(args) >= 2:
            ntable = args[0]
            get_args = args[1:]
        else:
            ntable, get_args = [None, ()]
        if kw:
            if not (kw.has_key('name') and kw['name'] != u''):
                flash(l_(u'Name is required'), 'error')
                redirect(request.headers['Referer'])
            elif not (kw.has_key('table') and kw['table'] != u''):
                flash(l_(u'Table is required'), 'error')
                redirect(request.headers['Referer'])
            elif not (kw.has_key('project') and kw['project'] != u''):
                flash(l_(u'Project is required'), 'error')
                redirect(request.headers['Referer'])
            else:
                lista = UserLists()
                lista.name = kw['name']
                lista.table = kw['table']
                lista.pname = kw['project']
                if kw.has_key('notes') and kw['notes'] != u'':
                    lista.notes = kw['notes']
                if kw.has_key('permitusers') and kw['permitusers'] != u'':
                    if isinstance(kw['permitusers'], (list, tuple)):
                        permitusers = [
                            usr for usr in users
                            if usr.user_name in kw['permitusers']
                        ]
                    else:
                        permitusers = [
                            usr for usr in users
                            if usr.user_name == kw['permitusers']
                        ]
                    lista.permitusers = permitusers
                if kw.has_key('argv') and kw['argv'] != u'':
                    elements = []
                    for arg in kw['argv']:
                        elements.append(arg)
                    import pickle
                    lista.elements = pickle.dumps(elements)

                user.lists.append(lista)
                DBSession.add(lista)
                DBSession.flush()
                flash(l_(u'Task completed successfully'))
                redirect(request.headers['Referer'])
        return dict(user=user,
                    allproj=allproj,
                    users=users,
                    page='index',
                    ntable=ntable,
                    get_args=get_args,
                    pname=None)
Beispiel #3
0
 def setUp(self):
     """Setup test fixture for each model test method."""
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Beispiel #4
0
 def setUp(self):
     """Setup test fixture for each model test method."""
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Beispiel #5
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)
Beispiel #6
0
 def addlist(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()
     users = DBSession.query(User).order_by(User.display_name).all()
     allproj = DBSession.query(Projects).order_by('id').all()
     if args and len(args) >= 2:
         ntable = args[0]
         get_args = args[1:]
     else:
         ntable, get_args = [None, ()]
     if kw:
         if not (kw.has_key('name') and kw['name'] != u''):
             flash(l_(u'Name is required'), 'error')
             redirect(request.headers['Referer'])
         elif not (kw.has_key('table') and kw['table'] != u''):
             flash(l_(u'Table is required'), 'error')
             redirect(request.headers['Referer'])
         elif not (kw.has_key('project') and kw['project'] != u''):
             flash(l_(u'Project is required'), 'error')
             redirect(request.headers['Referer'])
         else:
             lista = UserLists()
             lista.name = kw['name']
             lista.table = kw['table']
             lista.pname = kw['project']
             if kw.has_key('notes') and kw['notes'] != u'':
                 lista.notes = kw['notes']
             if kw.has_key('permitusers') and kw['permitusers'] != u'':
                 if isinstance(kw['permitusers'], (list, tuple)):
                     permitusers = [usr for usr in users if usr.user_name in kw['permitusers']]
                 else:
                     permitusers = [usr for usr in users if usr.user_name == kw['permitusers']]
                 lista.permitusers = permitusers
             if kw.has_key('argv') and kw['argv'] != u'':
                 elements = []
                 for arg in kw['argv']:
                     elements.append(arg)
                 import pickle
                 lista.elements = pickle.dumps(elements)
                     
             user.lists.append(lista)
             DBSession.add(lista)
             DBSession.flush()
             flash(l_(u'Task completed successfully'))
             redirect(request.headers['Referer'])
     return dict(user=user, allproj=allproj, users=users, page='index', ntable=ntable, get_args=get_args, pname=None)
Beispiel #7
0
 def new_user(self, *args, **kw):
     """
     Add new User.
     """
     try:
         come_from = request.headers['Referer']
     except Exception:
         come_from = request.path_url
     groups = DBSession.query(Group).all()
     if kw:
         if 'come_from' in kw and kw['come_from'] != u'':
             come_from = kw['come_from']
         if 'password' in kw and kw['password'] != u'':
             new = kw['password']
             if 'verification' in kw and kw[
                     'verification'] != u'' and new != kw['verification']:
                 flash(l_(u'Password not match'), 'error')
                 redirect(come_from)
             else:
                 flash(l_('Verification error'), 'error')
         else:
             flash(l_(u'Password is required'), 'error')
             redirect(come_from)
         if 'email' in kw and kw['email'] != u'':
             email = kw['email']
         else:
             flash(l_('Email is required'), 'error')
             redirect(come_from)
         if 'items_per_page' in kw and kw['items_per_page'] != u'':
             try:
                 items_per_page = int(kw['items_per_page'])
             except Exception:
                 flash(l_('Compounds per page should be a number'), 'error')
         else:
             flash(l_('Compounds per page required'), 'error')
             redirect(come_from)
         if 'user_name' in kw and kw['user_name'] != u'':
             user = User()
             user.user_name = kw['user_name'].strip().replace(' ', '.')
         else:
             flash(l_('User name is required'), 'error')
             redirect(come_from)
         if 'display_name' in kw and kw['display_name'] != u'':
             user.display_name = kw['display_name']
         if 'groups' in kw and kw['groups'] != u'':
             if isinstance(kw['groups'], basestring):
                 groups = [DBSession.query(Group).get(kw['groups'])]
             else:
                 groups = [
                     DBSession.query(Group).get(group_id)
                     for group_id in kw['groups']
                 ]
         else:
             flash(l_('Group is required'), 'error')
             redirect(come_from)
         if items_per_page:
             if items_per_page > 10 and items_per_page < 150:
                 user.items_per_page = items_per_page
             else:
                 flash(
                     l_(u'Number of Compound per page should be between 10 and 150'
                        ), 'error')
                 redirect(come_from)
         if email:
             import re
             if len(email) >= 6:
                 if re.match(
                         "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$",
                         email) != None:
                     user.email_address = email
                 else:
                     flash(l_(u'Email error'), 'warning')
                     redirect(come_from)
             else:
                 flash(l_(u'Email error'), 'warning')
                 redirect(come_from)
         else:
             flash(l_(u'Email not changed'), 'warning')
         if new:
             if len(new) >= 6:
                 user._set_password(new)
             else:
                 flash(l_(u'Password error'), 'error')
                 redirect(come_from)
         else:
             flash(l_('Password is required'), 'error')
             redirect(come_from)
         if groups:
             for group in groups:
                 group.users.append(user)
         else:
             flash(l_('Gropus error'), 'error')
             redirect(come_from)
         DBSession.add(user)
         DBSession.flush()
         flash(l_(u'Task completed successfully'))
         redirect(come_from)
     return dict(page='index',
                 come_from=come_from,
                 groups=groups,
                 pname=None)
Beispiel #8
0
    def new_project(self, *args, **kw):
        """
        Create new project & group with correct permissions asigned.
        If you wish to allow users acces to the project- add them to group named as a project.
        """
        userid = request.identity['repoze.who.userid']
        user = DBSession.query(User).filter_by(user_name=userid).first()
        try:
            come_from = request.headers['Referer']
        except Exception:
            come_from = request.path_url
        if kw:
            if 'come_from' in kw and kw['come_from'] != u'':
                come_from = kw['come_from']
            if 'name' in kw and kw['name'] != u'':
                cell_lines = []
                fp_lines = []
                htrf_lines = []
                for k, v in kw.iteritems():
                    if 'Cell_Line_' in str(k) and v != u'':
                        cell_lines.append(v.strip().replace(' ', '_'))
                    if 'FP_Line_' in str(k) and v != u'':
                        fp_lines.append(v.strip().replace(' ', '_'))
                    if 'HTRF_Line_' in str(k) and v != u'':
                        htrf_lines.append(v.strip().replace(' ', '_'))

                if not cell_lines:
                    flash(l_(u'At least 1 Cell_Line is required'), 'error')
                    redirect(come_from)
                if not fp_lines:
                    flash(l_(u'At least 1 FP_Line is required'), 'error')
                    redirect(come_from)
                if not htrf_lines:
                    flash(l_(u'At least 1 HTRF_Line is required'), 'error')
                    redirect(come_from)
                #create new project:
                project = Projects()
                project.name = kw['name'].strip().replace(' ', '_')
                #add group named as a project:
                gr = Group()
                gr.group_name = kw['name'].strip().replace(' ', '_')
                gr.display_name = kw['name']
                gr.users.append(user)

                #add permission named as a project and assign it to group:
                from molgears.model import Permission
                perm = Permission()
                perm.permission_name = kw['name'].strip().replace(' ', '_')
                perm.groups += [gr]
                #add description:
                if 'description' in kw and kw['description'] != u'':
                    project.description = kw['description']
                #add test and cell lines
                ptest = ProjectTests()
                ptest.name = 'CT'

                fp_ptest = ProjectTests()
                fp_ptest.name = 'FP'
                htrf_ptest = ProjectTests()
                htrf_ptest.name = 'HTRF'
                project.tests = [fp_ptest, ptest, htrf_ptest]
                import pickle
                if cell_lines:
                    pickle_dump1 = pickle.dumps(cell_lines)
                    ptest.cell_line = pickle_dump1
                if fp_lines:
                    pickle_dump2 = pickle.dumps(fp_lines)
                    fp_ptest.cell_line = pickle_dump2
                if htrf_lines:
                    pickle_dump3 = pickle.dumps(htrf_lines)
                    htrf_ptest.cell_line = pickle_dump3
                DBSession.add(perm)
                DBSession.add(gr)
                DBSession.add(ptest)
                DBSession.add(fp_ptest)
                DBSession.add(project)
                DBSession.flush()
                flash(l_(u'Task completed successfully'))
                redirect(come_from)
            else:
                flash(l_(u'Name is required'), 'error')
                redirect(come_from)
        return dict(page='index', userid=userid, come_from=come_from)
Beispiel #9
0
    def multiedit(self, *args, **kw):
        pname = request.environ['PATH_INFO'].split('/')[1]
        alltags = [tag for tag in DBSession.query(Tags).order_by('name').all()]
        principals = DBSession.query(Group).get(3)
        owners = DBSession.query(Group).get(2)
        come_from = request.headers['Referer']
        if kw:
            try:
                if isinstance(kw['argv'], basestring):
                    argv = [kw['argv']]
                else:
                    argv = [id for id in kw['argv']]
            except Exception:
                argv = None
            try:
                if kw.has_key('notes') != u'':
                    notes = kw['notes']
                else:
                    notes = None
            except Exception:
                notes = None
            try:
                priority = int(kw['priority'])
            except Exception:
                priority = None
            if argv:
                userid = request.identity['repoze.who.userid']
                for arg in argv:
                    try:
                        if isinstance(kw['text_tags'], basestring):
                            tagi = [
                                DBSession.query(Tags).get(int(kw['text_tags']))
                            ]
                        else:
                            tagi = [
                                DBSession.query(Tags).get(int(id))
                                for id in kw['text_tags']
                            ]
                    except Exception:
                        tagi = None
                    scompound = DBSession.query(SCompound).get(int(arg))
                    shistory = SHistory()
                    shistory.gid = scompound.mol.gid
                    shistory.user = userid
                    shistory.status = u'Multi - edit'
                    shistory.changes = u''
                    if kw.has_key('owner') and kw['owner'] != u'None' and kw[
                            'owner'] != scompound.owner:
                        scompound.owner = kw['owner']
                        shistory.changes += u' Właściciel: ' + kw['owner'] + ';'
                    if kw.has_key(
                            'principal') and kw['principal'] != u'None' and kw[
                                'principal'] != scompound.principal:
                        scompound.principal = kw['principal']
                        shistory.changes += u' Odbiorca: ' + kw[
                            'principal'] + ';'
                    if priority and priority != scompound.priority:
                        scompound.priority = int(kw['priority'])
                        shistory.changes += u'; Priorytet: ' + kw[
                            'priority'] + ';'
                        pcompound = DBSession.query(PCompound).get(
                            scompound.pid)
                        if pcompound:
                            pcompound.priority = int(kw['priority'])
                            phistory = PHistory()
                            phistory.project = pname
                            phistory.date = datetime.now().strftime(
                                "%Y-%m-%d %H:%M:%S")
                            phistory.user = userid
                            phistory.status = 'Priorytet'
                            phistory.changes = u'Priority: ' + kw['priority']
                            pcompound.history += [phistory]
                            DBSession.add(phistory)
                    if tagi and scompound.mol.tags != tagi:
                        scompound.mol.tags = tagi
                        shistory.changes += u' Tags: '
                        for tag in tagi:
                            shistory.changes += str(tag.name) + ';'
                    if notes and notes != scompound.notes:
                        scompound.notes = notes
                        shistory.changes += u' Notes: ' + notes
                    scompound.history += [shistory]
                    DBSession.add(shistory)
                    DBSession.flush()
                    #transaction.commit()
                if kw.has_key('come_from'):
                    come_from = kw['come_from']
                else:
                    come_from = request.headers['Referer']
                flash(l_(u'Task completed successfully'))
                redirect(come_from)

        return dict(alltags=alltags,
                    args=args,
                    users=principals.users,
                    owners=owners.users,
                    come_from=come_from,
                    page='kierownik',
                    pname=pname)
Beispiel #10
0
    def put(self, *args, **kw):
        pname = request.environ['PATH_INFO'].split('/')[1]
        sid = int(args[0])
        userid = request.identity['repoze.who.userid']
        scompound = DBSession.query(SCompound).get(sid)
        shistory = SHistory()
        shistory.gid = scompound.mol.gid
        shistory.user = userid
        shistory.status = u'Edycja'
        schanges = u''
        try:
            reason = kw['reason']
        except Exception:
            reason = None
            pass
        if reason and reason != u'':
            schanges += u'UWAGA! niestandardowa zmiana z powodu:' + reason
            etap = int(kw['etap'])
            etap_max = int(kw['etap_max'])
            if etap < etap_max:
                scompound.effort[-1].etap = etap
                scompound.effort[-1].etap_max = etap_max
                scompound.status = DBSession.query(SStatus).get(2)
                schanges += u'; Bieżący etap: ' + str(etap)
                schanges += u'; Liczba etapow: ' + str(etap_max)
            else:
                flash(
                    l_(u'Completed step must be smaller by 2 than the number of stages'
                       ), 'error')
                redirect(request.headers['Referer'])
#        scompound.status_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        if kw.has_key('lso') and kw['lso'] != scompound.lso:
            scompound.lso = kw['lso']
            schanges += u'; LSO: ' + kw['lso']
        if kw.has_key('notes') and kw['notes'] != scompound.notes:
            scompound.notes = kw['notes']
            schanges += u';Notes: ' + kw['notes']
        try:
            filename = kw['loadfile'].filename
            import os
            filename = os.path.basename(filename)
        except Exception as msg:
            filename = None
            pass
        try:
            reaction_file = kw['reaction'].filename
            import os
            reaction_file = os.path.basename(reaction_file)
        except Exception as msg:
            reaction_file = None
            pass

        if kw['owner'] != scompound.owner:
            scompound.owner = kw['owner']
            schanges += u'; Wlasciciel:' + kw['owner']
        if kw['principal'] != scompound.principal:
            scompound.principal = kw['principal']
            schanges += u'; Odbiorca:' + kw['principal']
        if kw.has_key('priority') and kw['priority'] != u'':
            scompound.priority = int(kw['priority'])
            schanges += u'; Priorytet:' + kw['priority']
            pcompound = DBSession.query(PCompound).get(scompound.pid)
            if pcompound:
                pcompound.priority = int(kw['priority'])
                phistory = PHistory()
                phistory.project = pname
                phistory.date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                phistory.user = userid
                phistory.status = 'Priorytet'
                phistory.changes = u'Priority: ' + kw['priority']
                pcompound.history += [phistory]
                DBSession.add(phistory)

        if filename or reaction_file:
            if filename:
                number = DBSession.query(SFiles).count() + 1
                newfilename = str(number) + '_' + userid + '_' + str(
                    sid) + '_' + filename
                newfilename.replace(' ', '_')
                f_path = os.path.join(files_dir, newfilename)
                try:
                    f = file(f_path, "w")
                    f.write(kw['loadfile'].value)
                    f.close()
                except Exception as msg:
                    flash(l_(msg), 'error')
                    redirect(request.headers['Referer'])
                sfile = SFiles()
                sfile.name = filename
                sfile.filename = newfilename
                if kw['opis']:
                    sfile.description = kw['opis']
                schanges += u'; Plik: ' + filename + u' ( ' + newfilename + u' )'
                DBSession.add(sfile)
            if reaction_file:
                number2 = DBSession.query(SFiles).count() + 1
                newfilename2 = str(number2) + '_' + userid + '_' + str(
                    sid) + '_' + reaction_file
                newfilename2.replace(' ', '_')
                f_path2 = os.path.join(files_dir, newfilename2)
                try:
                    f2 = file(f_path2, "w")
                    f2.write(kw['reaction'].value)
                    f2.close()
                except Exception as msg:
                    flash(l_(msg), 'error')
                    redirect(request.headers['Referer'])
                reaction_sfile = SFiles()
                reaction_sfile.name = reaction_file
                reaction_sfile.filename = newfilename2
                schanges += u'; Sciezka reakcji: ' + reaction_file + u' ( ' + newfilename2 + u' )'
                DBSession.add(reaction_sfile)
            shistory.changes = schanges
            scompound.history += [shistory]

            DBSession.add(shistory)
            DBSession.flush()
            #transaction.commit()
            scompound2 = DBSession.query(SCompound).get(sid)
            if filename:
                sfile2 = [sfile]
                sfile2 += scompound2.filename
                scompound2.filename = sfile2
            if reaction_file:
                reaction_sfile = [reaction_sfile]
                #                reaction_sfile += scompound2.reaction
                scompound2.reaction = reaction_sfile
        else:
            shistory.changes = schanges
            scompound.history += [shistory]
            DBSession.add(shistory)
            DBSession.flush()

            flash(l_(u'Task completed successfully'))
        if kw and kw.has_key('come_from'):
            come_from = kw['come_from']
        else:
            come_from = request.headers['Referer']
        redirect(come_from)
Beispiel #11
0
 def multiedit(self, *args, **kw):
     pname = request.environ['PATH_INFO'].split('/')[1]
     alltags =[tag for tag in DBSession.query(Tags).order_by('name').all() ]
     principals = DBSession.query (Group).get(3)
     owners = DBSession.query (Group).get(2)
     come_from = request.headers['Referer']
     if kw:
         try:
             if isinstance(kw['argv'], basestring):
                 argv = [kw['argv']]
             else:
                 argv = [id for id in kw['argv']]
         except Exception:
             argv = None
         try:
             if kw.has_key('notes') != u'':
                 notes = kw['notes']
             else:
                 notes = None
         except Exception:
             notes = None
         try:
             priority = int(kw['priority'])
         except Exception:
             priority = None
         if argv:
             userid = request.identity['repoze.who.userid']
             for arg in argv:
                 try:
                     if isinstance(kw['text_tags'], basestring):
                         tagi = [DBSession.query( Tags ).get(int(kw['text_tags']))]
                     else:
                         tagi = [DBSession.query( Tags ).get(int(id)) for id in kw['text_tags']]
                 except Exception:
                     tagi = None
                 scompound = DBSession.query(SCompound).get(int(arg))
                 shistory = SHistory()
                 shistory.gid = scompound.mol.gid
                 shistory.user = userid
                 shistory.status = u'Multi - edit'
                 shistory.changes = u''
                 if kw.has_key('owner') and kw['owner'] != u'None' and kw['owner'] != scompound.owner:
                     scompound.owner = kw['owner']
                     shistory.changes += u' Właściciel: ' + kw['owner'] + ';'
                 if kw.has_key('principal') and kw['principal'] != u'None' and kw['principal'] != scompound.principal:
                     scompound.principal = kw['principal']
                     shistory.changes += u' Odbiorca: ' + kw['principal'] + ';'
                 if priority and priority != scompound.priority:
                     scompound.priority = int(kw['priority'])
                     shistory.changes += u'; Priorytet: ' + kw['priority'] + ';'
                     pcompound = DBSession.query(PCompound).get(scompound.pid)
                     if pcompound:
                         pcompound.priority = int(kw['priority'])
                         phistory = PHistory()
                         phistory.project = pname
                         phistory.date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                         phistory.user = userid
                         phistory.status = 'Priorytet'
                         phistory.changes = u'Priority: ' + kw['priority']
                         pcompound.history += [phistory]
                         DBSession.add(phistory)
                 if tagi and scompound.mol.tags != tagi:
                     scompound.mol.tags = tagi
                     shistory.changes += u' Tags: '
                     for tag in tagi:
                         shistory.changes += str(tag.name) + ';'
                 if notes and notes != scompound.notes:
                     scompound.notes = notes
                     shistory.changes += u' Notes: ' + notes
                 scompound.history += [shistory]
                 DBSession.add(shistory)
                 DBSession.flush()
                 #transaction.commit()
             if kw.has_key('come_from'):
                 come_from = kw['come_from']
             else:
                 come_from = request.headers['Referer']
             flash(l_(u'Task completed successfully'))
             redirect(come_from)
             
     return dict(alltags=alltags, args=args, users=principals.users, owners=owners.users, come_from=come_from, page='kierownik', pname=pname)
Beispiel #12
0
    def put(self, *args, **kw):
        pname = request.environ['PATH_INFO'].split('/')[1]
        sid = int(args[0])
        userid = request.identity['repoze.who.userid']
        scompound = DBSession.query(SCompound).get(sid)
        shistory = SHistory()
        shistory.gid = scompound.mol.gid
        shistory.user = userid
        shistory.status = u'Edycja'
        schanges = u''
        try:
            reason = kw['reason']
        except Exception:
            reason = None
            pass
        if reason and reason != u'':
            schanges += u'UWAGA! niestandardowa zmiana z powodu:' + reason
            etap = int(kw['etap']) 
            etap_max = int(kw['etap_max'])
            if etap < etap_max:
                scompound.effort[-1].etap = etap
                scompound.effort[-1].etap_max = etap_max
                scompound.status = DBSession.query( SStatus ).get(2)
                schanges += u'; Bieżący etap: ' + str(etap)
                schanges += u'; Liczba etapow: ' + str(etap_max)
            else:
                flash(l_(u'Completed step must be smaller by 2 than the number of stages'), 'error')
                redirect(request.headers['Referer'])
#        scompound.status_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        
        if kw.has_key('lso') and kw['lso'] != scompound.lso:
            scompound.lso = kw['lso']
            schanges += u'; LSO: ' + kw['lso']
        if kw.has_key('notes') and kw['notes'] != scompound.notes:
            scompound.notes = kw['notes']
            schanges += u';Notes: ' + kw['notes']
        try:
            filename = kw['loadfile'].filename
            import os
            filename = os.path.basename(filename)
        except Exception as msg:
            filename = None
            pass
        try:
            reaction_file = kw['reaction'].filename
            import os
            reaction_file = os.path.basename(reaction_file)
        except Exception as msg:
            reaction_file = None
            pass
        
        if kw['owner'] != scompound.owner:
            scompound.owner = kw['owner']
            schanges += u'; Wlasciciel:' + kw['owner']
        if kw['principal'] != scompound.principal:
            scompound.principal = kw['principal']
            schanges += u'; Odbiorca:' + kw['principal']
        if kw.has_key('priority') and kw['priority'] != u'':
            scompound.priority = int(kw['priority'])
            schanges += u'; Priorytet:' + kw['priority']
            pcompound = DBSession.query(PCompound).get(scompound.pid)
            if pcompound:
                pcompound.priority = int(kw['priority'])
                phistory = PHistory()
                phistory.project = pname
                phistory.date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                phistory.user = userid
                phistory.status = 'Priorytet'
                phistory.changes = u'Priority: ' + kw['priority']
                pcompound.history += [phistory]
                DBSession.add(phistory)

        if filename or reaction_file:
            if filename:
                number = DBSession.query(SFiles).count() + 1
                newfilename = str(number) + '_' + userid + '_' + str(sid) + '_' + filename
                newfilename.replace(' ', '_')
                f_path = os.path.join(files_dir, newfilename)
                try:
                    f = file(f_path, "w")
                    f.write(kw['loadfile'].value)
                    f.close()
                except Exception as msg:
                    flash(l_(msg), 'error')
                    redirect(request.headers['Referer'])
                sfile = SFiles()
                sfile.name = filename
                sfile.filename = newfilename
                if kw['opis']:
                    sfile.description = kw['opis']
                schanges += u'; Plik: ' + filename + u' ( ' + newfilename + u' )'
                DBSession.add(sfile)
            if reaction_file:
                number2 = DBSession.query(SFiles).count() + 1
                newfilename2 = str(number2) + '_' + userid + '_' + str(sid) + '_' + reaction_file
                newfilename2.replace(' ', '_')
                f_path2 = os.path.join(files_dir, newfilename2)
                try:
                    f2 = file(f_path2, "w")
                    f2.write(kw['reaction'].value)
                    f2.close()
                except Exception as msg:
                    flash(l_(msg), 'error')
                    redirect(request.headers['Referer'])
                reaction_sfile = SFiles()
                reaction_sfile.name = reaction_file
                reaction_sfile.filename = newfilename2
                schanges += u'; Sciezka reakcji: ' + reaction_file + u' ( ' + newfilename2 + u' )'
                DBSession.add(reaction_sfile)
            shistory.changes = schanges
            scompound.history += [shistory]
    
            DBSession.add(shistory)
            DBSession.flush()
            #transaction.commit()
            scompound2 = DBSession.query(SCompound).get(sid)
            if filename:
                sfile2 = [sfile]
                sfile2 += scompound2.filename
                scompound2.filename = sfile2
            if reaction_file:
                reaction_sfile = [reaction_sfile]
#                reaction_sfile += scompound2.reaction
                scompound2.reaction = reaction_sfile
        else:
            shistory.changes = schanges
            scompound.history += [shistory]
            DBSession.add(shistory)
            DBSession.flush()
        
            flash(l_(u'Task completed successfully'))
        if kw and kw.has_key('come_from'):
            come_from = kw['come_from']
        else:
            come_from = request.headers['Referer']
        redirect(come_from)