Server Views with React#753
Conversation
working and streamlined for the time when most of our testing will be done using the django server.
…fig-consolidation WIP: consolidate our webpack config
|
@djbarnwal the small amount client-side code looks good. requesting review from @wlach on the server stuff. @djbarnwal please also merge in the latest master |
wlach
left a comment
There was a problem hiding this comment.
On the whole this looks ok. After looking at the patch, I am not crazy about django-webpack-loader. It feels pretty unwieldly, and I would rather we just have one static bundle rather than two seperate web configs with the server. However, this will probably be ok for initial testing.
I don't think we need the user api's (at least not yet). Please see if you can get things working with a filter on the notebook endpoints as I suggest, as it will reduce the surface we need to validate and test.
I haven't tested how this actually works, let me know once you've addressed the main points here and I'll take a closer look.
| In dev mode, resource paths are set to be relative to the `dev/` directory. Thus, you export a notebook from a dev notebook, you need to be sure save the exported HTML file in the `dev/` folder for the relative paths to correctly resolve the required js/css/font files. | ||
|
|
||
| ### Production mode | ||
| ### Production mode |
There was a problem hiding this comment.
Please try not to let these kind of unrelated changes into your pull requests, as they make them more difficult to review.
| urlpatterns = [ | ||
| url(r'^users/$', UserList.as_view(), name='user-list'), | ||
| url(r'^users/(?P<pk>[0-9]+)/$', UserDetail.as_view(), name='user-detail'), | ||
| url(r'^users/username/(?P<username>\w+)$', UserDetailFromUsername.as_view(), name='user-detail-username'), |
There was a problem hiding this comment.
If we were going to keep these methods, use rest_framework's router framework here (see server/notebooks/api_urls.py for an example of this)
| } | ||
|
|
||
| render() { | ||
| console.log('state', this.state.user) |
There was a problem hiding this comment.
Please do a search for all console.log statements in your patch and remove them.
| @@ -0,0 +1,9 @@ | |||
| from django.conf.urls import url | |||
There was a problem hiding this comment.
I'm pretty sure we don't need these user api's. Instead we can add a "filter by user" on the existing notebooks endpoint:
e.g. /api/v1/notebooks/?user=djbarnwal
See: http://www.django-rest-framework.org/api-guide/filtering/
You can see some examples of setting up filtering with rest framework in @jaredkerim's experimenter project:
https://github.com/mozilla/experimenter/tree/master/app/experimenter/experiments
There was a problem hiding this comment.
@wlach This can be done but this way we won't be able to fetch the meta data of the user (such as first name, avatar etc.) for the profile page.
There was a problem hiding this comment.
I think it would be more sensible to add such filtering to already existing users route instead of creating another users/username/ route
| from server.base.serializers import UserSerializer | ||
|
|
||
|
|
||
| class UserList(generics.ListCreateAPIView): |
There was a problem hiding this comment.
If you're going to keep this, use viewsets (probably ReadOnlyModelViewSet) here: http://www.django-rest-framework.org/api-guide/viewsets/
| url(r'^notebooks/', include('server.notebooks.urls')), | ||
|
|
||
| # various views to help with the authentication pipeline | ||
| # various views to help with the authentication pipe line |
| url(r'^logout/$', server.views.logout, name='logout'), | ||
|
|
||
| # route for creating new notebooks | ||
| url(r'^notebook', server.views.notebook, name='notebook'), |
There was a problem hiding this comment.
We should probably make this /server/notebooks/new and serve it under the existing notebook urls, above ^^^
| } | ||
|
|
||
| render() { | ||
| return ( |
There was a problem hiding this comment.
Let's take the advertising spiel out for now, and just focus on presenting a reasonable user interface when people are using the alpha server.
| url(r'^$', server.views.index, name='index'), | ||
| # url(r'^$', server.views.index, name='index'), | ||
| # react bundles to views | ||
| url(r'^(?!oauth/|notebooks)', server.views.index, name='index'), |
There was a problem hiding this comment.
I'm not sure what the comment here means, or the rationale behind this change? I'm sure there is one, I just don't understand. :)
| </head> | ||
|
|
||
| <body> | ||
| <div id="react"></div> |
There was a problem hiding this comment.
Could we pick a more meaningful identifier than react?
…redirect Add https redirect for production deploys
|
This PR seems to have gotten disconnected from master somehow, there's a lot of commits in here that duplicate things already landed. In any case, after some discussion and thinking, I'd like to fork this PR and try an alternate approach described here: https://hackernoon.com/reconciling-djangos-mvc-templates-with-react-components-3aa986cf510a The key benefits are that we won't need seperate package.json files, or a seperate webpack server running on the host or in production. Everything can be generated in the existing npm build step. This should also make load times considerably faster (since we can just prepopulate what's visible on each page on the server side, instead of having the client make a round trip to the server after loading the assets) I'll do up some experiments based on the code here and we can see how it plays out. |
|
I think we can close this for now, thank you @djbarnwal for taking the first crack at this! Even though we decided to move in a slightly different direction for the implementation in the end, the learnings we got from this PR were extremely valuable. |
This Pull Request implements a MVP model of the Iodide website integrated with a server. The user can now -
What isn't included -
api/v1/users/route)Closes #669 and #633