Exemple #1
0
def userRiport(userId):
    """ Felhasználó riport megtekintése
    
    Arguments:
        userId {int} -- Felhasználó azonosító
    
    Returns:
        response
    """    
    user = User.query.get_or_404(userId)    
    creatorRiport = User.getJobCreatorRiportData(user)
    workerRiport  = User.getJobWorkerRiportData(user)
    data = {
        'user' : user,
        'createdCount' : creatorRiport['jobCount'],        
        'creatorRiportEstimated': creatorRiport['estimated'],
        'creatorRiportBooked': creatorRiport['booked'],
        'creatorRiportPercent': creatorRiport['percent'],
        'workerCount'  : workerRiport['jobCount'],
        'workerRiportEstimated': workerRiport['estimated'],
        'workerRiportBooked': workerRiport['booked'],
        'workerRiportPercent': workerRiport['percent'],
        'activeLink' : 'users',
    }
    return render_template('User/userRiport.html', **data)
Exemple #2
0
def deleteProjectWorker(projectId):
    """ Munkatárs törlése a projektből
    
    Arguments:
        projectId {int} -- Projekt azonosító
    
    Returns:
        response
    """
    project = Project.query.get_or_404(projectId)
    if current_user == project.creator and Project.isModifiable(project, current_user.id):
        userId = request.form.get('delUserId')
        user = User.query.filter_by(id=userId).first()
        if user is not None:
            if not User.hasProjectConnection(user, project):
                project.workers.remove(user)
                db.session.commit() 
                flash(f'Munkatárs törölve!', 'success')
            else:
                flash(f'Munkatárs nem törölhető, van létrehozott vagy elvégzendő feladata!', 'danger')
    else:
        flash(f'Projekt nem módosítható', 'danger')
        return redirect(url_for('projectData', projectId=projectId))
        
    return redirect(url_for('projectWorkers', projectId=project.id))
Exemple #3
0
def uploadFileToJob(projectJobId):
    """ Projekt feladathoz file feltöltése
    
    Arguments:
        projectJobId {int} -- Projekt feladat azonosító
    
    Returns:
        response
    """
    projectJob = ProjectJob.query.get_or_404(projectJobId)
    project = Project.query.get_or_404(projectJob.projectId)
    if project not in User.getUserVisibleProjects(current_user.id):
        return redirect(url_for('projects'))
    
    data = {
        'projectJob' : projectJob,
        'allowed'    : str(app.config['FILE_EXTENSIONS']).strip('[]').lower(),
        'maxSize'    : str(app.config['FILE_UPLOAD_SIZE'] / pow(1024, 2)) + ' MB',
        'activeLink' : 'projects', 
    }
    
    if request.method == 'POST':        
        if request.files:            
            file = request.files['file']
            fileName = file.filename
            # Név, kiterjesztés ellenőrzés
            if fileName == '' or not allowedFile(fileName):
                flash(f'Nem megengedett kiterjesztés!', 'danger')
                return render_template('ProjectJob/upload.html', **data)
            # Méret ellenőrzés
            if not allowedFileSize(request.cookies.get("fileSize")):
                flash(f'Fájl mérete meghaladja a megengedett méretet!', 'danger')
                return render_template('ProjectJob/upload.html', **data)
            # Biztonságos egyedi filename 
            secureFileName = str(projectJobId) + '_' + str(randint(1, 1000)) + '_' + secure_filename(fileName)            
            savePath = os.path.join(app.config['FILE_UPLOADS'], secureFileName)
            # Mentés       
            file.save(savePath)                        
            # Ha kijátsza a cookie-t akkor mentés után újra ellenőrzés
            if not allowedFileSize(os.path.getsize(savePath)) and os.path.exists(savePath):
                os.remove(savePath)
                flash(f'Fájl mérete meghaladja a megengedett méretet!', 'danger')
                return render_template('ProjectJob/upload.html', **data)
            else:
                # Kapcsolat a Projekt feladattal
                fileData = {
                    'projectJobId'  : projectJobId,
                    'fileName'      : secureFileName,
                    'createTime'    : datetime.now(),
                    'creatorUserId' : current_user.id,
                }
                projectJobFile = ProjectJobFile(**fileData)
                db.session.add(projectJobFile)
                db.session.commit()
                flash(f'Sikeres fájl feltöltés! {secureFileName}', 'success')    

    return render_template('ProjectJob/upload.html', **data)
