def add_employee(request, template_name='retailer/employee/add_employee.html'): if request.method == 'POST': form = NewEmployeeForm(request.POST) if form.is_valid(): employees = request.user.retailer.employees username_exists = employees.filter(username=form.cleaned_data['username']) if username_exists.exists(): form._errors['username'].append('Username already exists') else: employee = Employee() employee.first_name = form.cleaned_data['first_name'] employee.last_name = form.cleaned_data['last_name'] employee.username = form.cleaned_data['username'] employee.retailer = request.user.retailer employee.save() return HttpResponseRedirect(reverse('manage_employees')) else: form = NewEmployeeForm() vars = RequestContext(request, { 'form':form }) return render_to_response(template_name, vars)
def query_text(message): roles = { 'Житель города': { 'greet': 'Отлично, Вы житель!', 'role': 0 }, 'Старший по дому': { 'greet': 'Добро пожаловать!', 'role': 1 }, 'Сотрудник УК/ТСЖ': { 'greet': 'Приятно поработать!', 'role': 2 }, } with open(settings.MEDIA_ROOT + f'{message.chat.id}.txt', 'a') as f: f.writelines([str(roles[message.text]['role']) + '\n']) bot.send_message(message.chat.id, roles[message.text]['greet']) if message.text != 'Сотрудник УК/ТСЖ': markup = types.ReplyKeyboardMarkup(row_width=1) geo_button = types.KeyboardButton(text="Отправить местоположение", request_location=True) markup.add(geo_button) bot.send_message(message.chat.id, "Нажмите на кнопку и передайте координаты.", reply_markup=markup) bot.register_next_step_handler(message, location) else: lines = [ line for line in open(settings.MEDIA_ROOT + f'{message.chat.id}.txt') ] employee = Employee( external_id=lines[0], surname=lines[1], name=lines[2], tg_role=roles[message.text]['role'], position_id=random.choice([1, 2]) ) # TODO Хреновая реализация, но для ускорения разработки пока так employee.save() org = Organization.objects.get(pk=1) employee.organizations.add(org) delete_file(settings.MEDIA_ROOT + f'{message.chat.id}.txt') bot.send_message(message.chat.id, "Здесь Вы будете получать заявки для выполнения.", reply_markup=types.ReplyKeyboardRemove())
mobile="0987654321", ssn="E123456722", birthday="1980-02-01") pAccount2.save() pAccount3 = Contact(name="Jack", title="staff", address="Kaohsiung", phone="073234567", mobile="0987654321", ssn="E123456733", birthday="1980-03-01") pAccount3.save() pAccount4 = Contact(name="Jane", title="staff", address="Tainan", phone="063234567", mobile="0987654321", ssn="E123456744", birthday="1980-04-01") pAccount4.save() pAccountC1 = Company(name="Company A",) pAccountC1.save() pAccountC2 = Company(name="Company B",) pAccountC2.save() pAccountE1 = Employee(contact=pAccount1) pAccountE1.save() pAccountE2 = Employee(contact=pAccount2) pAccountE2.save() pAccountE3 = Employee(contact=pAccount3) pAccountE3.save() pAccountE4 = Employee(contact=pAccount4) pAccountE4.save() #project設定 pProject1 = Project(contact=pAccount1, company=pAccountC1, name="SkyTower") pProject1.save() pProject2 = Project(contact=pAccount2, company=pAccountC2, name="MoonLand") pProject2.save() pProjectA1 = Assignment(project=pProject1, comment="",
def main(request): c = base_context(request) template = get_template("index.html") c['title'] = _('Request') form = RequestForm() # if user is authenticated user = request.user c['user'] = user if user.is_authenticated(): e = Employee.objects.filter(user=user) if e: empl = e[0] form = RequestForm(initial={'fio': empl.fio, 'tab_number': empl.tab_number, 'post': empl.post, 'cabinet': empl.cabinet}) c['logout'] = True c['form'] = form if request.method == 'POST': postdata = request.POST.copy() form = RequestForm(request.POST) if form.is_valid(): empl = Employee.objects.filter(tab_number = postdata.get('tab_number', 0)) if not empl: # django user --- if user.is_authenticated(): # logout logout(request) username = postdata.get('fio', 'error!') password = postdata.get('tab_number', 0) User.objects.create_user(username, '*****@*****.**', password) # login new_user = authenticate(username=username, password=password) if new_user: login(request, new_user) # amortization user empl = Employee() empl.tab_number = postdata.get('tab_number', 0) empl.fio = postdata.get('fio', "error!") empl.user = new_user empl.post = postdata.get('post', '') empl.cabinet = postdata.get('cabinet', '0-000') empl.save() uid = empl else: uid = empl[0] user = authenticate(username=uid.user.username, password=uid.tab_number) if user: login(request, user) req = Request() req.user = uid req.number = postdata.get('number', '000000000000') req.device = postdata.get('device', 'NoName') req.serial = postdata.get('serial', '') req.year = postdata.get('year', '----') req.save() c['saved'] = True else: c['form'] = form return HttpResponse(template.render(Context(c)))
pAccount4 = Contact(name="Jane", title="staff", address="Tainan", phone="063234567", mobile="0987654321", ssn="E123456744", birthday="1980-04-01") pAccount4.save() pAccountC1 = Company(name="Company A", ) pAccountC1.save() pAccountC2 = Company(name="Company B", ) pAccountC2.save() pAccountE1 = Employee(contact=pAccount1) pAccountE1.save() pAccountE2 = Employee(contact=pAccount2) pAccountE2.save() pAccountE3 = Employee(contact=pAccount3) pAccountE3.save() pAccountE4 = Employee(contact=pAccount4) pAccountE4.save() #project設定 pProject1 = Project(contact=pAccount1, company=pAccountC1, name="SkyTower") pProject1.save() pProject2 = Project(contact=pAccount2, company=pAccountC2, name="MoonLand") pProject2.save() pProjectA1 = Assignment(project=pProject1, comment="",
download_image( school.name, school.school_avatar, school_names_and_avatars[school_names[i]]) school.save() print("Finished populating Schools") ### # Populating precreated Employees for employee_name in random_employee_names: first_name = employee_name.split(' ')[0] last_name = employee_name.split(' ')[1] if not Employee.objects.filter(first_name=first_name, last_name=last_name, email=first_name+last_name+"@capitalone.com"): employee = Employee(first_name=first_name, last_name=last_name, email=first_name+last_name + "@capitalone.com", position="Supervisor") employee.set_password("123") employee.save() try: confirmation_key = employee.confirmation_key except: confirmation_key = employee.add_unconfirmed_email(employee.email) employee.confirm_email(confirmation_key) print("Finished populating Employees") ### # Populating precreated projects employee_list = list(Employee.objects.all()) for i in range(len(project_names_and_avatars)): if not Project.manager.filter(title=project_names[i]): project = Project(title=project_names[ i], brief_description=brief_description, description=description, github=project_github_repos[i], trello=project_trello_pages[i])