Ejemplo n.º 1
0
    def post(self):

        user = self.request.environ['current_user']

        role_key = Role.gql("WHERE value = :hr", hr='hr').get().key()

        if role_key not in user.role:
            self.error(403)
            return

        start_str = self.request.get('start')
        finish_str = self.request.get('finish')
        type = self.request.get('type')

        event = Event.all().filter('type', type).get()
        try:
            first_date = event.first_effective_date
        except AttributeError:
            first_date = None

        employees = self.request.get('employees')[:-1].split(',')

        try:
            start = datetime.datetime.strptime(start_str, '%Y-%m-%d').date()
            finish = datetime.datetime.strptime(finish_str, '%Y-%m-%d').date()
        except ValueError:
            self.response.out.write('incorrect date')
            self.error(403)
            return

        description = "PR %s: %s-%s" % (type, start_str, finish_str)

        period = PerformanceReviewPeriod(type=type,
                                         description=description,
                                         start_date=start,
                                         finish_date=finish)
        period.put()

        for employee in employees:
            if employee != '':
                user = Model.get(employee)
                pr = PerformanceReview(employee=user,
                                       first_effective_date=first_date,
                                       manager=user.manager,
                                       period=period,
                                       date=start)
                pr.put()

        self.response.out.write(period.key())
    def get(self):
        today = datetime.date.today()
        events = Event.all()
        employees = User.all()
        month = datetime.timedelta(days=30)
        week = datetime.timedelta(weeks=1)

        for event in events:

            if event.start_date < today:
                event.start_date = event.start_date.replace(year = (today.year + 1))
                event.put()

        for employee in employees:

            first_date = employee.first_date

            if not first_date:
                first_date = datetime.date.min

            start_date = first_date + datetime.timedelta(weeks=13)
            finish_date = start_date + datetime.timedelta(weeks=2)

            if start_date - month == today:

                description = "PR annual: %s-%s" % (start_date, finish_date)

                period = PerformanceReviewPeriod(type='annual',
                                                description=description,
                                                start_date=start_date,
                                                finish_date=finish_date)
                period.put()

                pr = PerformanceReview(employee=employee,
                                        manager=employee.manager,
                                        date=period.start_date,
                                        period=period)
                pr.put()

            next_pr_start_date = start_date + 13 * week

            for event in events:

                delta = next_pr_start_date - event.start_date

                if next_pr_start_date > today:

                    if delta < month and delta > -month:

                        if event.start_date - month == today:

                            description = "PR %s: %s-%s" % (event.type, event.start_date, event.finish_date)
                            period = PerformanceReviewPeriod(start_date=event.start_date,
                                description=description,
                                finish_date=event.finish_date)
                            period.put()

                            pr = PerformanceReview(period=period,
                                employee=employee,
                                manager=employee.manager,
                                date=period.start_date
                            )
                            pr.put()
                    else:

                        if next_pr_start_date == today + month:

                            finish_date = next_pr_start_date + 2 * week
                            description = "PR custom: %s-%s" % (next_pr_start_date, finish_date)
                            period = PerformanceReviewPeriod(start_date=next_pr_start_date,
                                description=description,
                                finish_date=finish_date)
                            period.put()

                            pr = PerformanceReview(period=period,
                                employee=employee,
                                manager=employee.manager,
                                date=period.start_date
                            )
                            pr.put()

                else:

                    for event in events:
                        if event.start_date - month == today or event.start_date.replace(year=(today.year + 1)):

                            description = "PR %s: %s-%s" % (event.type, event.start_date, event.finish_date)
                            period = PerformanceReviewPeriod(start_date=event.start_date,
                                description=description,
                                finish_date=event.finish_date)
                            period.put()

                            pr = PerformanceReview(period=period,
                                employee=employee,
                                manager=employee.manager,
                                date=period.start_date
                            )
                            pr.put()
