»
S
I
D
E
B
A
R
«
IntelliJ IDEA 9 released
Dec 9th, 2009 by evereq

Hi! It’s good news today for a lot of java, ruby and groovy developers – new version “Maia” (officially v9) was just released by JetBrains with a lot of new features (including faster environment, extensive Java 6 support, build-in Google App Engine and Grails projects support etc) – feel read full “What’s new” list.

There exists also not so good news – this time for PHP developers – support of PHP was removed from release of free (”community”) version of IDEA, so developers can stick with other completely free IDEs this time :( – for example NetBeans comes to my mind this time… as alternative… but after Oracle buy Sun, I not sure it is right choice… but this is “idea” for another post…)

Actually personally I don’t understand why “Community” version does not support PHP, Javascript, Python or Ruby as this languages are used by a lot (if not most) of “open source” developers that for some reasons does not feet into JetBrains licensing of commercial version of IntelliJ IDEA for open source projects. I think “vice versa” if compare to JetBrains – Commercial version must have extended support for Java development, while Community edition must support MORE other open source frameworks / languages, like Ruby, Python or PHP etc. Sure it’s only my “personal” opinion, but I think most of developers will agree with me – people that use IDEA for Java development (usually in enterprises) can (and will!) simply BUY commercial licenses, while a lot of potential IntelliJ users actually want to use it for small open source projects in non-Java languages stack and want to get IDE for FREE!

But totally – all new features show that JetBrains go in right direction – support for most “progressive” and “latest” technologies in IDEA (even if it is available only commercially ;-) )

Keep it going, JetBrains! ;-)

Some Django Links
Nov 21st, 2009 by evereq

Some interesting Django related links:

A Django project. - Django Project Home
Google “Go” become “issue 9″
Nov 19th, 2009 by evereq

Today I get a talk with my friend regarding new programming language emerged by Google with “interesting” name  “Go”.

Actually we both agree that we don’t see any reason to invent another “low level” / “middle” level compiled programming language… with Nothing NEW inside (see notes at the end of the post)! Just reuse of best practices, but with a LOT of limitations compared with C++ for example  (just take a look here for some comparison information – most impressive that Google decide: “Go does not have classes with constructors or destructors. Instead of class methods, a class inheritance hierarchy, and virtual functions, Go provides interfaces, which are discussed in more detail below. Interfaces are also used where C++ uses templates.”… very strange for me… I can agree with C# approach for such details, but seems Google approach is too much!!! I note sure is it really OOP  or not if you have only interfaces in hands…. when I do everyday development in C#, at least few times per day I not happy that I don’t have true multiple inheritance, what developers will say about “Go” if they start use it everyday??? )!

Personally I think that if Google want invent some “own” programming language (and only in case if they really want OWN…) they need to take a look into high (or very high) level multi paradigm languages like  F# or Scala (or at least on Groovy with his meta programming features for example) and does not invent another “c/c++” or “Python” inspired language !

But what is most interesting and curious is that Google give the name for new language exactly same like another person name his language few years ago!  To be more concrete, go to the issue 9 page in google issues tracking page for new language:

“Issue 9: I have already used the name for *MY* programming language”

Amazing! Just read comments! Ha ha ha! Never see something like this before regarding programming languages! Google took this name and even not “google” for it ;-) ! Amazing stupid mistake! Yes, even companies like Google with best and talented people made such stupid mistakes! Actually, I not sure that name “Go” anyway is a good name for such language (and not only me think this way – read comments to issue 9 to get many examples!)…

Even for me, with average (or even low) level of English it looks strange that something that they promote as “fast” have the name “Go” (as we all know most of things that “Go” is slow by default)… Why they not name it “Run” , if they want that this language actually “run” ?! Or like many people suggest “Goo” (from Google) ?

Anyway, it looks really curious…….. :)

Hope this will just “push” Google to develop BETTER OWN language (it MUST be HIGH level or VERY HIGH level language for sure!!!) and probably select for it BETTER name!

