def __call__(self, environ, start_response): current_user = users.get_current_user() url = users.create_login_url("/") req = Request(environ) non_auth_urls = ['/create_role', '/p', '/users', '/add_emp', '/edit_user', '/upload_contacts', '/parse_xls'] if environ['PATH_INFO'] not in non_auth_urls: if current_user is None: try: auth_header = req.headers['Authorization'] except KeyError: resp = Response(status="307", location=url) return resp(environ, start_response) username, password = '', '' try: user_info = base64.decodestring(auth_header[6:]) username, password = user_info.split(':') except ValueError: resp = Response(status="401") return resp(environ, start_response) user_info = User.gql("WHERE username = :username ", username=username).get() if user_info is None: resp = Response(status="401") return resp(environ, start_response) if not check_password(password, user_info.password): resp = Response(status="401") return resp(environ, start_response) else: email = str(current_user.email()).strip() user_info = User.all().filter('email', email).get() if user_info is None: user_info = User( email=current_user.email()) user_info.put() environ["current_user"] = user_info try: environ["current_role"] = Model.get(user_info.role[0]).value except IndexError: environ["current_role"] = '' resp = req.get_response(self.app) return resp(environ, start_response)
def get(self): term = self.request.get('term') users = User.all().fetch(1000) users = filter(lambda x: x.email[:len(term)] == term, users) user_list = map(lambda x: x.email, users) user_list_json = simplejson.dumps(user_list) self.response.out.write(user_list_json)
def get(self): users = User.all().order('first_name').fetch(1000) for user in users: user.roles = '' for role in user.role: user.roles = user.roles + Model.get(role).value + ' ' upload_url_first_date = blobstore.create_upload_url('/upload_first_date') upload_url = blobstore.create_upload_url('/upload_contacts') self.template_values.update({'users': users, 'upload_url_first_date': upload_url_first_date, 'upload_url': upload_url}) self.response.out.write(template.render(self.path, self.template_values))
def get(self, key): users = User.all() managers = [] for user in users: for role in user.role: if Model.get(role).value == 'manager': managers.append(user) roles = [] if key: user = User.get(key) for role in user.role: roles.append(Role.get(role).value) else: user = None template_values = {'managers': managers, 'user': user, 'roles': roles} path = 'templates/new_user.html' self.response.out.write(template.render(path, template_values))
def post(self): upload_files = self.get_uploads('file') blob_info = upload_files[0] file = blob_info.open().read() wb = xlrd.open_workbook(file_contents=file) wb.sheet_names() sh = wb.sheet_by_index(0) cols_dict = {'name': 0, 'date': 1} for rownum in range(sh.nrows)[6:]: date = sh.cell_value(rownum, cols_dict['date']) - 2 first_date = datetime.date(year=1900, month=1, day=1) date = first_date + datetime.timedelta(days=date) name = sh.cell_value(rownum, cols_dict['name']).replace(' ', ' ') last_name, first_name = name.split(' ')[:2] user = User.all().filter('last_name', last_name).filter('first_name', first_name).get() if user: user.first_date = date user.put() else: logging.debug('last name: "%s" first_name: "%s" string: %s' %(last_name, first_name, name)) self.redirect('/users')
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()
def get(self): file_key = ContactXlsFile.all().get().file_key blob_info = blobstore.BlobInfo.get(file_key) file = blob_info.open().read() wb = xlrd.open_workbook(file_contents=file) wb.sheet_names() sh = wb.sheet_by_index(0) cols_dict = {'first_name': 1, 'last_name': 0, 'dept': 2, 'position': 3, 'email': 4, 'manager': 12} manager_dict = {} reg = "^\s+|\n|\r|\s+$" employee_role = Role.all().filter('value', 'employee').get().key() for rownum in range(sh.nrows)[6:]: email = sh.cell_value(rownum, cols_dict['email']).strip() user = User.all().filter('email', email).get() if user is None: user = User(email=email) user.put() if not user.role: user.role.append(employee_role) string_fields = ['first_name', 'last_name', 'position', ] for field in string_fields: value = re.sub(reg, '', sh.cell_value(rownum, cols_dict[field])) setattr(user, field, value) department_str = re.sub(reg, '', sh.cell_value(rownum, cols_dict['dept'])) department = Dept.all().filter('name', department_str).get() if department is None: department = Dept(name=department_str) department.put() user.dept = department user.put() manager_str = re.sub(reg, '', sh.cell_value(rownum, cols_dict['manager'])) manager_dict[user.key()] = manager_str manager_role = Role.all().filter('value', 'manager').get().key() for user_key in manager_dict: manager_str = manager_dict[user_key].replace(' ', ' ') if manager_str: last_name, first_name = manager_str.split(' ')[:2] manager = User.all().filter('last_name', last_name).filter('first_name', first_name).get() else: manager = None if manager is not None: if manager_role not in manager.role: manager.role.append(manager_role) manager.put() user = User.get(user_key) user.manager = manager user.put() self.redirect('/users')