Esempio n. 1
0
def load_notes():
    req = ajax.Ajax()
    req.bind('loading', query_notes)
    req.bind('complete', on_load_notes)
    req.open('POST', '/load_notes', True)
    req.set_header('content-type', 'application/x-www-form-urlencoded')
    req.send()
Esempio n. 2
0
def pessoa_curso(ev):
    exec(document['submit'].value)
    req = ajax.Ajax()
    curso = document['curso'].value
    ID_pessoa = document['id_pcurso'].value
    url = 'http://127.0.0.1:5000/pessoas/curso'
    window.location.href = (url + "?id=%s&Curso=%s" % (ID_pessoa, curso))
Esempio n. 3
0
    def save(self):
        self.time_stamp.innerHTML = self.modify_date(datetime.now())

        req = ajax.Ajax()
        req.open('POST', '/save_note', True)
        req.set_header('content-type', 'application/x-www-form-urlencoded')
        req.send(repr(self))
Esempio n. 4
0
def delete(e):
    id = document.location.pathname.split('/')[-1]
    url = 'http://127.0.0.1:5000/api/indicator/' + id
    req = ajax.Ajax()
    req.bind('complete', delete_data)
    req.open('DELETE', url, True)
    req.send('')
Esempio n. 5
0
def delete_comment(e):
    id = e.target.parent.parent.parent.attrs['id']
    url = 'http://127.0.0.1:5000/api/comment/'+id
    req = ajax.Ajax()
    req.bind('complete', output_data)
    req.open('DELETE', url, True)
    req.send('')
Esempio n. 6
0
def change_state(task_id, new_state):
    json = {'state': new_state}

    req = ajax.Ajax()
    req.open('PATCH', f'/tasks/{task_id}', True)
    req.set_header('content-type', 'application/json')
    req.send(JSON.stringify(json))
    return req
Esempio n. 7
0
def send_question_json(answer):
    req = ajax.Ajax()
    req.bind('complete', display_text_question)
    req.open('POST',
                '/ask',
                True)
    req.set_header('Content-Type', 'application/json')
    req.send(json.dumps(answer))
Esempio n. 8
0
def get_user_info(ev):
    req = ajax.Ajax()
    req.bind('complete', on_complete)
    req.open('GET', '172.16.3.86:8080/')
    sel = document['user_id'].options
    selected = [option.value for option in sel if option.selected]
    console.log(selected[0])
    req.send()
Esempio n. 9
0
def request(url, json, bind, method='POST'):
    """Send json data to backend."""
    req = ajax.Ajax()
    req.bind('complete', bind)
    req.open(method, url, True)
    req.set_header('content-type', 'application/json')
    req.send(JSON.stringify(json))
    return req
Esempio n. 10
0
def send_coefficient_json(coefficients):
    req = ajax.Ajax()
    req.bind('complete', display_solutions)
    req.open('POST',
                '/solve',
                True)
    req.set_header('Content-Type', 'application/json')
    req.send(json.dumps(coefficients))
Esempio n. 11
0
def sign_up(event):
    first_name = sign_up_first_name.value
    last_name = sign_up_last_name.value
    email = sign_up_email.value
    password = sign_up_password.value

    if not first_name and not last_name and not email and not password:
        show_toast("You Didn't Enter Anything", "sign up", "error")

        return
    elif not first_name:
        show_toast("You Didn't Enter Your First Name", "sign up", "error")

        return
    elif not last_name:
        show_toast("You Didn't Enter Your Last Name", "sign up", "error")

        return
    elif not email:
        show_toast("You Didn't Enter An Email", "sign up", "error")

        return
    elif not password:
        show_toast("You Didn't Enter A Password", "sign up", "error")

        return
    elif not validate_name(first_name):
        show_toast("First Name Is Invalid", "sign up", "validate")

        return
    elif not validate_name(last_name):
        show_toast("Last Name Is Invalid", "sign up", "validate")

        return
    elif not validate_email(email):
        show_toast("Email Is Invalid", "sign up", "validate")

        return
    elif not validate_password(password):
        show_toast(
            "Password Must Have:<br>" +
            "At Least 8 Characters<br>" +
            "1 Number<br>" +
            "1 Uppercase Letter<br>" +
            "1 Special Character",
            "sign up",
            "validate")

        return
    else:
        req = ajax.Ajax()
        req.bind('loading', on_send_sign_up)
        req.bind('complete', on_sign_up)
        req.open('POST', '/sign_up', True)
        req.set_header('content-type', 'application/x-www-form-urlencoded')
        req.send(
            {'first_name': first_name, 'last_name': last_name, 'email': email,
             'password': password})
Esempio n. 12
0
def getData(aa):
    url = document['url'].value
    req = ajax.Ajax()
    req.bind('complete', on_complete)
    # send a POST request to the url
    req.open('GET', url, True)
    req.set_header('content-type', 'application/x-www-form-urlencoded')
    # send data as a dictionary
    req.send({'x': 0, 'y': 1})
