You are viewing a read-only archive of the Blogs.Harvard network. Learn more.

Django Formsets, the worst thing ever?

This kind of thing really attracted me to django, but then the usability of it goes entirely out the window when you take a closer look.

Formsets are basically a container for an arbitrary collection of forms. A form is a abstraction layer for UI, but I’ve seen they (or rather ModelForms) can be somewhat helpful as a funnel for POST vars and validation of the model. Maybe my issue is that the use I’ve found for them is not the primary concern people have.

from https://docs.djangoproject.com/en/dev/topics/forms/formsets/

>>> ArticleFormSet = formset_factory(ArticleForm, formset=BaseArticleFormSet)
>>> data = {
...     'form-TOTAL_FORMS': u'2',
...     'form-INITIAL_FORMS': u'0',
...     'form-MAX_NUM_FORMS': u'',
...     'form-0-title': u'Test',
...     'form-0-pub_date': u'1904-06-16',
...     'form-1-title': u'Test',
...     'form-1-pub_date': u'1912-06-23',
... }
>>> formset = ArticleFormSet(data)
>>> formset.is_valid()

See, how you would expect something like this to work is it would take in a list, or at least a dict with a list. But no, they have you cat “form-n-” to the field name. This is just so sloppy I have to point it out.

They spent so much time figuring out how to take away customizability from the front end, they weren’t paying attention to the backend.

Django nonrel (noSQL) (app engine)

I’ve been working with this for the last couple weeks. I have been doing this for a couple reasons.
1) I wanted to play with noSQL
2) I’m developing and deploying with the google app engine — the app engine does have a mySQL option (Cloud SQL), but they have no free version of this — so to do a GAE app (entirely (including data) in GAE), you have to use the google data store or pay for SQL.

Now doing the design in a key-value noSQL wasn’t too bad. I just had a design that had each object containing the ids of the other objects that were associated with it both ways. This was somewhat redundant she thinking about it in a relational way, but it made queries simple and fast. The overhead is making sure the software keeps the ids updated in all related objects I.e. if something is deleted.

That wasn’t so bad. It was a fun to design things differently than I’m used to. Then I fleshed out the models in django.

The issue I ran into was django-nonrel. This is the project that converts django to be able to deal with non relational DBs. This changes core django abstraction models and consists of apps that can be installed locally or globally. So I installed them locally because I don’t like the idea of altering the framework globally.

It did not work with the latest version of django.

So I read through the docs a little more carefully to discover the core team quit this project over a year ago. Because noSQL wasn’t right for their projects and Cloud SQL was now available for app engine. The guy who took it over isn’t keeping it up to date with django. He’s about a year behind. It’s working with django 1.3. Current version right now is 1.5.1. That is enough to throw errors.

If django is making changes in point releases that cause the django-nonrel to become out of date, either django isn’t doing a good job at maintaining backwards compatability or (much more likely) django-nonrel project isn’t doing a good job keeping away from hacky implementations that rely on very specific django references.

I don’t have the time to debug django-nonrel. It’s like 4 apps that go in your django project.

Additionally I worked out what the cost of Cloud SQL would be for development and I can deal with less than $2 a month. When it goes production I can worry about dealing with my teams extremely poor mysql management or get my group to pay for a more substantial Cloud SQL instance.

Posted in ATG, Flashcards. Tags: , , , , , , , . Comments Off on Django nonrel (noSQL) (app engine) »

Drag Dropping a Helper (or something else) with jQuery UI

I was having issues using jquery UI’s draggable and dropping something other than what I was dragging into a sortable. So this example, but dropping something else.

Originally I was trying to do it with Helpers. Helpers are nice, but limited in functionality and you cannot get the draggable helper element from the sortable. The right way seems to be to append / create the element within the dom once it’s been dropped. So create an element template and drop it in on the sortable’s update event.

Here is a jsfiddle with my solution.

Highlight:

var textItem = 'Text that is droppped';
var imgItem = 'Image that is dropped';

