menu
Tatoeba
language
Register Log in
language English
menu
Tatoeba

chevron_right Register

chevron_right Log in

Browse

chevron_right Show random sentence

chevron_right Browse by language

chevron_right Browse by list

chevron_right Browse by tag

chevron_right Browse audio

Community

chevron_right Wall

chevron_right List of all members

chevron_right Languages of members

chevron_right Native speakers

search
clear
swap_horiz
search
saeb saeb June 12, 2014, edited July 17, 2014 June 12, 2014 at 9:02:47 AM UTC, edited July 17, 2014 at 4:04:38 AM UTC link Permalink

*GSOC week 3 progress report*

Done:
- Python API
- Sentence/Correction/Tag CRUD and detail views.
- Lots of tests ( 110 tests atm 80% coverage, working on making it 100%)

Not Done:
- User related views.
- Permissions and user groups/statuses.
- Browse and main views.
- Various database optimizations.

Sorry that I haven't been updating my work log lately and didn't write up this report on monday. I'm a bit behind but hopefully i can stay on schedule for this week.

The inner python api is mostly complete. That means developers trying to extend pytoeba will never have to deal with low level database operations or even understand the underlying schema or worry about unoptimized queries. All what they need to do is write things in this abstraction that we provide for common operations. A sample of what this looks like is the following:
>>> from pytoeba.models import Sentence
>>> from django.contrib.auth.models import User
>>> from pytoeba.utils import work_as
>>> user = User.objects.get(username='saeb')
>>> sentence = Sentence.objects.show(13213)
>>> with work_as(user):
>>> sentence.correct('Some important correction')
>>> sentence.add_tag('Not natural')
>>> sentence.edit('Test edit')
>>> sentence.translate('Test translation.', 'eng')
>>> sentence.delete()
>>> Sentence.objects.active() # returns all trusted sentences
>>> Sentence.objects.orphan().filter(lang='fra').filter(link__side2__lang='eng', level=1) # returns all orphan sentences in french that have translations in english with a depth of one (direct translation)

The current core implementation of the python api is a bit clunky and very naive. There's lots of mirroring on the model instance/queryset classes/ and manager classes. Also, each operation atm takes a few db queries. I have plans to optimize it all to 1 db hit per api call even for bulk operations. One good thing about the current implementation though is that it's lean. ~400 lines of python if you don't count any docstrings or mirroring code. That means if you are a programmer you can probably dive into pytoeba in a few hours and actually *get* what's happening and extend the website right away. Planning to trim and reduce that number quite a bit too.

The bulk of the views are done for the most part, it was as simple as wrapping the python api with django generic views and hooking them up to some urls. Testing them has been a bit of a pain though as I'm using py.test and need to reimplement a lot of the assert helpers django provides out of the box which is taking more time than I'd like. So they're largely untested atm, but this should be fixed in the coming weeks.

The ugly part about this week is that I haven't really been comfortable with my workflow. Not submitting smaller patches and commits have basically caused me to have this 2k line patch that I still haven't submitted till now...So you can imagine that this essentially killed code review this week and made me more and more reluctant to write entries in my work log about things that's not publicly available yet. Even reluctant to write this progress report. So hopefully this week I'll try submitting medium sized patches, and keep submitting what I have at the end of the day.

This week I wanna dive into userena and django-social-auth's code and see what I can do to integrate all this mess into one centralized user model and implement a full stack of modular permissions for all python api operations. Wish me luck.

----------------------------
intro message:
http://tatoeba.org/eng/wall/sho...#message_19536
progress reports:
week 1: http://tatoeba.org/eng/wall/sho...#message_19654
week 2: http://tatoeba.org/eng/wall/sho...#message_19768
week 3: http://tatoeba.org/eng/wall/sho...#message_19821
weeks 4-8: http://tatoeba.org/eng/wall/sho...#message_20001
-----------------------------
work log:
http://en.wiki.tatoeba.org/arti...work-log-lool0

patches pending review:
https://review.gerrithub.io/#/q...s:open+pytoeba

merged patches:
https://github.com/loolmeh/pytoeba

project template for testing:
https://github.com/loolmeh/pytoeba-dev

{{vm.hiddenReplies[19821] ? 'expand_more' : 'expand_less'}} hide replies show replies
TRANG TRANG June 12, 2014 June 12, 2014 at 9:13:18 AM UTC link Permalink

Good luck :) And thanks for keeping us updated.

Hybrid Hybrid June 12, 2014 June 12, 2014 at 2:10:04 PM UTC link Permalink

Thank you for your work (even if I don't understand everything). If I may request a feature, it would be to be able to have a "Next page" button on the "Latest contributions" page.

{{vm.hiddenReplies[19826] ? 'expand_more' : 'expand_less'}} hide replies show replies
saeb saeb June 12, 2014 June 12, 2014 at 6:59:01 PM UTC link Permalink

noted :)

Yan Yan June 16, 2014 June 16, 2014 at 3:35:58 PM UTC link Permalink

Thank you saeb for doing this!

It seems you have scheduled the implementation of an API (REST API?). Since you are using Python/Django, I suggest using Django Rest Framework, a great tool for building REST APIs, have a look: https://github.com/tomchristie/...rest-framework
What's the purpose of the API? Is it intended to be consumed by the future Tatoeba mobile app or by other applications, or both?

Do you need some help?
I'm familiar with Python/Django/Django Rest Framework. I can directly make some contributions on the github repo and send pull requests.

Is this project going to replace the current version of tatoeba?

Wish you good luck.

{{vm.hiddenReplies[19829] ? 'expand_more' : 'expand_less'}} hide replies show replies
saeb saeb June 16, 2014 June 16, 2014 at 3:51:33 PM UTC link Permalink

> It seems you have scheduled the implementation of an API (REST API?). Since you are using Python/Django, I suggest using Django Rest Framework, a great tool for building REST APIs, have a look: https://github.com/tomchristie/...rest-framework

I considered all my options before drafting the proposal and I settled on tastypie, and I'm kinda already familiar with it from my early attempts at prototyping this.

>What's the purpose of the API? Is it intended to be consumed by the future Tatoeba mobile app or by other applications, or both?

yeah, mainly for mobile apps and for an easier form of updates for all those people who download the dump every week, 300 mbs every week and rebuilding existing databases that they might have is not funny.

>Do you need some help?
I'm familiar with Python/Django/Django Rest Framework. I can directly make some contributions on the github repo and send pull requests.

I don't think I can accept help at this point. After gsoc is over though I'll move the main dev repo to github under Tatoeba's organization account, so anyone can send pull requests.

> Is this project going to replace the current version of tatoeba?

Hopefully, yes. If it's production ready by the end of gsoc and I can work out importing the rest of the missing data like the logs and user info and stuff from the current schema, transition should be quick.

> Wish you good luck.

Thank you.

{{vm.hiddenReplies[19830] ? 'expand_more' : 'expand_less'}} hide replies show replies
Yan Yan June 16, 2014 June 16, 2014 at 4:10:55 PM UTC link Permalink

Thank you for the answers. Hope the project will be production ready soon.