Skip to content
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

Use Django REST framework #1

Closed
zemogle opened this issue Jun 11, 2015 · 7 comments
Closed

Use Django REST framework #1

zemogle opened this issue Jun 11, 2015 · 7 comments

Comments

@zemogle
Copy link
Contributor

zemogle commented Jun 11, 2015

This project is mainly an API service. At present all of the API end points are hand-rolled. It would be much more sustainable if these were to use Django REST framework intead

@adrienbrunet
Copy link
Contributor

I had a look at it today. I'm really short on time so I can't do it right now even I'd really like to.
IMO, we need to add first a form to handle the query. It would be really cleaner to use a clean function to handle the query rather than request.GET.get('attribute', '').

It will make the view thiner and easier to understand. What the views does:
it retrieves the Target model and filter it with the parameters from the form. The data validation should occur in a form clean rather than inside the view.

When we have that, it would be even easier to add DRF. It is easy to create a model API endpoint, and filter the queryset with some parameters. The tricky part seems to rely here on that form clean.

With a form, we could also add widgets (such as a datetime picker...!!) and the html will be much simpler. You don't need to write all the form html, django can do it for you. Adding sites would be even easier if we consider a foreignkey to a new model with the coordinates.

You might want to create tickets from that comment. Again, I'm truly sorry to write more comments than actual code. I lack some free time to help you more.

I have started to add a sphinx structure for the project. Do you have any docs that you've written which isn't in the repo? It would be helpful. The docs I'va generated are quite empty so far.

@zemogle
Copy link
Contributor Author

zemogle commented Jun 23, 2015

Thanks for the suggestions. This package is only providing an API end-point for use inside the telescope observing interface. At present a form never gets shown to the user (the form you can see in urls.py is just to help with testing a bit). The observing interface constructs the query string parameters. It would be excellent to have the form available more generally (and develop the list of objects including ones suitable for amateur telescopes).

It looks like DRF does validation using serializers. How about I start the ball rolling by thinning the view down in this way?

@zemogle zemogle assigned zemogle and unassigned adrienbrunet Jun 23, 2015
@adrienbrunet
Copy link
Contributor

I'm not sure to understand. There IS a form. When you "runserver", you get a page with a form to fill with a date and a location to select from a list. If it's only for testing purpose, we should get rid of it and write some test instead of an html mockup. It would be easier to maintain and a good test is self-explainatory while a bad mock up doesn't reflect the behaviour of your app. 😃

To filter against parameter querys, see http://www.django-rest-framework.org/api-guide/filtering/#filtering-against-query-parameters

I have the feeling that the project is splitted in too many really small projects. We could have more benefits to work on a larger picture but you may have your reasons not to do so. 😔 I'm trusting you on the architecture of the project

@zemogle
Copy link
Contributor Author

zemogle commented Jun 23, 2015

😊 You found me out! We can replace that with a Django form, or just remove it because Laurent has written some excellent tests which make it redundant.

What did you mean about the larger picture? If you mean the full observation interface, it is a longer term plan for us to open that up but it is a HUGE piece of code. Maybe a functional diagram would help, to show how different apps fit together?

@adrienbrunet
Copy link
Contributor

Maybe yes. There is a lot of overhead to maintain different apps for too small part of code. Maybe there is a ot we could refactor. But it is a start. Let's get that app working, then we'll talk bigger apps ❗

@zemogle
Copy link
Contributor Author

zemogle commented Oct 28, 2015

Now using DRF in production 😄

@zemogle zemogle closed this as completed Oct 28, 2015
@adrienbrunet
Copy link
Contributor

👍

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

No branches or pull requests

2 participants