Ejemplo n.º 3
0
    def get(self, role, pr_key, blob_key):

        blob_key = str(urllib.unquote(blob_key))
        blob_info = blobstore.BlobInfo.get(blob_key)

        current_pr = PerformanceReview.get(pr_key)

        if role == 'manager':
            url = '/#/manager/pr/get/manager/%s' %current_pr.key()
        elif role == 'hr':
            url = '/#/hr/get/manager/%s' %current_pr.key()
        elif role == 'employee':
            url = '/#/employee/pr/get/employee/%s' %current_pr.key()
        else:
            url = '/'

        file = blob_info.open()

        employee = current_pr.employee

        NAMESPACES = {
            'w':"http://schemas.microsoft.com/office/word/2003/wordml",
            'v':"urn:schemas-microsoft-com:vml",
            'w10':"urn:schemas-microsoft-com:office:word",
            'sl':"http://schemas.microsoft.com/schemaLibrary/2003/core",
            'aml':"http://schemas.microsoft.com/aml/2001/core",
            'wx':"http://schemas.microsoft.com/office/word/2003/auxHint",
            'o':"urn:schemas-microsoft-com:office:office",
            'dt':"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882",
            'wsp':"http://schemas.microsoft.com/office/word/2003/wordml/sp2",
            'ns0':"GD_AssessmentReportManager.xsl",
        }

        ElementTree.register_namespace(
                                'o',
                                'urn:schemas-microsoft-com:office:office')

        try:
            parser = ElementTree.parse(file)
        except SyntaxError:
            self.response.out.write('incorrect type')
            return

        date = parser.find('.//w:body//ns0:ActionDateFormat//w:t',
                          namespaces=NAMESPACES).text
        manager_type = parser.find(
                          './/w:body//ns0:GD_ManagerAssessmentForm//w:t',
                          namespaces=NAMESPACES)
        if manager_type is None:

            blob_info.delete()
            self.response.out.write('incorrect type')
#
            return

        fio = parser.find('.//w:body//ns0:EmployeeName//w:t',
                          namespaces=NAMESPACES).text.replace('  ',' ').strip()

        last_name, first_name = fio.split(' ')[:2]

        employee_from_form = User.gql(
            "WHERE last_name = :last_name AND first_name = :first_name",
                                      last_name=last_name,
                                      first_name=first_name).get()

        if employee_from_form is None or \
            employee_from_form.email != employee.email:

            blob_info.delete()
            self.response.out.write('incorrect user')
            return

        date = datetime.datetime.strptime(date, '%d/%m/%Y').date()
        type = 'annual'
        description = "PR %s: %s-%s" % (type, date, date)

        month = datetime.timedelta(days=30)

        period = PerformanceReviewPeriod.gql("WHERE start_date >= \
                                            :min_start_date AND \
                                            start_date <= :max_start_date",
                                             max_start_date=date+month,
                                             min_start_date=date-month).get()
        if period is None:
            period = PerformanceReviewPeriod(start_date=date,
                                             finish_date=date,
                                             description=description,
                                             type=type)
            period.put()

        pr = PerformanceReview(employee=employee,
                               first_effective_date=employee.first_date,
                               manager=employee.manager,
                               period=period,
                               date=date)
        pr.put()

        manager_form = PerformanceReviewForm(pr=pr,
                                             status='approved',
                                     type='manager')
        manager_form.put()

        achievements = parser.findall(
                    './/w:body//ns0:AchievementMngList//ns0:Description//w:t',
                    namespaces=NAMESPACES)

        for achievement in achievements:

            achievement = achievement.text.replace('\n', '').replace('  ',' ')

            logging.debug(achievement)
            ach = Achievements(value=achievement,
                               form=manager_form)
            ach.put()

        challenges = parser.findall(
                    './/w:body//ns0:ChallengeMngList//ns0:Description//w:t',
                    namespaces=NAMESPACES)

        for challenge in challenges:

            challenge = challenge.text.replace('\n', '').replace('  ',' ')
            ch = Challenges(value=challenge,
                               form=manager_form)
            ch.put()

        goals = parser.findall(
                    './/w:body//ns0:NextYearGoalsMng//ns0:Goal//w:t',
                    namespaces=NAMESPACES)
        
        for goal in goals:

            goal = goal.text.replace('\n', '').replace('  ',' ')
            g = NextGoals(value=goal,
                               form=manager_form)
            g.put()

        blob_info.delete()
        self.response.out.write('done')