Exemple #4
0
def projectJobData(projectJobId):
    """ Projekt feladat adatlap
    
    Arguments:
        projectJobId {int} -- Projekt feladat azonosító
    
    Returns:
        response
    """    
    projectJob = ProjectJob.query.get_or_404(projectJobId)
    project = Project.query.get_or_404(projectJob.projectId)
    if project not in User.getUserVisibleProjects(current_user.id):
        return redirect(url_for('projects'))

    projectJob.hasSubJob = ProjectJob.hasSubJob(projectJob)   
    
    if ProjectJob.hasSubJob(projectJob) :
        worktimesAll = [] 
        worktimesSorted = [] # Nincs feladat munkaidő        
        for job in ProjectJob.getSubJobs(projectJob):
            worktimes = ProjectJob.getJobWorktimes(job.id)
            for worktime in worktimes:
                user = User.query.get(worktime.createUserId)
                projectSubJob = ProjectJob.query.get(job.id)
                userName = user.fullName
                worktimesAll.append({
                    'projectJobName' : projectSubJob.name, 
                    'userName' :userName, 
                    'date' : worktime.createTime, 
                    'workTime' : worktime.workTime,
                    'comment' : worktime.comment
                })        
        worktimesSubJob = sorted(worktimesAll, key=lambda k:  k['date'])
    else:
        projectJob.workTimes = ProjectJob.getJobWorktimes(projectJobId)
        worktimes = []
        worktimesSubJob = [] # Nincs alfeladat munkaidő
        for worktime in projectJob.workTimes:
            user = User.query.get(worktime.createUserId)
            worktimes.append({
                'userName' : user.fullName, 
                'date' : worktime.createTime, 
                'workTime' : worktime.workTime,
                'comment' : worktime.comment
            })
        worktimesSorted = sorted(worktimes, key=lambda k:  k['date'])

    data = {
        'projectJob' : projectJob,
        'project'    : project,
        'worktimes'  : worktimesSorted,
        'worktimesSubJob'  : worktimesSubJob,
        'sumHours'   : ProjectJob.getJobWorktimesAll(projectJob.id),        
        'activeLink' : 'projects', 
    }
    return render_template('ProjectJob/projectJobData.html', **data)
Exemple #5
0
def downloadFile(fileId):
    """ Projekt feladat file letöltése
    
    Arguments:
        fileId {int} -- Projekt feladat file azonosító
    
    Returns:
        response
    """
    projectJobFile = ProjectJobFile.query.get_or_404(fileId)
    if projectJobFile.projectJob.project in User.getUserVisibleProjects(current_user.id):
        try:
            return send_from_directory(app.config['FILE_UPLOADS'], filename=projectJobFile.fileName, as_attachment=True)
        except FileNotFoundError:
            abort(404)
Exemple #6
0
def userJobsAll():
    """ Feladatok, kapcsolatok lekérése a charthoz / User nézet
    
    Returns:
        [json] -- Feladatok és linkek serializálva
    """
    jobsAll = User.getProjectJobListCategories(current_user.id)
    jobs = jobsAll['pendingJobs']
    if jobsAll['activeJob'] is not None:
        jobs.append(jobsAll['activeJob'])

    links = ProjectJobLink.query.all()

    return jsonify(data=[i.serialize for i in jobs],
                   links=[j.serialize for j in links])
Exemple #7
0
def projects():
    """ Projekt lista
    
    Returns:
        response
    """
    if current_user.admin == True:
        projects = Project.query.order_by(Project.name).all()
    else:
        projects = User.getUserVisibleProjects(current_user.id)    
    
    data = {
        'activeLink' : 'projects',
        'projects' : projects,
    }
    return render_template('Project/projects.html', **data)
Exemple #8
0
def removeFile(fileId):
    """ Projekt feladat file törlése, és átmozgatása 
        a törölt könyvtárba
    
    Arguments:
        fileId {int} -- Projekt feladat file azonosító
    
    Returns:
        response
    """
    projectJobFile = ProjectJobFile.query.get_or_404(fileId)
    if projectJobFile.projectJob.project in User.getUserVisibleProjects(current_user.id) and projectJobFile.creatorUserId == current_user.id:
        if ProjectJobFile.deleteFile(projectJobFile):
            flash(f'Fájl törölve!', 'success')
        else:
            flash(f'Fájl nem törölhető!', 'danger')

    return redirect(url_for('projectJobData', projectJobId=projectJobFile.projectJobId))
