def get(self): user = self.user_info real_user_id = user.get('user_id') q = Building.query() buildings = q.fetch() some_json = [] for building in buildings: some_json.append(OrderedDict([('lat', float(building.lat)), ('lng', float(building.lng)), ('content', building.uuid)])) mirakuru = json.dumps(some_json) admin = user.get('isAdmin') if admin is True: template_values = { 'buildings': buildings, 'mirakuru': mirakuru, 'user': user, 'admin': admin, } else: template_values = { 'buildings': buildings, 'mirakuru': mirakuru, 'user': user, } path = os.path.join(os.path.dirname(__file__), 'templates/view-buildings.html') self.response.write(template.render(path, template_values))
def post(self, uuid): tenant = Tenant() tenant.uuid = uuid1().get_hex() tenant.tenant_name = self.request.get('tenant_name') tenant.address = self.request.get('address') tenant.cell = self.request.get('cell') tenant.email = self.request.get('email') tenant.contact_person = self.request.get('contact_person') tenant.contact_phone = self.request.get('contact_phone') unconverted_date = self.request.get('kurcina') converted_date = datetime.strptime(unconverted_date, '%d-%m-%Y') tenant.lease_expire = converted_date users.get_current_user() user = self.user_info tenant.brokers_name = user.get('user_name') user_id = user.get('user_id') tenant.user = ndb.Key(User, user_id) tenant.building_uuid = uuid building = Building.query(Building.uuid == uuid).get() building_id = building.key.id() tenant.building = ndb.Key(Building, building_id) marcipan = tenant.put() time.sleep(2) kurcina = marcipan.id() mrgud = ndb.Key(Tenant, kurcina) building.tenants.append(mrgud) building.last_updated = datetime.now() building.put() time.sleep(2) self.redirect('/viewtenants/' + uuid)
def post(self, uuid): landlord = Landlord() landlord.uuid = uuid1().get_hex() landlord.building_uuid = uuid landlord.cell = self.request.get('cell') landlord.email = self.request.get('email') landlord.contact_phone = self.request.get('contact_phone') landlord.contact_person = self.request.get('contact_person') landlord.budget = int(self.request.get('budget')) unconverted_date = self.request.get('kurcina') converted_date = datetime.strptime(unconverted_date, '%d-%m-%Y') landlord.last_contact = converted_date users.get_current_user() user = self.user_info landlord.brokers_name = user.get('user_name') user_id = user.get('user_id') landlord.user = ndb.Key(User, user_id) buildingz = Building.query(Building.uuid == uuid).get() building_id = buildingz.key.id() landlord.building = ndb.Key(Building, building_id) marcipan = landlord.put() time.sleep(2) kurcina = marcipan.id() mrgud = ndb.Key(Landlord, kurcina) buildingz.landlord = mrgud buildingz.last_updated = datetime.now() buildingz.put() time.sleep(2) self.redirect('/landlords')
def get(self): user = self.user_info real_user_id = user.get('user_id') key = ndb.Key(User, real_user_id) q = Building.query(Building.user == key) buildings = q.fetch() kurac = [] for building in buildings: #print building.tenants kurac.append(len(building.tenants)) print kurac #print buildings print len(kurac) print kurac admin = user.get('isAdmin') if admin is True: template_values = { 'kurac': kurac, 'buildings': buildings, 'user': user, 'admin': admin, } else: template_values = { 'kurac': kurac, 'buildings': buildings, 'user': user, } path = os.path.join(os.path.dirname(__file__), 'templates/view-buildings-list.html') self.response.write(template.render(path, template_values))
def get(self, uuid): tenant = Tenant.query(Tenant.uuid == uuid).get() tenant_id = tenant.key.id() tenant_key = ndb.Key(Tenant, tenant_id) building_tenant = Building.query(Building.tenants == tenant_key).get() if tenant: tenant.key.delete() building_tenant.tenants.remove(tenant_key) building_tenant.put() self.redirect('/tenants') else: self.abort(404)
def get(self, uuid): landlord = Landlord.query(Landlord.uuid == uuid).get() landlord_id = landlord.key.id() landlord_key = ndb.Key(Landlord, landlord_id) building_landlord = Building.query(Building.tenants == landlord_key).get() if landlord: landlord.key.delete() building_landlord.landlord.remove(landlord_key) building_landlord.put() self.redirect('/landlords') else: self.abort(404)
def post(self, uuid): landlord = Landlord.query(Landlord.uuid == uuid).get() building = Building.query(Building.user == landlord.key()).get() building.last_updated = datetime.now() building.put() landlord.budget = int(self.request.get('budget')) landlord.cell = self.request.get('cell') landlord.email = self.request.get('email') landlord.contact_phone = self.request.get('contact_phone') landlord.contact_person = self.request.get('contact_person') unconverted_date = self.request.get('kurcina') if unconverted_date: converted_date = datetime.strptime(unconverted_date, '%d-%m-%Y') landlord.last_contact = converted_date landlord.put() self.redirect('/landlord')
def get(self, uuid): building = Building.query(Building.uuid == uuid).get() tenant = Tenant.query(Tenant.building_uuid == uuid).get() landlord = Landlord.query(Landlord.building_uuid == uuid).get() if building: building.key.delete() if tenant: tenant.key.delete() else: self.redirect("/viewbuildings-list") if landlord: landlord.key.delete() else: self.redirect("/viewbuildings-list") self.redirect("/viewbuildings-list") else: self.abort(403)
def get(self, uuid): user = self.user_info admin = user.get('isAdmin') building = Building.query(Building.uuid == uuid).get() if admin is True: template_values = { 'building': building, 'user': user, 'admin': admin, } else: template_values = { 'building': building, 'user': user, } path = os.path.join(os.path.dirname(__file__), 'templates/add-landlord.html') self.response.write(template.render(path, template_values))
def post(self, uuid): note = LandlordNote() landlord = Landlord.query(Landlord.uuid == uuid).get() landlord_id = landlord.key.id() building = Building.query(Building.user == landlord.key()).get() building.last_updated = datetime.now() building.put() note.landlord = ndb.Key(Landlord, landlord_id) note.landlord_uuid = uuid note.text = self.request.get('description') real_note = note.put() real_note_key = real_note.id() idzor = real_note_key mrav = ndb.Key(LandlordNote, idzor) landlord.notes.append(mrav) landlord.put() self.redirect('/landlords')
def get(self, uuid): user = self.user_info admin = user.get('isAdmin') files = Landlord.query(Landlord.building_uuid == uuid) building = Building.query(Building.uuid == uuid).get() landlords = files.order(-Landlord.contact_person).fetch() if admin is True: template_values = { 'user': user, 'building': building, 'landlords': landlords, 'admin': admin, } else: template_values = { 'user': user, 'building': building, 'landlords': landlords, } path = os.path.join(os.path.dirname(__file__), 'templates/l-dashboard-2.html') self.response.write(template.render(path, template_values))
def get(self, uuid): user = self.user_info building = Building.query(Building.uuid == uuid).get() serve_me = images.get_serving_url(building.picture, size=None, crop=False, secure_url=None) tenants = [] if building.tenants: for tenant in building.tenants: kurac = tenant.id() tenant = Tenant.get_by_id(kurac) tenants.append(tenant) else: tenant = None if building.landlord: smajser = building.landlord.id() landlord = Landlord.get_by_id(smajser) else: landlord = None admin = user.get('isAdmin') if admin is True: template_values = { 'landlord': landlord, 'serve_me': serve_me, 'building': building, 'user': user, 'admin': admin, 'tenants': tenants, } else: template_values = { 'landlord': landlord, 'serve_me': serve_me, 'building': building, 'user': user, } path = os.path.join(os.path.dirname(__file__), 'templates/view-building.html') self.response.write(template.render(path, template_values))
def get(self, uuid): user = self.user_info admin = user.get('isAdmin') files = Tenant.query(Tenant.building_uuid == uuid) building = Building.query(Building.uuid == uuid).get() tenants = files.order(-Tenant.contact_person).fetch() if admin is True: template_values = { #'list_list': list_list, 'user': user, 'building': building, 'tenants': tenants, 'admin': admin, } else: template_values = { #'list_list': list_list, 'user': user, 'building': building, 'tenants': tenants, } path = os.path.join(os.path.dirname(__file__), 'templates/dashboard-2.html') self.response.write(template.render(path, template_values))
def post(self, uuid): user = self.user_info print user user_uuid = user.get('uuid') user_object = User.query(User.uuid == user_uuid).get() real_key = user_object.key.id() real_user_key = ndb.Key(User, real_key) building = Building.query(Building.user == real_user_key).get() building.last_updated = datetime.now() building.put() note = TenantNote() tenant = Tenant.query(Tenant.uuid == uuid).get() tenant_id = tenant.key.id() note.tenant = ndb.Key(Tenant, tenant_id) note.tenant_uuid = uuid note.text = self.request.get('description') real_note = note.put() real_note_key = real_note.id() idzor = real_note_key mrav = ndb.Key(TenantNote, idzor) tenant.notes.append(mrav) tenant.put() self.redirect('/tenants')
def post(self): user = users.get_current_user() if user: missedLectureCheck(user) #logging.info(self.request.body) data = json.loads(self.request.body) latitude = data["lat"] longitude = data["lon"] day = datetime.date.today().weekday() hour = datetime.datetime.now().hour minute = datetime.datetime.now().minute if minute > 45: hour = hour + 1 thisLecture = None thisUser = None poly = [] userQuery = User.query(User.userid == user.user_id()) for userEntity in userQuery: thisUser = userEntity for lecture in userEntity.lectures: #checks for a lecture that matches the current day and time if(lecture.day == day and (lecture.time <= hour and lecture.time + lecture.duration > hour)): thisLecture = lecture locations = lecture.location.split(";"); for location in locations: #need to make multiple polys for each lecture, for each possible location buildingQuery = Building.query(Building.number == location) for building in buildingQuery: buildingCoords = [] for coordinate in building.coordinates: c = (coordinate.lon, coordinate.lat) buildingCoords.append(c) poly.append(buildingCoords) noLecture = False checkedIn = False #checks if there is no current lecture if thisLecture is None: noLecture = True self.response.out.write(json.dumps({"valid":3})) else: #checks if the user has already checked in to this lecture for pastLecture in thisUser.history: if pastLecture.week == getCurrentWeek() and pastLecture.time == thisLecture.time and pastLecture.day == thisLecture.day: checkedIn = True if checkedIn: self.response.out.write(json.dumps({"valid":4})) if not checkedIn and not noLecture: inBuilding = False for coords in poly: #checks user is at the correct location(s) for the lecture if not inBuilding and point_in_poly(longitude, latitude, coords): inBuilding = True attendedLecture = Lecture(module=thisLecture.module, title=thisLecture.title, location=thisLecture.location, day=thisLecture.day, time=thisLecture.time, duration=thisLecture.duration) attendedLecture.attended = True attendedLecture.week = getCurrentWeek() checkin = CheckIn(student=thisUser, lecture=attendedLecture) checkin.put() thisUser.history.append(attendedLecture) completedChalls = challengecheck(thisUser, attendedLecture, checkin) pointsEarned = 0 challIcons = [] challTitles = [] challDescs = [] challPoints = [] for challenge in completedChalls: pointsEarned += challenge.points challTitles.append(challenge.title) challIcons.append(challenge.badge.iconName) challDescs.append(challenge.description) challPoints.append(challenge.points) thisUser.score = thisUser.score + 10 + thisUser.streak + pointsEarned thisUser.streak = thisUser.streak + 1 thisUser.count = thisUser.count + 1 thisUser.put() self.response.out.write(json.dumps({"valid":1, "score":thisUser.score, "count":thisUser.count, "streak":thisUser.streak, "icons":challIcons, "titles":challTitles, "points":challPoints, "descriptions":challDescs})) if not inBuilding: self.response.out.write(json.dumps({"valid":2})) else: self.redirect(users.create_login_url(self.request.uri))