Skip to content

Commit 4be4560

Browse files
authored
Fix issue with resolving path (#50)
1 parent 73afc76 commit 4be4560

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

cypress/integration/websocket_spec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@ describe("Integration tests", () => {
1212
cy.get('#counter').should('have.text', '1')
1313
}),
1414

15-
it("able to use reflex which isn't registered", () => {
15+
it("are able to use reflex which isn't registered", () => {
1616
cy.visit('/test/')
1717
cy.get('#counter-2').should('have.text', '0')
1818
cy.wait(200)
1919

2020
cy.get('#decrementor').click()
2121
cy.get('#counter-2').should('have.text', '-1')
2222
})
23+
24+
it("get parameters won't throw exceptions when triggering reflex", () => {
25+
cy.visit('/param/?word=world')
26+
cy.get('#word').should('have.text', 'world')
27+
cy.wait(200)
28+
29+
cy.get('#button').click()
30+
cy.get('#word').should('have.text', 'space')
31+
})
2332
})

sockpuppet/consumer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ def render_page_and_broadcast_morph(self, reflex, selectors, data):
221221

222222
def render_page(self, reflex):
223223
parsed_url = urlparse(reflex.url)
224-
url_path = parsed_url.path + parsed_url.query
225-
resolved = resolve(url_path)
224+
resolved = resolve(parsed_url.path)
226225
view = resolved.func
227226

228227
instance_variables = [

tests/example/reflexes/example_reflex.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ def increment(self, step=1):
99
class DecrementReflex(Reflex):
1010
def decrement(self, step=1):
1111
self.session['otherCount'] = int(self.element.dataset['count']) - step
12+
13+
14+
class ParamReflex(Reflex):
15+
def change_word(self):
16+
self.word = 'space'

tests/example/templates/param.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% load static %}
2+
3+
<!DOCTYPE html>
4+
<html lang="en">
5+
<head>
6+
<meta charset="UTF-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<script src="{% static 'js/example.js' %}"></script>
9+
<title>Param view</title>
10+
</head>
11+
<body>
12+
Hello <span id="word">{{ word }}</span>
13+
<button id="button" data-reflex="click->ParamReflex#change_word">Change me</button>
14+
</body>
15+
</html>

tests/example/urls.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717
from django.urls import path
1818

19-
from .views.example import ExampleView
19+
from .views.example import ExampleView, ParamView
2020

2121
urlpatterns = [
22-
path('test/', ExampleView.as_view(), name='example')
22+
path('test/', ExampleView.as_view(), name='example'),
23+
path('param/', ParamView.as_view(), name='param')
2324
]

tests/example/views/example.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ def get_context_data(self, *args, **kwargs):
99
context['count'] = self.request.session.get('count', 0)
1010
context['otherCount'] = self.request.session.get('otherCount', 0)
1111
return context
12+
13+
14+
class ParamView(TemplateView):
15+
template_name = 'param.html'
16+
17+
def get(self, request, *args, **kwargs):
18+
kwargs.update(dict(self.request.GET.items()))
19+
context = self.get_context_data(**kwargs)
20+
return self.render_to_response(context)

0 commit comments

Comments
 (0)