Skip to content

Django IDOM #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jul 21, 2021
Merged

Django IDOM #1

merged 24 commits into from
Jul 21, 2021

Conversation

Archmonger
Copy link
Contributor

@Archmonger Archmonger commented May 18, 2021

This is the most minimalistic Django configuration possible that can support Websockets.

I've used folder structure and file naming schemes suggested by Django documentation.

Also included the Daphne webserver in the requirements for testing on more than just the development webserver.

In order to get this configuration running

  1. cd <repo_root_dir>
  2. pip install requirements.txt
  3. python manage.py migrate to create the initial database
  4. python manage.py runserver to run the django development test server. Alternatively, daphne dj_idom.asgi:application to run the production-grade webserver.

Here's the files in the repo:
dj_idom/static/scripts.js: Client side websocket
dj_idom/templates/base.html: HTML base template.
dj_idom/consumers.py: Server side websocket
dj_idom/asgi.py: Websocket URL routing
dj_idom/urls.py: HTTP URL routing
dj_idom/settings.py: Django boot time config
manage.py: Django project management utility

@rmorshea
Copy link
Contributor

rmorshea commented May 20, 2021

Thanks! I'll look this over shortly.

@rmorshea
Copy link
Contributor

@Archmonger IDOM 0.29.0 was just released and contains a fix so that we won't need to do pip install idom[stable] here.

@Archmonger
Copy link
Contributor Author

@rmorshea Resolved all startup errors under this repo's default configuration, I'll look to implement some tests soon.

@Archmonger Archmonger changed the title Barebones Django app with websockets Django IDOM Jun 20, 2021
@Archmonger
Copy link
Contributor Author

Archmonger commented Jun 20, 2021

@rmorshea Getting a test_suite fail on GH actions, seems to be due to "figure-it-out" noxfile.py:53
I assume this is where you want to run manage.py test?

@rmorshea
Copy link
Contributor

rmorshea commented Jun 20, 2021

Yup, I think a test that goes something like this should be totally sufficient:

import idom

def test_simple_counter():
    run_the_app_somehow()
    web_driver = make_the_web_driver_somehow()


    @idom.component
    def Counter():
        count, set_count = idom.hooks.use_state(0)
        return idom.html.div(
            idom.html.button(
                {"id": "incr", "onClick": lambda event: set_count(count + 1)},
                "Click me!",
            ),
            idom.html.p(
                {"id": "count", "data-count": count}, f"Current count is: {count}"
            )
        )
    
    counter_button = web_driver.find_element_by_id("incr")
    counter_view = web_dirver.find_element_by_id("count")

    for i in range(5):
        assert counter_view.get_attribute("data-count") == i
        counter_button.click()

Anything beyond that is nice but probably not necessary right now. Basically we just want to check that the end-to-end works.

@Archmonger
Copy link
Contributor Author

I think I'll need to tag up with you regarding the frontend-backend connection via django. Not sure how to get those components to actually appear in a django fashion.

@rmorshea
Copy link
Contributor

I think there's some docs on on how to set up a test using Selenium: https://docs.djangoproject.com/en/3.2/topics/testing/tools/#liveservertestcase

If there's not enough info there, grab a weekly office hour slot and we'll figure it out: reactive-python/reactpy#312

@rmorshea
Copy link
Contributor

There's some critical bugs in IDOM that need attention. Probably won't have time to work on this for another week or so.

@Archmonger
Copy link
Contributor Author

Does the commit from 6 days ago address the critical bugs you brought up?

@rmorshea
Copy link
Contributor

It does. I plan to release it soon. I'll then have some time to return to this after the two remaining open PRs are merged..

@rmorshea
Copy link
Contributor

Ok, I'm not free to start working on this again.

@Archmonger
Copy link
Contributor Author

Ok, I'm not free to start working on this again.

😂

I've been focused on Pyarr development but I'll have time to return to this soonish

@rmorshea
Copy link
Contributor

Edit: I'm now free to start working on this again.

@Archmonger
Copy link
Contributor Author

Can't wait to test this out!! This is the last piece of the puzzle for developing the Conreq community app store!

@rmorshea
Copy link
Contributor

I'm gonna go ahead and merge this, but I really do think we should provide an app that encapsulates what was done in test_app since there's a lot of little things you have to understand about IDOM to make it work. Unfortunately, I don't think I understand enough about Django to make that happen.

Ideally one would be able to install django_idom as an app and then just embed a template into you HTML where you want an IDOM view to show up. I think I'll have to do some pair programming with someone who knows how to make re-usable apps though.

@rmorshea rmorshea merged commit ff7ec1c into reactive-python:main Jul 21, 2021
@Archmonger
Copy link
Contributor Author

Archmonger commented Jul 21, 2021

I'm gonna go ahead and merge this, but I really do think we should provide an app that encapsulates what was done in test_app since there's a lot of little things you have to understand about IDOM to make it work. Unfortunately, I don't think I understand enough about Django to make that happen.

Ideally one would be able to install django_idom as an app and then just embed a template into you HTML where you want an IDOM view to show up. I think I'll have to do some pair programming with someone who knows how to make re-usable apps though.

I can show you how to make reusable templates. That one is fairly simple, but it might be awkward given the current repo structure of using test_app

@rmorshea
Copy link
Contributor

@Archmonger it'd be great to organize another working session to get through that.

@Archmonger
Copy link
Contributor Author

@Archmonger it'd be great to organize another working session to get through that.

We can plan something out around your schedule, let me know your availability.

@Archmonger
Copy link
Contributor Author

@rmorshea Something came up so I'll need to cancel our 11. I'll be able to do later in the evening if you're free.

@rmorshea
Copy link
Contributor

Should be fine. Just let me know when you're able.

@rmorshea
Copy link
Contributor

@Archmonger still able to meet?

@Archmonger
Copy link
Contributor Author

@rmorshea just freed up, lemme know when you wanna meet

@rmorshea
Copy link
Contributor

Moved the event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants