Beispiel #1
0
 def get(self):
     profile = get_profile()
     template = jinjaEnvironment.get_template('template/rideroverview.html')
     template_values = make_user_links(self.request.uri)
     template_values['menu'] = make_menu(page='user/rideroverview')
     template_values['rides'] = BikeRide.query(ancestor=profile.key).order(-BikeRide.date).fetch(20)
     self.response.out.write(template.render(template_values))
Beispiel #2
0
    def get(self):
        error_list = []
        profile = get_profile()
        template_values = make_user_links(self.request.uri)
        key = self.request.get('key')
        # below test is a bit of a hack because an empty key is returned as the string 'None' sometimes
        if key and (key != 'None'):
            b_key = ndb.Key(urlsafe=key)
            bike = b_key.get()
            template_values['submitValue'] = 'Update'
            if bike:
                if b_key.parent() != profile.key:
                    error_list.append('Attempt to edit bike not owned by user')
            else:
                error_list.append('Bike not found')
        else:
            key = None
            bike = Bike()
            template_values['submitValue'] = 'Create'

        if len(error_list) > 0:
            logging.info('%s' % error_list)
            self.redirect('user/errorPage')
        else:
            template = jinjaEnvironment.get_template('template/bikeentry.html')
            template_values['menu'] = make_menu(page='user/bikeentry')
            bike_form = BikeForm(obj=bike)
            bike_form.bikeType.choices = [(bikeType.key.urlsafe(), bikeType.name) for bikeType in
                                          BikeType.query().fetch()]
            bike_form.bikeType.data = (bike.bikeType.urlsafe() if bike.bikeType else 0)
            template_values['form'] = bike_form
            template_values['key'] = key
            self.response.out.write(template.render(template_values))
Beispiel #3
0
    def get(self):
        profile = get_profile()
        template_values = make_user_links(self.request.uri)
        error_list = []
        key = self.request.get('key')
        if key and (key != 'None'):
            r_key = ndb.Key(urlsafe=key)
            bike_ride = r_key.get()
            template_values['submitValue'] = 'Update'
            if bike_ride:
                if r_key.parent() != profile.key:
                    error_list.append('Attempt to edit bikeRide not owned by user')
            else:
                error_list.append('bikeRide not found')
        else:
            key = None
            bike_ride = BikeRide()
            template_values['submitValue'] = 'Create'

        if len(error_list) > 0:
            logging.info('%s' % error_list)
            self.redirect('/user/errorPage')
        else:
            bike_ride_form = BikeRideForm(obj=bike_ride)
            bike_ride_form.bike.choices = [(bike.key.urlsafe(), bike.brand + ' ' + bike.model) for bike in
                                           Bike.query(ancestor=profile.key).fetch()]
            bike_ride_form.bike.data = (bike_ride.bike.urlsafe() if bike_ride.bike else 0)
            bike_ride_form.rideType.choices = [(rideType.key.urlsafe(), rideType.name) for rideType in
                                               RideType.query().fetch()]
            bike_ride_form.rideType.data = (bike_ride.rideType.urlsafe() if bike_ride.rideType else 0)
            template_values['form'] = bike_ride_form
            template = jinjaEnvironment.get_template('template/rideentry.html')
            template_values['menu'] = make_menu(page='user/rideentry')
            template_values['key'] = key
            self.response.out.write(template.render(template_values))
Beispiel #4
0
 def get(self):
     profile = get_profile()
     template = jinjaEnvironment.get_template('template/bikeoverview.html')
     template_values = make_user_links(self.request.uri)
     template_values['menu'] = make_menu(page='user/bikeoverview')
     template_values['bikes'] = Bike.query(ancestor=profile.key).fetch()
     template_values['biketypes'] = BikeType.query().fetch()
     self.response.out.write(template.render(template_values))