Esempio n. 13
0
def submit(ev):
    exec(document['submit'].value)
    req = ajax.Ajax()
    nome = document['Nome'].value
    telefone = document['Telefone'].value
    cpf = document['CPF'].value
    #req.bind('complete',on_complete(req))
    # pass the arguments in the query string
    url = 'http://127.0.0.1:5000/pessoas/add'
    window.location.href = (url + "?Nome=%s&Telefone=%s&CPF=%s" %
                            (nome, telefone, cpf))
Esempio n. 14
0
def indicator_editing(e):
    id = document.location.pathname.split('/')[-1]
    url = 'http://127.0.0.1:5000/api/indicator/' + id
    data = {
        'cold': int(document['form_admin_indicator_cold'].value),
        'hot': int(document['form_admin_indicator_hot'].value),
        'user_id': int(document['form_admin_indicator_user'].value)
    }
    req = ajax.Ajax()
    req.bind('complete', output_data)
    req.open('PUT', url, True)
    req.send(json.dumps(data))
Esempio n. 15
0
def edit_user(e):
    id = document.location.pathname.split('/')[-1]
    url = 'http://127.0.0.1:5000/api/owner/' + id
    data = {
        'apartment': document['form_admin_user_apart'].value,
        'email': document['form_admin_user_email'].value,
        'phone_number': document['form_admin_user_tel'].value
    }
    req = ajax.Ajax()
    req.bind('complete', output_data)
    req.open('PUT', url, True)
    req.send(json.dumps(data))
Esempio n. 16
0
def post_editing(e):
    id = document.location.pathname.split('/')[-1]
    url = 'http://127.0.0.1:5000/api/post/' + id
    data = {
        'header': document['form_admin_post_header'].value,
        'url': document['form_admin_post_url'].value,
        'tag': document['form_admin_post_tag'].value,
        'cardtext': document['form_admin_post_cardtext'].value,
        'htmltext': document['form_admin_post_html'].value
    }
    req = ajax.Ajax()
    req.bind('complete', delete_data)
    req.open('PUT', url, True)
    req.send(json.dumps(data))
Esempio n. 17
0
def test_browser_ajax():
    from browser import document, ajax

    def on_complete(req):
        if req.status == 200 or req.status == 0:
            document["result"].html = req.text
        else:
            document["result"].html = "error " + req.text

    url = ""
    req = ajax.Ajax()
    req.bind('complete', on_complete)
    # send a POST request to the url
    req.open('POST', url, True)
    req.set_header('content-type', 'application/x-www-form-urlencoded')
    # send data as a dictionary
    req.send({'x': 0, 'y': 1})

    from browser import document, ajax

    def on_complete(req):
        if req.status == 200:
            document["result"].html = req.text
        else:
            document["result"].html = "error " + req.text

    ajax.post(url, data={'x': 0, 'y': 1}, oncomplete=on_complete)

    from browser import ajax

    def read(f):
        data = f.read()
        assert isinstance(data, bytes)

    req = ajax.get("tests.zip", mode="binary", oncomplete=read)

    from browser import ajax, bind, document

    def upload_ok(req):
        print("all right")

    @bind("#upload", "click")
    def uploadfiles(event):
        for f in document["choosefiles"].files:
            ajax.file_upload("/cgi-bin/savefile.py", f, oncomplete=upload_ok)
        assert True

    uploadfiles(evt)  ## added
Esempio n. 18
0
def get_images_url(card: str, on_result):
    # TODO Cache
    def parse(response):
        start = response.text.index('small')
        start += len('small') + 3
        end = response.text.index(',', start)
        end -= 1
        image_url = response.text[start:end]
        on_result(image_url)

    request = ajax.Ajax()
    request.bind('complete', parse)
    request.open(
        'GET',
        'https://api.scryfall.com/cards/named?exact=' + card.replace(' ', '+'))
    request.send()
Esempio n. 19
0
  def send(self, data):
    """ Send data to the server (via websocket or AJAX) """

    if USE_WEBSOCKETS:
      self.socket.send(json.dumps(data))
    else:
      req = ajax.Ajax(HTTP_URL, method='POST')

      @req.complete
      def success():
        if req.status == 200 or req.status == 0:
          data = json.loads(req.text)
          self.recv(data)

      req.set_header('content-type', 'application/json')
      req.send(json.dumps(data))
Esempio n. 20
0
def wikicene_request():
    term = search_bar.value
    if term:
        global start_ts

        # fetch selected options and build url
        analyzer_type = get_selected_option(analyzer_selector)
        query_type = get_selected_option(query_selector)
        url = wikicene_url_template.format(term=term,
                                           analyzer_type=analyzer_type,
                                           query_type=query_type)

        if analyzer_type == "custom":

            # add the tokenizer of the custom analyzer
            tokenizer = get_selected_option(tokenizer_selector)
            url += "&tokenizer={}".format(tokenizer)

            # add token filters
            for token_filter in get_selected_options(token_filter_selector):
                url += "&tokenFilter={}".format(token_filter)

        # add the fields to use when matching (e.g. title, summary)
        for field in get_selected_options(field_selector):
            url += "&queryField={}".format(field)

        # add max edit distance parameter for fuzzy queries
        if query_type == "fuzzy":
            max_edit_dist = get_selected_option(max_dist_selector)
            url += "&maxEdits={}".format(max_edit_dist)

        # create and send an ajax request
        req = ajax.Ajax()
        req.bind("complete", on_wikicine_response)
        req.open("GET", url, True)
        start_ts = time.time()
        req.send()
    elif results.text:
        results.clear()
        debug.text = default_debug_message