Notes:
1) in this post I follow latest definitions for  “low level” and “high level” languages… Sure long time ago, “low level” was assembler and C was “high level” language! But currently, it looks like languages like C become really “low level” also! You can check for example following Wikipedia article to get more information).  After reading most of information on Go language website, I still not sure can we call this language “Object Oriented” for example… In most areas approach of Google looks minimum “strange”… Except maybe how they implement concurrency… Maybe I just need to try to code something on it to get  better understanding?)
2) Please note that I DON’T describe “Go” language as “bad” language. Instead I just put it to “low level” or “middle level” where it looks perfectly!  Sure Google will found A LOT of ways how to use this language (and I think maybe already found such ways – for example to embed it in Chrome – read more here) and will “push” usage of  this language inside Google and sure outside! And Google really have resources to do this! And some people will probably LIKE new simple but speed language! What I just NOT happy is that this language is NOT really high level language (NO Generics for example, at least by now!). Sure it’s just first release, maybe Google will improve it… but  Google likes “minimalism” style, so….. Anyway, let’s just wait a little! Maybe they change language name and Universe! ;-)

Evejob Sprint #1 Domain Model Part #2: EvejobDJ Django Models
Nov 10th, 2009 by evereq

OK, in Part #1 we already figure out what Models we need to create. Because Django support concept of “applications” inside one project, we can actually start creating models for 3 applications:

  • Accounts (User profiles, registration, authentication / authorization etc)
  • Companies (Companies catalog, profiles etc)
  • Common (seems City and Country are good example of entities that will be used in other applications)

Django internally support following concepts that will be used in Accounts application:

  1. Users
  2. Groups (known in other frameworks as “User Roles”)
  3. User Profile (you need to create your own model for it, but Django have special support for this)
So, Let’s create “accounts” Django Application that will dial with Users Registration, Login, Logout, Profiles etc
cd c:\evejob\EvejobDJ
python manage.py startapp accounts

The same way, you can create now “common” and “companies” applications in EvejobDJ project.

Let’s take a look into possible simple “accounts” application model.py file:

from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
 
class UserProfile(models.Model):
 
    # required field - user that own profile
    user = models.ForeignKey(User, unique=True)
 
    # optional Job Title
    job_title = models.CharField(_("Job Title"), max_length=128, null = True, blank = True)
 
    # optional Phone Number
    phone = models.CharField(_("Phone"), max_length=16, null = True, blank = True)
 
    # Boolean stored as tinyint in MySQL database, but it's ok for now
    allow_site_to_contact_by_email = models.BooleanField(_("Allow site to contact me by email"))
    allow_site_partners_to_contact_by_email = models.BooleanField(_("Allow site partners to contact me by email"))
    allow_site_to_contact_by_phone = models.BooleanField(_("Allow site to contact me by phone"))
    allow_site_partners_to_contact_by_phone = models.BooleanField(_("Allow site partners to contact me by phone"))
 
    def __unicode__(self):
       return self.user.username

Let’s review now most important aspects of this code:

from django.contrib.auth.models import User

Line above import already defined in Django User Model. We not going to create our own User Model and will try to reuse as much as possible from what is available in Django framework. But because we need to hold additional user details (like job title or phone for example), we create “UserProfile” model, that reference User as Foreign Key:

# required field - user that own profile
user = models.ForeignKey(User, unique=True)

Also we are going to use “Internationalization” (I18N) build in into Django functionality to made our site available in few languages:

from django.utils.translation import ugettext_lazy as _

After such import, to translate string from one language into another we need just use _(”String to translate”) pattern (sure and also define translations some way – more about it in dedicated article)

Other code just define different fields of UserProfile that we want actually to store in Database (some of them are strings, some booleans).

Last two lines used to get a “string” representation of the model that will be used in Django Admin for example (same idea like you can “override ToString()” in C#):

    def __unicode__(self):
       return self.user

That’s it for accounts application regarding models!

For “common” application we will have to define two model classes (City and Country):

from django.db import models
from django.contrib.auth.models import User
import EvejobDJ.settings as settings
from django.utils.translation import ugettext_lazy as _
 
class Country(models.Model):
 
    # required Unique Company Name
    name = models.CharField(_("Name"), max_length=255, unique = True)
 
    def __unicode__(self):
       return '%s' % (self.name)
 
    class Meta:
       verbose_name = _('Country')
       verbose_name_plural = _('Countries')
 
class City(models.Model):
 
    # required Unique Company Name
    name = models.CharField(_("Name"), max_length=255, unique = True)
 
    country = models.ForeignKey(Country, unique = False)
 
    def __unicode__(self):
       return '%s' % (self.name)
 
    class Meta:
       verbose_name = _('City')
       verbose_name_plural = _('Cities')

Exactly same logic like for Profiles, with small addition to made correct “plural” name for entity using definitions for “verbose_name_plural” field on Meta class. This will allow to see “Cities” or “Countries” in Admin, instead of automatic “Citys” or “Countrys” :)

    class Meta:
       verbose_name = _('City')
       verbose_name_plural = _('Cities')