Exemple #9
0
def userData(userId):
    """ Felhasználó adatlap megtekintése
    
    Arguments:
        userId {int} -- Felhasználó azonosító
    
    Returns:
        response
    """    
    user = User.query.get_or_404(userId)    
    jobs = User.getProjectJobListCategories(userId)
    data = {
        'user' : user,
        'projectCount' : len(user.projects),
        'pendingJobCount' : len(jobs['pendingJobs']),
        'doneJobCount' : len(jobs['doneJobs']),
        'activeLink' : 'users',
    }
    return render_template('User/userData.html', **data)
Exemple #10
0
def account():
    """ Adataim menüpont
    
    Returns:
        response
    """
    form = ModifyAccountBaseDataForm()
    user = User.query.get_or_404(current_user.id)
    jobs = User.getProjectJobListCategories(current_user.id)
    data = {
        'user' : user,       
        'projectCount' : len(user.projects),
        'pendingJobCount' : len(jobs['pendingJobs']),
        'doneJobCount' : len(jobs['doneJobs']),
        'activeLink' : 'account',
    }

    if form.validate_on_submit():
        email = form.email.data
        userName =  remove_tags(form.userName.data)
        oldUser = User.query.filter(
            or_(User.userName == userName, User.email == email), 
            and_(User.id != current_user.id)
        ).first()
        if oldUser is None or oldUser.id == current_user.id:
            user.userName = userName
            user.email = email
            db.session.commit()
            flash(f'Sikeres módosítás', 'success')
            return redirect(url_for('account'))
        else:
            flash(f'Adott felhasználónév vagy email foglalt!', 'danger')
            data['form'] = form
            return render_template('User/account.html', **data)
    else:
        if not form.is_submitted():
            form.userName.default = user.userName
            form.email.default = user.email
            form.process()
    
        data['form'] = form
        return render_template('User/account.html', **data)
Exemple #11
0
def index():
    """ Dashboard megjelenítése
    
    Returns:
        response
    """
    jobs = User.getProjectJobListCategories(current_user.id)
    pendingJobs = []
    for job in jobs['pendingJobs']:
        job.hasSubJob = ProjectJob.hasSubJob(job)
        job.canCreateSubJob = ProjectJob.canCreateSubJob(job, current_user.id)
        pendingJobs.append(job)

    data = {
        'activeLink' : 'home',
        'activeJob' : jobs['activeJob'],
        'pendingJobs' : pendingJobs,
        'doneJobs' : jobs['doneJobs'],
        'form' : AddProjectWorkTimeForm(),
    }
    return render_template('Index/home.html', **data)
Exemple #12
0
def projectData(projectId):
    """ Projekt adatai aloldal
    
    Arguments:
        projectId {int} -- Projekt azonosító
    
    Returns:
        response
    """
    project = Project.query.get_or_404(projectId)  
    project.isModifiable = Project.isModifiable(project, current_user.id)  
    if current_user.admin == False and project not in User.getUserVisibleProjects(current_user.id):
        return redirect(url_for('projects'))  
      
    worktimesAll = []
    for job in project.projectJobs:
        worktimes = ProjectJob.getJobWorktimes(job.id)
        for worktime in worktimes:
            user = User.query.get(worktime.createUserId)
            projectJob = ProjectJob.query.get(job.id)
            userName = user.fullName
            worktimesAll.append({
                'projectJobName' : projectJob.name, 
                'userName' :userName, 
                'date' : worktime.createTime, 
                'workTime' : worktime.workTime   
            })        
        job.isModifiable = ProjectJob.isModifiable(job, current_user.id)
    worktimesAllSorted = sorted(worktimesAll, key=lambda k: k['date']) 
    riport = Project.getRiportData(project)

    data = {
        'project' : project,
        'activeLink' : 'projects',
        'sumHours' : riport['booked'],
        'estimatedHours' : riport['estimated'],
        'riportPercent' : riport['percent'],
        'worktimesAll' : worktimesAllSorted,
    }
    return render_template('Project/projectData.html', **data)