Esempio n. 21
0
def init():
    def on_complete(request):
        print(request.responseText)
        data = json.loads(request.responseText)
        canvas.height = data['height'] * 15
        canvas.width = data['width'] * 15
        for i in range(len(data['field'])):
            for j in range(len(data['field'][i])):
                ctx.beginPath()
                ctx.rect(j * 15, i * 15, 15, 15)
                ctx.fillStyle = COLORS[data['field'][i][j]]
                print(COLORS[data['field'][i][j]])
                ctx.fill()
                ctx.beginPath()
                ctx.rect(j * 15, i * 15, 15, 15)
                ctx.stroke()

    print(1)
    req = ajax.Ajax()
    req.bind('complete', on_complete)
    req.open('POST', '/api/get_initial_config', True)
    req.send()
Esempio n. 22
0
def log_in(event):
    email = log_in_email.value
    password = log_in_password.value

    if not email and not password:
        show_toast("You Didn't Enter Anything", "log in", "error")

        return
    elif not email:
        show_toast("You Didn't Enter Your Email", "log in", "error")

        return
    elif not password:
        show_toast("You Didn't Enter Your Password", "log in", "error")

        return
    else:
        req = ajax.Ajax()
        req.bind('loading', on_send_log_in)
        req.bind('complete', on_log_in)
        req.open('POST', '/log_in', True)
        req.set_header('content-type', 'application/x-www-form-urlencoded')
        req.send({'email': email, 'password': password})
Esempio n. 23
0
def add_note(event):
    global logged_in
    global notes
    global highest_z
    global highest_id

    color_bar_display = color_bar.style.display
    search_bar_display = search_bar.style.display

    if color_bar_display == 'block':
        event = window.MouseEvent.new('click')

        color_changer.dispatchEvent(event)
    elif search_bar_display == 'block':
        event = window.MouseEvent.new('click')

        end_search_button.dispatchEvent(event)

    left = str(random.randint(48, 150)) + 'px'
    top = str(random.randint(48, 150)) + 'px'

    z_index = highest_z
    highest_z = highest_z + 1

    if logged_in:  # Add note to database
        req = ajax.Ajax()
        req.bind('complete', on_create_note)
        req.open('POST', '/create_note', True)
        req.set_header('content-type', 'application/x-www-form-urlencoded')
        req.send({'left': left, 'top': top, 'z_index': str(z_index)})
    else:
        sticky_note_id = highest_id
        highest_id = highest_id + 1

        sticky_note_builder(left, top, z_index, sticky_note_id, None, '', 0,
                            None, None, None)
Esempio n. 24
0
 def close(self, event):
     req = ajax.Ajax()
     req.bind('complete', self.on_close)
     req.open('POST', '/close_note', True)
     req.set_header('content-type', 'application/x-www-form-urlencoded')
     req.send({'id': self.get_id()})
Esempio n. 25
0
def delete(ev):
    exec(document['delete'].value)
    req = ajax.Ajax()
    id = document['id'].value
    url = ('http://127.0.0.1:5000/pessoas/delete?id=%s' % (id))
    window.location.href = url
Esempio n. 26
0
def show_all(ev):
    exec(document['all_students'].value)
    req = ajax.Ajax()
    url = 'http://127.0.0.1:5000/pessoas/all'
    window.location.href = url
Esempio n. 27
0
def log_out(event):
    req = ajax.Ajax()
    req.bind('complete', on_log_out)
    req.open('POST', '/log_out', True)
    req.send()
Esempio n. 28
0
def change_state(task_id, new_state):
    req = ajax.Ajax()
    req.open('PATCH', f'/change-state/{task_id}/{new_state}', True)
    req.set_header('content-type', 'application/json')
    req.send()
Esempio n. 29
0
ajax.get('../brython.png', mode="binary", oncomplete=read_image)
ajax.get('../brython.png', mode="binary", oncomplete=read_image, blocking=True)

# ajax.post
ajax.post("/cgi-bin/post_test.py",
          oncomplete=lambda req: show(req, "bar:38"),
          data={'bar': 38})

ajax.post("/cgi-bin/post_test.py",
          headers={'Content-Type': "application/x-www-form-urlencoded"},
          oncomplete=lambda req: show(req, "bar:38"),
          data={'bar': 38})

# DOM style
req = ajax.Ajax()
req.open("GET", "files/text-latin1.txt")
req.encoding = 'latin-1'
req.bind("complete", lambda req: show(req, "bébé"))
req.send()

req = ajax.Ajax()
req.open("GET", "files/text-latin1.txt", False)
req.encoding = 'latin-1'
req.bind("complete", lambda req: show(req, "bébé"))
req.send()

req = ajax.Ajax()
req.open("GET", "files/text-utf8.txt", False)
req.bind("complete", lambda req: show(req, "bébé"))
req.send()