And last models that we need to produce in Sprint #1 is for Companies – Company and CompanyLogo.
Let’s review following code:

from django.db import models
from django.contrib.auth.models import User
import EvejobDJ.settings as settings
from django.utils.translation import ugettext_lazy as _
 
class Company(models.Model):
 
    # required Unique Company Name
    name = models.CharField(_("Name"), max_length=255, unique = True)
 
    # user that create this company first time.
    creation_by = models.ForeignKey(User, unique = False)
 
    # when user create this company first time. Django Automatically set the field to now when Company created for the first time
    creation_date = models.DateTimeField(_("Create Date"), auto_now_add = True)
 
    city = models.ForeignKey('common.City', unique = False, null = True, blank = True)
    country = models.ForeignKey('common.Country', unique = False, null = True, blank = True)
 
    # logo = models.OneToOneField('CompanyLogo', related_name='logo', verbose_name = "company logo")
    # But this is not needed, as you always can get access to logo using something like
    # (read more http://docs.djangoproject.com/en/dev/topics/db/queries/#one-to-one-relationships)
    # e = Company.objects.get(id=2)
    # e.companylogo
 
    def __unicode__(self):
       return '%s' % (self.name)
 
    class Meta:
       verbose_name = _('Company')
       verbose_name_plural = _('Companies')
 
class CompanyLogo(models.Model):
 
    company = models.OneToOneField(Company, primary_key=True)
 
    # user that create this logo first time.
    creation_by = models.ForeignKey(User, unique = False)
 
    # when user create this logo first time. Django Automatically set the field to now when logo created for the first time
    creation_date = models.DateTimeField(_("Create Date"), auto_now_add = True)
 
    caption = models.CharField(blank=True, null = True, max_length=100)
 
    image = models.ImageField(upload_to=settings.COMPANY_LOGO_RELATIVE_ROOT)
 
    def __unicode__(self):
       return '%s' % (self.company.name)
 
    class Meta:
       verbose_name = _('Company Logo')
       verbose_name_plural = _('Companies Logos')

Let’s take a look into some interesting things here… First of all, we will store currently company logo images in file system (but later we can use another storage provider). Thanks to Django, it have special field type for this: “ImageField”. Ones we add field with this type, we need to make sure that we install PIL library. You can read about some installation issues of it on dedicated post). Second take a look into “auto_now_add” parameter in creation_date field – this will instruct Django to automatically set the field to current date when user create new company logo! And last most important thing in this models is One To One relation (using models.OneToOneField) between CompanyLogo and Company entities! You can read more information about Django support of “One To One” relations” if you interesting in details.

That’s all regarding Models itself. Let me know if have any questions!

Notes:
To run code that you see above (at least to be able to create database using ‘python manage.py syncdb’ command), you need to made some settings in settings.py file. At minimum you need to add “accounts”, “companies” and “common” into Django Applications list:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.flatpages',
    'common',
    'accounts',
    'companies',
)

Also you probably need to define some settings like COMPANY_LOGO_RELATIVE_ROOT in same settings.py file.
In any case, I recommend to wait a little and read next post to get more information how to actually run EvejobDJ models and create views!
So keep reading!
;)

P.S. And last thing: I want to let you know that Python is NOT my “primary language of choice”. Means that I DON’T do everyday coding on it (instead of C# for example), so if you see (and feel) that I do something wrong, or that it can be done in Python better please let me know!

Evejob Development Environment Installation Part #1: Python, Django + AppEngine Installation
Oct 21st, 2009 by evereq

OK, let’s start installation of the development environment from Python + Django.

Here is step by step instructions:

1) Go to http://www.python.org/download/. Download 64 bit Python (if you use Windows 7 64 bit like me or other 64 bit OS) version 2.6.x (do not install version 3.x as Django not yet available for this Python version) – usually file have name like “python-2.6.x.amd64.msi”.
I recommend to change setup path to C:/Python, instead of C:/Python26

Python Download

2) Go to Control Panel\System and Security\System in Explorer. Than press “Advanced System Settings”. In System Properties window go to “Advanced” tab and press “Environment Variables” button. Here you need to add path to python in “System Variables”. Just found here “Path” and append “C:\Python”.