Exemple #13
0
def passiveUser(userId):
    """ Felhasználó passziválása
    
    Arguments:
        userId {int} -- Felhasználó azonosító
    
    Returns:
        response
    """
    if current_user.admin != True:
        return redirect(url_for('index'))

    user = User.query.get(userId)
    if User.isPassivable(user, current_user):
        user.deleted = True
        user.delTime = datetime.now()
        db.session.add(user)
        db.session.commit()
        flash(f'Sikeres felhasználó passziválás!', 'success')
    else:
        flash(f'Sikertelen felhasználó passziválás!', 'danger')
    return redirect(url_for('users'))
Exemple #14
0
def projectGantt(projectId):
    """ Projekt Gantt oldal
    
    Arguments:
        projectId {int} -- Projekt azonosító
    
    Returns:
        response
    """
    project = Project.query.get_or_404(projectId) 
    if not project in User.getUserVisibleProjects(current_user.id) or not Project.isActive(project):
        return redirect(url_for('projectData', projectId=projectId))
 
    users = Project.getProjectUsers(project)
    
    data = {
        'activeLink' : 'projects',
        'mode'       : 'project',
        'project'    : project,
        'users'      : users,
        'canAdd'     : True if current_user in project.leaders else False,
    }
    return render_template('Gantt/gantt.html', **data)
Exemple #15
0
def register():
    """ Felhasználó felvitele
    
    Returns:
        response
    """
    if current_user.admin != True:
        return redirect(url_for('index'))
    form = RegisterForm()
    if form.validate_on_submit():
        oldUser = User.query.filter(or_(User.userName == form.userName.data, User.email == form.email.data)).first()
        if oldUser is not None:
            flash(f'Adott felhasználónév vagy email foglalt!', 'danger')
            data = {
                'form' : form,
                'activeLink' : 'users',  
            }              
            return render_template('User/register.html', **data)
        else:
            hashedPassword = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
            userData = {
                'userName' : remove_tags(form.userName.data),
                'fullName' : remove_tags(form.fullName.data),
                'password' : hashedPassword,
                'email'    : form.email.data
            }
            user = User(**userData)
            db.session.add(user)
            db.session.commit()
            flash(f'Felhasználó regisztrálva {form.userName.data}', 'success')        
            return redirect(url_for('users'))
    else:
        data = {
            'form' : form,    
            'activeLink' : 'users',
        }
        return render_template('User/register.html', **data)
Exemple #16
0
def projectJobCreateSubJob(parentJobId):
    """ Várakozó elvégzendő feladathoz alfeladat felvitele
    
    Arguments:
        parentJobId {int} -- Szülő Projekt feladat azonosító
    
    Returns:
        response
    """
    form = AddAndModifyProjectJobSubJob()
    parentJob = ProjectJob.query.get_or_404(parentJobId)
    if not ProjectJob.canCreateSubJob(parentJob, current_user.id):
        flash(f'Feladathoz nem lehet alfeladatot rögzíteni!', 'danger')
        return redirect(url_for('index'))
    project   = Project.query.get_or_404(parentJob.projectId)

    if project not in User.getUserVisibleProjects(current_user.id):
        flash(f'Feladathoz nem lehet alfeladatot rögzíteni!', 'danger')
        return redirect(url_for('index'))

    if form.validate_on_submit():
        date = form.date.data
        start = form.start.data
        duration = form.duration.data
        dateStart = datetime.combine(date, start)
        dateEnd = dateStart + timedelta(hours=duration)
        
        projectJobData = {
            'name' : remove_tags(form.name.data),
            'description' : remove_tags(form.description.data),            
            'dateStart' : dateStart,
            'dateEnd' : dateEnd,
            'estimatedTime' : 0,
            'duration' : duration,
            'creatorUserId' : current_user.id,
            'workerUserId' : current_user.id,
            'projectId' : project.id,            
            'parentJobId' : parentJob.id,            
        }
        projectJob = ProjectJob(**projectJobData)

        db.session.add(projectJob)
        db.session.commit()

        jobLinkData = {
            'source' : projectJob.id,
            'target' : parentJob.id,
            'type'   : '2', # finish_to_finish
        }
        link = ProjectJobLink(**jobLinkData)
        
        db.session.add(link)
        db.session.commit()

        flash(f'Sikeres alfeladat felvitel!', 'success')
        return redirect(url_for('index'))
    else:
        data = {
            'form' : form,
            'parentJob' : str(parentJob),
            'activeLink' : 'projects',
        }
        return render_template('ProjectJob/addProjectJobSubJob.html', **data)