def update_service(service_id): all_service = Service.objects.with_id(service_id) if request.method == "GET": return render_template('update-service.html') elif request.method == "POST": form = request.form name = form['name'] yob = form['yob'] address = form['address'] phone = form['phone'] height = form['height'] status = form['status'] description = form['description'] measurements = form['measurements'] if form['gender'] == "male": gender = 1 elif form['gender'] == "female": gender = 0 new_service = Service(name=name, yob=yob, address=address, phone=phone, height=height, status=status, description=description, measurements=measurements, gender=gender) new_service.save() return redirect(url_for('admin'))
def creat(): if request.method == "GET": return render_template('new-service.html') elif request.method == "POST": form = request.form name = form['name'] yob = form['yob'] new_service = Service(name=name, yob=yob) new_service.save() return redirect(url_for('admin'))
def gender(): if request.method == "GET": return render_template('gender.html') elif request.method == "POST": form = request.form name = form['name'] yob = form['yob'] phone = form['phone'] if form['gender'] == "male": gender = 1 elif form['gender'] == "female": gender = 0 new_service = Service(name=name, yob=yob, phone=phone, gender=gender) new_service.save() return redirect(url_for('admin'))
def delete(service_id): service = Service.objects().with_id(service_id) if service is None: return "Not found" else: service.delete() return redirect(url_for('admin'))
def info(service_id): info_service = Service.objects().with_id(service_id) info_pic = info_service.game + '.jpg' info_account = info_service.account info_game = info_service.game info_price = info_service.price info_contact = info_service.contact info_occupied = info_service.occupied return render_template('info.html', info_pic=info_pic, info_account=info_account, info_game=info_game, info_price=info_price, info_contact=info_contact, info_occupied=info_occupied)
def service_page(): all_service = Service.objects() return render_template('service-page.html', all_service=all_service)
def remove_all(): all_service = Service.objects() all_service.delete() return redirect(url_for('admin'))
def admin(): all_service = Service.objects() return render_template('admin.html', all_service=all_service)
def customer(c): all_service = Service.objects(contacted=c, gender=1) return render_template('customer.html', all_service=all_service)
def search(g): all_service = Service.objects(gender=g) return render_template('search.html', all_service=all_service)
def admin(): return render_template('admin.html', services=Service.objects())
from Models.service import Service from random import randint, choice from faker import Faker import mlab mlab.connect() fake = Faker() # print(fake.address()) for i in range(50): print("Saving service", i + 1, "...") service = Service(name=fake.name(), gender=randint(0, 1), email=fake.email(), phone=fake.phone_number(), job=fake.job(), company=fake.company(), address=fake.address(), contacted=randint(0, 1)) service.save()
from Models.service import Service from random import randint, choice from faker import Faker import mlab mlab.connect() fake = Faker() # print(fake.address()) for i in range(50): print("Saving service", i+ 1, "...") service = Service(name=fake.name(), yob=randint(1999,2001), gender=randint(0,1), height=randint(150,190), phone=fake.phone_number(), address=fake.address(), status=choice([True,False])) service.save()
def search(game): filtered_services = Service.objects(game=game, occupied=False) return render_template('search.html', all_services=filtered_services)
def searchid(id): all_service = Service.objects(id=id) return render_template('searchid.html', all_service=all_service)
# mlab_connect() # # Service.drop_collection() # # for _ in range(7): # service = Service(account = choice([new_lol_accounts]), # password = randint(100, 999), # game = "lol", # price = choice(["1000/h", "1500/h", "2000/h"]), # contact = 0 + randint(100000000, 999999999), # occupied = choice([True, False])) # service.save() from mlab import mlab_connect from Models.service import Service from faker import Faker from random import randint, choice service_faker = Faker() mlab_connect() Service.drop_collection() for _ in range(30): service = Service(account=service_faker.name(), game=choice(["lol", "csgo", "pubg"]), price=choice(["1000/h", "1500/h", "2000/h"]), contact=0 + randint(100000000, 999999999), password=randint(100, 999), occupied=choice([True, False])) service.save()
from Models.service import Service import mlab mlab.connect() all_service = Service.objects(contacted='true') all_service = Service.objects(contacted='false') for index, service in enumerate(all_service): print(service['name']) if index == 9: break
from Models.service import Service from random import randint, choice from faker import Faker import mlab mlab.connect() fake = Faker() # print(fake.address()) for i in range(50): print("Saving service", i + 1, "...") service = Service(name=fake.name(), yob=randint(1999, 2001), gender=randint(0, 1), height=randint(150, 190), phone=fake.phone_number(), address=fake.address(), status=choice([True, False]), description=choice( ["ngoan hiền", "dễ thương", "lễ phép với gia đình"]), measurements=randint(60, 90)) service.save()
def search(g): all_service = Service.objects(gender=g, yob__lte=2000, address__icontains="Hà Nội") return render_template('search.html', all_service=all_service)