Add Path to Python

Note: I show here and will show in future ways how to finish tasks using windows GUI (if available), instead of command prompt commands (for example instead of usage of PATH command). Sure thing most of operations now can be done using command prompt, especially after introduction of PowerShell by Microsoft (it is build in to Windows 7 / Windows 2008 R2)

3) Go to command prompt (cmd.exe) and check that you can run actually Python by typing “python”.

Python

4) To grab latest source code from SVN repositories (for Django and other soft), let’s install now Subversion Client from http://www.collab.net/downloads/subversion/. I suggest to have this client even in case if you going to use TortoiseSVN. Why? Reason very simple – ones you study how to use it, you will know how to work with SVN in ANY OS, not only in Windows! It is exactly example, when better to use command prompt commands, instead of GUI like I recommend above – in such cases you will be familiar with command that runs on all kinds of operation systems!

CollabNet Subversion Command-Line Client vx.x.x (for Windows)

You can download installation after simple registration. Ones you install SVN client, go to command prompt and try to enter “svn” command. Hopefully you will get something like this:

SVN

4) I will use so called “development version” of Django. To install it you need to execute following command:

svn co http://code.djangoproject.com/svn/django/trunk/ C:\django-trunk

This will download latest source code for Django and save it in C:\django-trunk folder. Now it is time to setup PYTHONPATH variable (same way like in topic 2, but this time you need to create new variable, not just edit existed one!)

PythonPath

And before you leave Environment Variables, let’s add to the PATH variable location of Django bin folder (C:\django-trunk\django\bin):

DjangoAdminPath

Now it is time to check this setting:

TestDjangoAdminPy

Great Django installed!

One more simple step in installation of gettext-utils that used in Django translation system: go to the http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/ and download latest  gettext-runtime-X.zip and gettext-tools-X.zip files. Extract content from bin folders of archives to c:\gettext-utils folder and add this path to PATH variable, same way like add before another locations (see details in topics above):

gettext

5) Now it is time to overview folders structure for project:

- C:\Evejob will be home directory for all source code for Evejob project

- C:\Evejob\EvejobDJ will be home directory for Django version of Evejob

- C:\Evejob\EvejobDJG will be home directory for Django + Google AppEngine version of Evejob.

Now, let’s run in command prompt following commands:

CreateEvejobDJProject

Let’s check that at least Django build-in web server works fine:

DjangoWebServerWorks

Please note: Django version can be different on your machine!

Open in browser http://127.0.0.1:8000 and make sure you see something like this:

FirstDjangoInBrowser

The same way, let’s create EvejobDJG Project that will be tuned up to work with Google AppEngine (all command like before, just EvejobDJG used instead of EvejobDJ):

CreateEvejobDJGProject

6) Django and AppEngine integration

Ok, now let’s install Google AppEngine SDK for Python available at http://code.google.com/intl/en/appengine/downloads.html#Google_App_Engine_SDK_for_Python

I assume that SDK will be installed in following folder: C:\Google\google_appengine\

Also we will need to install the Python for Windows extensions to enable automatic detection of the SDK. Be careful and download 64 bit version, for example pywin32-214.win-amd64-py2.6.exe if you use Windows 64 bit like me. Installation will automatically found your Python language, so if you download correct version of pywin, you will not get any problems during installation at all.

7) Today available few helpers (projects) that can help us create Django application that will be hosted on Google App Engine.

More specifically exists two: Google App Engine Helper for Django (http://code.google.com/p/google-app-engine-django) and App-Engine-Patch (http://code.google.com/p/app-engine-patch)

Each library have own features, but main difference that with App-Engine-Patch you have to use Google’s Model class, while with Google App Engine Helper you can use BaseModel class that appears the same as the standard Django Model class…

Here are some interesting articles related to Django and AppEngine combination:

http://code.google.com/appengine/articles/django.html

http://code.google.com/appengine/articles/appengine_helper_for_django.html

http://www.42topics.com/dumps/appengine/doc.html

http://www.42topics.com/dumps/django/docs.html

http://thomas.broxrost.com/2008/04/08/django-on-google-app-engine/

I will come back to this libraries later, ones finish with more simple EvejobDJ standard Django Model…

»  Substance: WordPress   »  Style: Ahren Ahimsa
© Copyright 2008–2009 EvereQ.com All rights reserved.