More fine tuned auto save feature in Lotte for Transifex

Lotte is the component of Transifex providing the web UI for the translators to translate online. Well, some time back, I made some changes in the Lotte code so that it has the auto-save feature on by default. It was running fine then and I was happy. Then I added the spellcheck feature in Lotte. Then the things started going not as expected.

Actually, the auto-save triggers when the contents of a text area has been edited and it loses focus. The first problem I faced is that the spellcheck button did not respond on the first click, but on the second. As expected, on the first click, auto-save was triggered. But this was not the case when I clicked the Undo button. First the auto-save and then the undo function would be executed. I was not able to come up with an answer to explain this. I was tinkering with the code and then accidentally I solved the problem. I just changed the order of the buttons. Initially I had – Spellcheck button , Save Button and Undo Button. Now, I have – Save button, Spellcheck button, Undo button. Weird! You can have a look at the change at https://bitbucket.org/rtnpro/transifex/changeset/b59880cadf67 . If you have an explanation for this, please comment.

One problem gets fixed and another comes to your mind. The auto-save function was being an overhead. The function would be triggered even if I press the spellcheck button, auto translate and copy source buttons in the same row. I am still editing the same string! The way it should be is  that it should trigger when I am finished with editing the string.

So, what I did is that I moved the code saving the string from the function being called by the blur event of the textarea to a new function. Whenever a textarea being edited receives the blur event, I save the edited string, its id and a must_push flag for future use. Now, whenever any other textarea receives focus, depending on the must_push flag, the string save function is called. This was just one part of the problem I fixed. Now, I have to deal with the click events that might take place in various parts of the page and it should save the edited string from the textarea that just lost focus. My save function is already ready and it deals with the required checks on whether to save or not. I just need to call the new save function. I just browsed through the html tree, found a list of elements and bound their click event to the save function. As for the table rows, I bound the click event of all the rows other than the current row to the save function. Here is the commit implementing the new auto-save feature : https://bitbucket.org/rtnpro/transifex/changeset/5a7c2a2e13ea  . I had quite some jquery drill to fix these issues :) .

Well, now Lotte with new auto-save feature is ready. Nice and elegant. I hope it makes up to the expectations of the translators. That’s what people strive at Transifex.

Contributing to transifex

For some time, I have been hanging around with django. I got some cool video tutorials on the web on django. They helped me a lot to start coding in django. At the same time, I was also going through the Transifex source code. After some time, I browsed through the tickets in trac.transifex.org and started with fixing ticket #679.

I had to go through javascript, jquery, html in addition to write the patch for #679. I also wrote a custom pagination plugin for dataTables pagination for fixing the issue mentioned in ticket #679. I submitted the patch upstream for review. I hope it will be accepted.

After that Diego directed me to work on ticket #129. Here I had add the provision for a “Remember me” option, which, if selected during login, will set the login duration to 21 days, else, the login session will expire on browser close. I had to create a form class _AuthenticationForm subclassing django’s AuthenticationForm to add a new Boolean form field “Remember me”. Then I had to just pass this _AuthenticationForm as the form argument in simpleauth.views.login and call simpleauth.views.login when the url is of the pattern r’^accounts/login/$’. Yeah … I know this looks odd.

But the best thing about this is that, it works both for simpleauth and for django-profiles. Also, when django-profile is being used, the django-profile templates are used. I have tested this patch on my system, its working fine. I hope the upstream will accept this.

Wrote a patch for kettu, web interface for transmssion

Kettu is the new web interface for transmission bit torrent client. It is written using javascript and jquery. I wrote a small patch for kettu to filter the torrents on the basis of activity. Here activity means if the torrent is either uploading or downloading, i.e, upload_speed + download_speed > 0 KBps.

Here’ s the patch I wrote :

diff –git a/index.html b/index.html
index 2a8ff97..b54b6b4 100644
— a/index.html
+++ b/index.html
@@ -58,6 +58,7 @@
<a href=”#” id=”activate_sorts”>Sort</a> -&nbsp;
<span id=”filters”>
<a href=”#/torrents?filter=all”>All</a>
+            <a href=”#/torrents?filter=active”>Activity</a>
<a href=”#/torrents?filter=downloading”>Downloading</a>
<a href=”#/torrents?filter=seeding”>Seeding</a>
<a href=”#/torrents?filter=paused”>Paused</a>
@@ -94,4 +95,4 @@
</nav>
</footer>
</body>
-</html>
\ No newline at end of file
+</html>
diff –git a/js/helpers/filter_torrents_helpers.js b/js/helpers/filter_torrents_helpers.js
index 95f841e..3b54b2c 100644
— a/js/helpers/filter_torrents_helpers.js
+++ b/js/helpers/filter_torrents_helpers.js
@@ -5,6 +5,12 @@ var FilterTorrentsHelpers = {

if(filter_mode == ‘all’) {
filtered_torrents = torrents;
+    } else if(filter_mode == ‘active’) {
+      $.each(torrents, function() {
+        if(this.activity()) {
+          filtered_torrents.push(this)
+        }
+      })
} else {
$.each(torrents, function() {
if(this.status == stati[filter_mode]) {
@@ -15,4 +21,4 @@ var FilterTorrentsHelpers = {

return filtered_torrents;
}
-}
\ No newline at end of file
+}
diff –git a/js/models/torrent.js b/js/models/torrent.js
index 8e39f1d..1bf2a2a 100644
— a/js/models/torrent.js
+++ b/js/models/torrent.js
@@ -106,6 +106,7 @@ Torrent = function(attributes) {
localized_stati[torrent.stati['downloading']] = ‘Downloading’;
localized_stati[torrent.stati['seeding']] = ‘Seeding’;
localized_stati[torrent.stati['paused']] = ‘Paused’;
+    localized_stati[torrent.stati['active']] = ‘Activity’;

return localized_stati[this['status']] ? localized_stati[this['status']] : ‘error’;
};
@@ -138,4 +139,4 @@ Torrent = function(attributes) {
};

return torrent;
-};
\ No newline at end of file
+};

The patch got accepted by the kettu upstream endor on  2010-03-29 and following is the patch commit link:

http://github.com/endor/kettu/commit/5d3a64c4807eee6bbfbb2d3013e384971930bca8

Feels nice to have written my first patch :)