$(document).ready(function(){
	$('#sortable').sortable({
		revert: true,
		update: function(event, ui){
			if($(ui.item).hasClass('mysortable')){
			    // we don't add one if we're sorting a pre-existing item	
			} else {
				$(ui.item).removeClass('ui-state-highlight');
				$(ui.item).addClass('mysortable');
				
				if($(ui.item).hasClass('textDrag')){
					$(ui.item).html(textItem);					
				}
				if($(ui.item).hasClass('imgDrag')){
					$(ui.item).html(imgItem);					
				}
			}
		}
	});
	$('.draggable').draggable({
        connectToSortable: "#sortable",
        helper: "clone",
        revert: "invalid"
	});
	
});
Posted in ATG, Flashcards, Javascript, jQuery. Tags: , , , , . Comments Off on Drag Dropping a Helper (or something else) with jQuery UI »

Agile Context Switching

I had the pleasure of trying to work on 3 separate agile projects last sprint. I typically get 40-50 story points done in a sprint. I like to take on more than I think I can do to keep myself from letting work expand to fill time. I also had the issue of having to take on another developer’s work. Total, we promised ~80 story points.

Now, when my kid was new and I wasn’t allowed to sleep nights, I was able to cram 70-80 sps into a sprint. But sleep has made that level of productivity very hard.

I was also tasked with working offsite, organizing a community of practice, and trying to learn a very large project through “osmosis”. Which is to say, learn as much as you can without reporting time spent on it.

I have to admit, all of the work is interesting and the clients are all people I personally don’t want to let down. So it’s hard to say “forget project X”. (Which is hard to say generally when there actually is a project X.)

So with many things pulling me in many directions, my completed story points for the sprint was 33. A significant decrease in general productivity.

Context switching needs to be allocated for in sprint planning. Duh?

The trick is how much? Some people say it takes 15-30 min to effectively context switch. That’s part of it. I think the larger part is when you’re focused on one-two items, you can finish things effectively. The more items, the more you end up with partial work. Partial work is the worst time killer. You get 50% into a feature and if you have to stop and start again it magically turns into 30-40% done.

Solution? Don’t switch contexts.

Har har. Work on something to completion before switching contexts. Be strict about it.

Posted in Agile, ATG, Development, Flashcards, Harmony Lab, Quizmo. Tags: , . Comments Off on Agile Context Switching »

Flashcard Gamification

With our Flashcard application, I am trying to make gamification a focal point. I want the games to be modular so anyone can create new games and I want games that are multiplayer. Friendly competition within the class would be ideal.

Competition among a scoring system is too antisocial. The score scroll at the end of a game of donkey kong doesn’t make for a lot of interest in this day and age.

I have a couple of ideas.

A “card” game. Each student is dealt the same 5 cards from a “deck”. They see only one side of the 5 cards. The reverse of one of those cards is displayed and the first student to select the correct card gets a point. That card is then replaced with a new one. Having them both have the same cards takes any chance out of the game. It is time based, which means it is reliant on students being on at the same time.

So a variation of the previous could be one student plays and waits for the other student to play and they don’t lose a point unless they get it wrong. Players could be matched based on how much they’ve studied.

But is that fun? I think after a while, most people would just get bored of it.

Word games on phones are quite popular, but they’re all just variations of word scrambles, word finds, or crosswords. These are simple and not very applicable to a flashcard framework.

I stopped writing this and don’t have the motivation to continue, so I’m just going to post what I have.

Posted in ATG, Flashcards, Gamification, Trends. Tags: . Comments Off on Flashcard Gamification »

Inserting images into Github’s wiki

This is something I was not able to find clear information on. Specifically, I wanted to add a flow chart I’d created to the wiki. I’ll also be adding an ER diagram later. It’s cool to have the important development documents somewhere where they can be accessed and perhaps edited from anywhere by anyone if need be. Github has a failing in this regard I think. They should have an interface for this.

The trick of it all is the wiki is itself a git repo. What you have to do is check out that repo. In my case, my project was https://github.com/jazahn/HarvardCards. To checkout that project, you would use the command:


clone git@github.com:jazahn/HarvardCards.git .

But that’s the project. The wiki is:

clone git@github.com:jazahn/HarvardCards.wiki.git .

So you have to check that out, add the image file to it, and then you can [[add the image]] via relative path image link. https://github.com/jazahn/HarvardCards/wiki/Flashcard-Flowchart

Posted in ATG, Flashcards, Git, Version Control. Tags: , , , . Comments Off on Inserting images into Github’s wiki »