== Dev Week -- LoCo Directory Hacking -- mhall119 -- Wed, Mar 2nd, 2011 == {{{#!irc [17:02] Hello everyone [17:02] my name is Michael Hall, and I'm one of the developers of the Ubuntu LoCo Directory [17:03] I hope you've all been to http://loco.ubuntu.com already, but does anybody not know what it is? [17:04] alright, quick overview then [17:05] the loco directory is a community-driven project, meaning decisions and implementation are determined by the community, not Canonical [17:05] techbreak asked: mhall119, idk what is this sessoin about ? loco directory ??? [17:05] techbreak_: http://loco.ubuntu.com [17:05] this session is going to get you ready to start hacking and contributing to it [17:06] the loco-directory is written in Python, and uses the Django web framework [17:06] you will need at least working knowledge of python, and some basic understanding of Django to work on LD [17:07] if you don't currently have Django knowledge, don't worry, it's very easy and I'll go over some of it this hour [17:07] the main developers of LD are myself, cjohnston, dholbach, Ronnie and daker [17:07] we all hang out in #ubuntu-locoteams, and that's usually where we discuss LD development [17:08] since loco.ubuntu.com is hosted on one of Canonical's servers running Ubuntu 10.04, we're restricted to the versions software in those repositories [17:09] specifically python 2.6, Django 1.1, jQuery 1.3 and jQuery-ui 1.7 [17:09] if you're running Lucid, you're all set [17:09] if you're running Maverick or Natty, you'll need to grab those versions manually [17:11] < YoBoY> QUESTION : we can't develop with earlier versions of python, django, ... or [17:11] it's just recomended ? [17:12] since we develop on 2.6, and it'll be running 2.6 in production, it's generally a good idea for you to use 2.6 [17:12] I can't say for sure that it won't work with 2.4, but it's likely [17:13] I'm assuming you have all been introduced to the basics of bzr by now, but if not just ask about it as I go [17:13] alright, lets get the code! [17:13] cd to where you want it to live [17:13] then run: bzr branch lp:loco-directory [17:13] that'll get you a copy of the latest trunk [17:14] trunk is almost always stable [17:14] RawChid asked: IS there a manual or webpage which describes how to do this? [17:14] not that I know if, but ask us in #ubuntu-locoteams (after this session) and we can help you with it === cmagina is now known as cmagina-lunch [17:15] okay, by now you should all have a local branch of loco-directory [17:15] so cd loco-directory and let's take a look [17:16] quick Django info: [17:16] Django projects are divided between the root 'project' folder, and sub 'application' folders [17:17] in the root of the branch, 'loco_directory' is the django project folder [17:17] so cd loco_directory [17:17] under there you'll see 'common', 'events', 'meetings', 'services', 'teams', 'userprofiles' and 'venues' [17:18] those are all of the Django applications that make up LD [17:18] 'common' is just what it sounds like, it's for things that don't fit elsewhere [17:19] 'teams' contains all the code for LoCo Team records [17:19] ls ./teams/ [17:19] a Django app typically has several standard files [17:20] models.py is where you define your data models, Django will automatically turn these into SQL tables for you (you'll see that later) [17:20] views.py is where you write the code that is responsible for responding to an HTTP request [17:21] and urls.py maps a URL pattern to a view [17:21] any questions so far? [17:21] ok, moving on [17:22] the 'events' and 'venues' are the apps that handle LD's event tracker, if you've used LD before you'll know what they do [17:22] they have the same basic structure as 'teams', with models.py, views.py and urls.py [17:23] same for 'meetings' and 'userprofiles' [17:23] now, Django has a built-in templating system that we use. Our views.py code will usually make use of one or more templates in rendering an HTTP response [17:24] templates live under the 'templates' directory in the project folder [17:24] if you ls ./templates/ you'll see that they're separated out by app as well [17:24] so, to recap [17:25] if you want to change data structures, it'll likely be in a models.py [17:25] if you want to change the logic behind a display, it'll likely be in a views.py [17:25] and if you want to change the interface (html), it'll likely be in the templates [17:25] everybody with me so far? [17:26] alright, let's get you guys setup with a working instance of LD [17:27] first things first, lets look at settings.py in the project folder [17:27] there's a lot of stuff in here, but the key piece is down around line 116: INSTALLED_APPS [17:27] this is a list of apps that Django will use for this project [17:28] monish001 asked: does Django works on MVC (model view controller framework)? [17:28] yes, though they call it Model-View-Template, and things are slighting shifted [17:29] specifically, the typical 'controller' logic is in the view, and most of the display stuff is in the templates [17:29] okay, lets loot at INSTALLED_APPS [17:29] the first 4 are the standard Django apps, auth gives us User and Group models, plus permissions [17:30] contenttypes is really internal stuff you won't likely ever need to worry about [17:30] sessions gives us automatic session tracking, just like any good web framework should [17:30] admin is the best of them all, it'll give you a fully functional interface to manage the data in your database for all your defined models [17:31] if you look in most of the application folders, you'll see amdin.py, which tells the admin app how to present your models [17:31] the next 6 items in INSTALLED_APPS are the LD apps we've already gone over [17:32] django_openid_auth is what let's us tie our users and groups to the Ubuntu Single Signon === Mkaysi is now known as OmgBot [17:32] south is a special Django app, by default Django will create DB tables based on your models, but it won't change existing tables, which means once you create them you have to make any future changes manually === OmgBot is now known as Guest83509 [17:33] south lets you track your model structure, and will provide migration scripts whenever you make changes to them [17:33] we make good use of south in the loco directory === Guest83509 is now known as Mkaysi [17:33] if you look under most of the application folders, you'll see a 'migrations' folder, these are the south scripts [17:33] ok, that's all for settings.py [17:34] next step, copy local_settings.py.sample to local_settings.py [17:34] we use local_settings.py for settings that are specific to a running instance of LD, they aren't checked into bzr [17:35] there's not really anything you need to do with it right now, except make the copy [17:35] everyone with me still? The next part is setting it all up [17:36] alright, lets get our database [17:36] from the project folder, run "./manage.py syncdb" [17:36] it will ask you for a superuser, select yes and give it a username, email and password [17:37] syncdb is the Django command that created your initial database tables [17:37] by default, LD will use a local sqlite3 file for it's database [17:37] in production, it runs against postgres [17:38] you're also free to use MySQL [17:38] when syncdb finishes, you'll see a message about some apps not being synced because they're under south's migration control [17:38] so after syncdb, run: ./manage.py migrate [17:39] this will cause South to run through all of it's migration scripts [17:39] which will leave you with the proper table structures [17:39] if you're using sqlite, you'll see some warnings because it doesn't support some contraints, don't worry about those [17:40] finally, we'll need to initialize your setup, so run: ./manage.py init-ld [17:41] init-ld does several things, it'll setup a group in your database for the LoCo Council, it will create necessary symlinks for jquery, and finally it'll grab a copy of lp:ubuntu-website/light-django-theme [17:41] that last bit is important [17:41] light-django-theme provides the base templates and CSS for several Django powered Ubuntu sites [17:42] loco.ubuntu.com (of course), but also summit.ubuntu.com and 10.cloud.ubuntu.com [17:42] everybody run all of those steps okay? [17:42] * mhall119 looks at the clock [17:44] okay, typically the next step is to either refresh your database with data from Launchpad,or refresh it with data from loco.ubuntu.com [17:44] but, both of those take a while to run, so we're going to skip them and I'll just have you download a copy of loco_directory.db [17:44] http://ubuntuone.com/p/fn1/ [17:44] put that into your project folder (over-writing the one you made with syncdb) [17:45] for reference, "./manage.py lpupdate" will refresh teams and some users from Launchpad, but won't get events, venues or meetings [17:45] "./manage.py import-live-data" will use LD's REST/Json services to download data from loco.ubuntu.com [17:46] once you have the database file, run: ./manage.py runserver [17:46] this will run django's built in webserver on localhost:8000 [17:47] which you can then visit in your browser to see your local instance running [17:48] oh yes, Ronnie brings up a point that I missed [17:48] INSTALL file in the root of the branch has instructions for getting things setup [17:48] one of the lines is a long apt-get install, which will get you all the dependencies [17:49] okay, hopefully I've gotten you guys a working (or mostly working) isntance of the LD code [17:50] the next step is to find a bug at https://bugs.launchpad.net/loco-directory to work on [17:50] if you need help figuring out what needs to be done, just ask us in #ubuntu-locoteams [17:51] There are 10 minutes remaining in the current session. [17:51] but remember, data=models.py, logic=views.py, UI=templates [17:51] that'll get you to the right place 90% of the time [17:51] after you make the fix, test it locally first [17:51] once you're happy with it, run: bzr commit -m "You message" --fixes lp:12345 [17:51] where 12345 is the bug number you're working on [17:52] that'll help launchpad associate your code with that bug [17:52] then: bzr push lp:~you/loco-directory/fixes-12345 [17:52] agian, I hope you've all been introduced to bzr and distributed development, so this should be familiar [17:53] then go to https://code.launchpad.net/loco-directory, select your branch, and click the "Propose for merging" link [17:54] then one of the main developers will review your code (when we have time, we all have actual jobs too) [17:54] < chadadavis> QUESTION, doe the push statement make a new branch as well, or just [17:54] upload the current branch? [17:55] it will create a new branch in Launchpad, based off the lp:loco-directory branch [17:55] these are very lightweight in launchpad, so don't hesitate to push stuff [17:55] we typically have one branch per fix or feature [17:56] There are 5 minutes remaining in the current session. [17:56] once your code bases a review, we will merge it into lp:loco-directory [17:56] from there it will get translated and wait for the next release of LD [17:56] anything that lands in trunk will be in the next release [17:57] we don't have a fixed release schedule though, so it's hard to say if it'll take days or weeks to get it out [17:57] < YoBoY> QUESTION : can you point us some easy bugs to start working on ? [17:58] we try to mark small/easy fixes as 'bitesize' in launchpad, you can get a list of them from https://bugs.launchpad.net/loco-directory/+bugs?field.tag=bitesize [17:58] if you get stuck or have other questions, come find one of us in #ubuntu-locoteams [17:58] and happy hacking! }}}