Beispiel #5
0
    def post(self):
        error_list = []
        profile = get_profile()
        key = self.request.get('key')
        if key and (key != 'None'):
            r_key = ndb.Key(urlsafe=key)
            bike_ride = r_key.get()
            if bike_ride:
                if r_key.parent() != profile.key:
                    error_list.append('Attempt to edit bikeRide not owned by user')
            else:
                error_list.append('bikeRide not found')
        else:
            bike_ride = BikeRide(parent=profile.key)

        if len(error_list) > 0:
            logging.info('%s' % error_list)
            self.redirect('/user/errorPage')
        else:
            form_data = BikeRideForm(self.request.POST, bike_ride)
            form_data.bike.choices = [(bike.key.urlsafe(), bike.brand) for bike in Bike.query().fetch()]
            form_data.rideType.choices = [(rideType.key.urlsafe(), rideType.name) for rideType in
                                          RideType.query().fetch()]
            logging.info("data from bikeride form is: %s", form_data)
            logging.info("data from the bikeride request is: %s", self.request)

            if form_data.validate():
                form_data.bike.data = ndb.Key(urlsafe=form_data.bike.data)
                form_data.rideType.data = ndb.Key(urlsafe=form_data.rideType.data)
                form_data.populate_obj(bike_ride)
                bike_ride.put()
                self.redirect('/user/rideroverview')
            else:
                template = jinjaEnvironment.get_template('template/rideentry.html')
                template_values = make_user_links(self.request.uri)
                template_values['menu'] = make_menu(page='user/rideentry')
                template_values['submitValue'] = 'Fix'
                template_values['form'] = form_data
                template_values['key'] = key
                self.response.out.write(template.render(template_values))
Beispiel #6
0
    def post(self):
        error_list = []
        profile = get_profile()
        key = self.request.get('key')
        if key and (key != 'None'):
            b_key = ndb.Key(urlsafe=key)
            bike = b_key.get()
            if bike:
                if b_key.parent() != profile.key:
                    error_list.append('Attempt to edit bike not owned by user')
            else:
                error_list.append('Bike not found')
        else:
            bike = Bike(parent=profile.key)

        if len(error_list) > 0:
            logging.info('%s' % error_list)
            self.redirect('user/errorPage')
        else:
            form_data = BikeForm(self.request.POST, bike)
            form_data.bikeType.choices = [(bikeType.key.urlsafe(), bikeType.name) for bikeType in
                                          BikeType.query().fetch()]
            logging.info('%s' % form_data.bikeType.data)

            if form_data.validate():
                # Save and redirect to bike overview page
                form_data.bikeType.data = ndb.Key(
                        urlsafe=form_data.bikeType.data)  # translate urlsafe key string to actual key
                form_data.populate_obj(bike)
                bike.put()
                self.redirect('/user/bikeoverview')
            else:
                # back to form for editing
                template = jinjaEnvironment.get_template('template/bikeentry.html')
                template_values = make_user_links(self.request.uri)
                template_values['menu'] = make_menu(page='user/bikeentry')
                template_values['submitValue'] = 'Fix'
                template_values['form'] = form_data
                template_values['key'] = key
                self.response.out.write(template.render(template_values))
Beispiel #7
0
import sys

from databricks_cli.secrets.api import SecretApi

from databrickslabs_jupyterlab.remote import connect

from helpers import get_profile

profile = get_profile()

try:
    apiclient = connect(profile)
    client = SecretApi(apiclient)
except Exception as ex:  # pylint: disable=broad-except
    print(ex)
    sys.exit(1)

client.create_scope("dbjl-pytest", None)
client.put_secret("dbjl-pytest", "pytest-key", "databrickslabs-jupyterlab", None)
 def setup_method(self):
     self.profile = get_profile()
     self.host, self.token = get_db_config(self.profile)
     self.log = logging.getLogger("TestEnd2End")
     self.log.info("Using %s on %s", EXE, ("AWS" if is_aws() else "Azure"))
Beispiel #9
0
th_box = int(img_gray.shape[0] * 0.007) * 2 + 1
th_box_div = 3
img_bin = cv2.adaptiveThreshold(img_gray.copy(), 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, th_box, th_box//th_box_div)
# if kernel_size is not None:
#     kernel = np.ones((kernel_size, kernel_size), np.uint8)
#     img_bin = cv2.erode(img_bin, kernel)
# best_bin = is_id(img_bin.copy())

rec_8 = get_8_parts(img_bin)
for r_num, r in enumerate(rec_8):
    x, y, w, h = r[0], r[1], r[2], r[3]

    cv2.rectangle(img_draw, (x, y), (x + w, y + h), (255, 0, 0), 1)

    img_dd = img_draw[y:y+h, x:x+w, :]  #.copy()
    best_c, name_best_c = get_profile(img_bin[y:y+h, x:x+w])
    if best_c is None:
        continue
    cv2.drawContours(img_dd, [best_c], -1, (0, 255, 0), 1)

    # cnt2res(best_c)
    hull = cv2.convexHull(best_c)
    cv2.drawContours(img_dd, hull, -1, (0, 0, 255), 3)
    hull2 = get_key_points(best_c, img_bin[y:y+h, x:x+w])
    # cv2.drawContours(img_dd, [hull2], -1, (100, 100, 255), 3)
    if not len(hull2.shape):
        continue
    # print(hull2.shape[0])
    for k, el in enumerate(hull2):
        if k + 1 == hull2.shape[0]:
            break