Posts for the 'Websites' Category

  1. Javascript MVC frameworks with MVC server frameworks

    Really interesting article about Javascript MVC frameworks at CodeBrief.

    Personally and for work I am totally into backbone.js. It is changing the way that I work with Javascript in my web applications for the better by bringing greater structure and organisation to my code and having a common methodology in the way that I approach server-browser communications.

    The only problem that I have is that having a MVC stack in the browser is fine, but then we have the same on the server side with Rails (ok not exactly MVC), Django, Node.js or what have you. We end up with MVCMVC or rather MCVCMV, and this is of course a pattern that causes code duplication if we are not careful.

    I might look into creating backbone.js models from Django at some point, but I am not sure that this is the correct route. Obviously the way that GWT and PyJamas work becomes more compelling. Well for me GWT is not that compelling as I don’t really want to have to work on frontend in Java, I don’t think there is the control that one needs over the presentation and I can’t stand Eclipse/NetBeans/xxxx IDE’s as they are slow and cumbersome.

    Regarding the Codebrief article ember.js came out on top, and I can see the negatives of backbone.js in its somewhat boilerplate approach though I think this can be minimised somewhat.

    Personally I think my goals going forward for Javascript is:

    1. Find a decent testing enviroment that I am happy with
    2. Loading of modules should be optional, and I need to work to convert my existing application to load intelligently our backbone.js models and views
    3. Greater reuse or automatic generation of code

    I am intending to write about all of this on this blog in the near future as I come up with more conclusions.

    By timc3 on the
    January 21st, 2012
  2. Django Select Multiple filter.

    Django has a really nice select multiple field, for choosing multiple items at once with a Javascript chooser..

    It is really handy to use when there is a large number of items that have to be chosen from in a select. I am using with JQuery.

    To do this, grab SelectFilter2.js from the django-admin media folder, or get it from Django’s GitHub repository. Then to initialize it you can put the following into your code:

    $(document).ready(function() {
        $.each($("select[multiple]"), function () {
             // "Locations" can be any label you want
        SelectFilter.init(this.id, "Locations", 0, "/media/");
      });
     });

    This will use the SelectFilter on all select multiples and give it a label of locations.

    For reference the functions are:

     function(field_id, field_name, is_stacked, admin_media_prefix)

    So you could use:

     SelectFilter.init("#MySelect", "Test", 0, "{{ MEDIA_URL}}img/");

    Then all that needs is styling the select multiple.

    By timc3 on the
    November 2nd, 2010
  3. Orbited + Django dev daemon

    Today I got my Django project working with Orbited.

    By creating a twisted proxy for Orbited and Django I am able to serve a development environment for both Django and Orbited plus the builtin MorbidQ message queue.

    I am going to be using this to give live notifications of events that are happening on the system in realtime, and so it should be able to handle quite a large load. To do this I will use another queue in production, but I have found it needed to sort out the development environment first of course.

    This daemon I have put up at GitHub .

    It even serves the static files. Much thanks goes to the HotDot project for seeing how alot of this was done, but I have taken out the authentication and other bits to make it cleaner for general use.

    By timc3 on the
    August 21st, 2010
  4. Realtime web – Orbited vs Tornado

    My latest task and one that I have been researching and playing with for some time is to integrate real time feedback in to our web application. The main goal is to be able to provide real time feedback of jobs and updates to users without Ajax style polling.

    This is a simple requirement to write, but one that had many deeper issues. Firstly it needs to be able to handle many users concurrently and secondly it should do so without blocking execution of code. Our application framework was not designed for this and this is no problem, it has been designed to do certain thing well and other I am really not going to force upon it.

    The main application framework will handle the standard page requests, user authentication and the rest of the standard stack, so I have been looking at technologies to complement its capabilities. This has led me to look at Comet applications and very fast non-block frameworks.

    Of these I would prefer to keep the language in Python, there seem to be good alternatives in Java and .Net but I would rather keep an upgrade path by having a language that can be migrated across to these (thanks Jython and IronPython) and keep data in a backend store that is language agnostic.

    Orbited and Tornado are really good candidates. I am going to stay away from more raw implementations of non-blocking event based frameworks such as Twisted because efforts are often better at this stage in building to serve a business purpose where possible. Orbited does actually use twisted, and I am hoping that I will have little need to dig that deep except for understanding its implementation.

    Tornado I initially didn’t think of, but came around after reading “Building the Realtime User Experience” in which the author, Ted Roden, seems rather partial to it. In fact it can work quite well in fronting our application, but I am starting to reconsider based upon two factors. Firstly, even though it itself was built for a largish scale operation (FriendFeed – now owned by FaceBook), it has little other commercial users behind it and I haven’t found many examples of usage with integrating with Django, Pylons, Turbogears or Zope in a production environment. Secondly what really turns me off is the immaturity of its tests. Looking on GitHub even the README shows that little effort has been put into its testing environment, let alone their sporadic coverage.

    Twisted on the other hand is extremely mature in both terms of numbers of deployments and its test environment, and this makes Orbited a much better candidate.

    I have yet to look at certain other alternatives, such as Diesel, but I have a feeling that I will again come around to start using Orbited.

    The other huge plus for me in using Orbited is that it can use the STOMP protocol, and use RabbitMQ or ActiveMQ. Other parts of our technology stack are starting to use STOMP and I wish to move more operations on to an event queue, which will open up much in terms of flexibility in the future.

    Its a pity that “Building the Realtime User Experience” was so limited in terms of covering alternatives to Tornado.

    By timc3 on the
    August 16th, 2010
  5. Twitter mobile phone number fail

    Could someone please tell me exactly how I am supposed to put in my phone number?

    twitter.png

    Seriously something wrong with this. And of course if I click submit it tells me that I should have filled out the number correctly.

    By timc3 on the
    March 18th, 2009
  6. Facebook is AOL 2.0

    Facebook is The Borg: “

    Much of the activity that used to happen out in the wild unfettered Net, over email, open (XMPP-based) IM and blog posts is now happening inside the Facebook silo. It is AOL 2.0.

    I avoid the place, but that’s getting harder. On this current visit I see 7 friend suggestions, 273 friend requests, 6 event invitations, 5 good karma from debo requests, 1 good karma request, 220 other requests, 4 new updates, 235 items in my inbox, 7 pokes and 522 friends to start with.

    Okay, I just said yes to several friend requests, congratulated a friend on his new twins, and started chatting in FB for the first time.

    To FB’s credit, it’s working on a Jabber/XMPP interface, so you can chat to FB-based friends through any client that talks XMPP. That’s cool, but The Borg still grows.

    I also notice that FB now has a tiny pale gray thumbs-up and thumbs-down for its advertising. When I click on the down thumb (which I always do — I haven’t yet seen a relevant ad), it just says ‘Loading…’ in a big box that won’t go away.

    So I just punched out. I suspect I’ll be doing less of that.

    (Via The Doc Searls Weblog.)

    By timc3 on the
    January 8th, 2009
  7. This is awesome – Papervision

    This is really really awesome, and you have to really check it out for your self.

    MeWithAPet.jpg

    Its a little flash application that uses a webcam or other camera attached to your computer to project a little ‘Proto’ guy on top of a printed piece of paper. They have even got some code released for it.

    Check it out here with some images and video, but it really works better to try it yourselves:

    http://www.boffswana.com/news/

    By timc3 on the
    December 16th, 2008
  8. django one form, two models

    This post is a work in progress is now working I am glad to say. I have been working on a django site which needs two models updated for one post. It is actually using models very close to that on django-forums and I have created a forms.py file:

    class ThreadForm(forms.ModelForm):
        class Meta:
            model = Thread
            exclude = ('forum', 'sticky', 'closed', 'posts', 'views', 'latest_post_time')
         
        def clean_title(self):
            title = self.cleaned_data['title']
            if not alnum_re.search(title):
                raise forms.ValidationError(ugettext("Titles can only contain letters, numbers and underscores"))

            if len(title) < 1:
                raise forms.ValidationError(ugettext("Please enter a title"))
            return title

           
    class PostForm(forms.ModelForm):
        class Meta:
            model = Post
            exclude = ('thread', 'author', 'time', 'related_item')
           
        def clean_body(self):
            body = self.cleaned_data['body']
            if len(body) < 1:
                raise forms.ValidationError(ugettext("Please enter some body text"))
            return body

    And then in my views (after importing in the correct models):

    @login_required
    def groupnewthread(request, slug):
        thegroup = get_object_or_404(GroupsOfUser, slug=slug)
        if request.method == 'POST':
            f = request.POST.copy()
            tdata = {
                'title': f['title'],
            }
            pdata = {
                'body': f['body'],
            }
            t = ThreadForm(tdata)
            p = PostForm(pdata)
            if t.is_valid():
                newthread = t.save(commit=False)
                newthread.forum = thegroup
               
               
                if p.is_valid():
                    newthread.save()
                    newpost = p.save(commit=False)
                    newpost.thread = newthread
                    newpost.author = request.user
                    newpost.save()
             
                    strmessage = 'has created a thread <a href="%s">%s</a>' % (newthread.get_absolute_url(), newthread.title)
                    usm = UserStatus(user = newpost.author, message = strmessage)
                    usm.save()
             
                    return HttpResponseRedirect(reverse('groupdetail', args=[thegroup.slug]))
           
        else:

            t = ThreadForm()
            p = PostForm()
           
        objContext = RequestContext(request, {'threadform': t, 'postform': p})
        return render_to_response('groups/group_thread_add.html', objContext)

    Now the bit that is in progress is the returning part of dealing with the form data being bound, but I am going to write a custom handler. This is obviously going to be much easier to handle than an update, which I will have to deal with at a point.

    The form HTML looks like this btw:

    {% extends "base.html" %}
    {% load i18n %}
    {% block title %}
        {% trans 'Add a new group thread' %}
    {% endblock %}
    {% block body %}
        <h1>{% trans 'Create a new group thread' %}</h1>
    <div class="column span-14">
        {% if t.errors %}
        <h3>{% blocktrans count t.errors|length as count %}Please correct the following error:{% plural %}Please correct the following errors:{% endblocktrans %}</h3>
        {% endif %}
        {% if p.errors %}
        <h3>{% blocktrans count p.errors|length as count %}Please correct the following error:{% plural %}Please correct the following errors:{% endblocktrans %}</h3>
        {% endif %}
        <table>
        <form method="post" action=".">
            {{ threadform.as_table }}
            {{ postform.as_table }}
        <tr><td></td><td><input type="submit" value="{% trans "Update" %}"/></td></tr>
        </form>
        </table>
    </div>
    {% endblock %}
    By timc3 on the
    June 21st, 2008
  9. Looks like Django is really taking off

    Since the introduction of Google’s appengine which includes support for some of Django’s code, and the template system there has been an incredible amount of press for Django.

    At the moment there is no backend support for AppEngine in Django (and DB2 support is still lacking – there was a blog post about a year ago but nothing seems to have happened since, and I would love to be proved wrong on that one) but it must only be a matter of time before this happens so for the moment you have to disable the ORM support. Pity, but I can see why.

    But I am glad that Django is getting the attention that it deserves, I have long know that Python is well used in Google (and Yahoo for that matter), and now we should see even more people using Django which can only be a good thing for the ever-growing community.

    Here is an excellent write-up on Google App Engine http://www.dougma.com/archives/81

    By timc3 on the
    April 18th, 2008