Tuesday, October 28, 2008
The google app engine roadmap has been publicly released. One of the things that caught my attention was the support for new runtime language. Rumors have been running around that GAE platform will be supporting both java and php but google never confirmed anything.
What if GAE supports PHP?
Both Java and PHP community will be happy but considering that PHP applications can be hosted for as low as 4 USD a month, I dont think people will easily jump from using hosting service to GAE platform.
What if GAE supports Java?
The main reason why people turn away from java is because of the high cost of its hosting. Allowing small java developers/players to host their applications for free will be fantastic.
I created a survey so you can all vote for what you think (and what you want) GAE to support next.
http://www.surveymonkey.com/s.aspx?sm=kSlGNa0ZFh2iKmq5tY7HcA_3d_3d
Saturday, October 18, 2008
As I was browsing, I came across an article used to host python web applications better. The module called 'mod_wsgi' is a new&better apache module than mod_python when hosting django/python apps. I haven't personally tried it (maybe I will this coming weekend) but the comments by other people are very interesting. Anyway to give you some short round-up, this are the things that it can do:
- Can serve dynamic content by about 100-150% faster compare to mod_python
- Consumes less memory
- Secure (Don't know yet why it's secure)
Links:
http://code.google.com/p/modwsgi/
http://www.technobabble.dk/2008/aug/25/django-mod-wsgi-perfect-match/
http://code.djangoproject.com/wiki/django_apache_and_mod_wsgi
Saturday, October 18, 2008
Here is the base class of my entities. This one supports deleting of record by marking instead of permanently deleting the record:
class BaseModel(models.Model):
"""
Base model for all entities
"""
date_created = models.DateTimeField(auto_now_add=True)
date_updated = models.DateTimeField(auto_now=True, auto_now_add=True)
def delete(self, permanent=False):
"""
Delete a model by flagging. An optional parameter 'permanent' can be passed to permanently delete it
"""
if BaseModel.__deletable_type(self.__class__) and not permanent:
self.deleted = 1
self.save()
else:
models.Model.delete(self)
@classmethod
def all(cls, include_deleted=False):
"""
Get all query object with deleted records filtered
"""
deleted_field = hasattr(cls, "deleted")
if BaseModel.__deletable_type(cls) and not include_deleted:
query = cls.objects.all()
return query.filter(deleted=False)
else:
return cls.objects.all()
@classmethod
def __deletable_type(cls, input_cls):
"""
Check if this class is deletable by flagging. The algorithm is slow so it needs some tweaking later
"""
for b in input_cls.__bases__:
if b.__name__ == 'BaseDeletableUserModel': return True
return False
class Meta:
abstract = True
class BaseDeletableModel(BaseModel):
"""
A deletable base model
"""
deleted = models.BooleanField(default=False)
class Meta:
abstract = True
The code above still needs to be improved so any kind of comments will be appreciated.
Saturday, October 18, 2008
I don't know why python did'nt simply followed the standard way of using a ternary operator. Instead of following the usual format:
(x > 10) ? true_value : false_value
Python uses a different one:
x > 10 and true_value or false_value
Saturday, October 18, 2008
At the moment I dont know how to test django components from eclipse so I'm running my test on the terminal window. To test your django components, create a tests.py file on your application folder. For example my myapp/tests.py looks like the following:
from myapp.models import *
from myapp.forms import *
from mypp import log
import unittest
class CountryTestCase(unittest.TestCase):
"""
Test case for country model
"""
def setUp(self):
log.debug('Running CountryTestCase')
def testCountCountries(self):
allquery = Country.objects.all()
self.assertTrue(allquery.count() > 0)
class RegistrationTestCase(unittest.TestCase):
"""
Test case for user registration
"""
def setUp(self):
user = User(email='reyjexter@gmail.com', username='reyjexter@gmail.com', is_superuser=0,is_staff=0, is_active=1)
user.save()
user = User(email='core_reyj@yahoo.com', username='core_reyj@yahoo.com', is_superuser=0,is_staff=0, is_active=0)
user.save()
def tearDown(self):
userquery = User.objects.all()
for user in userquery:
user.delete()
def testFailedRegistration(self):
postdata = {
'email': 'reyjexter@gmail.com',
'password': 'rey123',
'confirm_password': 'rey123',
}
form = UserRegistrationForm(postdata)
self.assertFalse(form.is_valid())
postdata = {
'email': '',
'password': 'rey123',
'confirm_password': 'rey123',
}
form = UserRegistrationForm(postdata)
self.assertFalse(form.is_valid())
postdata = {
'email': 'rey@ideyatech.com',
'password': 'rey123',
'confirm_password': 'rey1234',
}
form = UserRegistrationForm(postdata)
self.assertFalse(form.is_valid())
def testSuccessRegistration(self):
postdata = {
'email': 'rey@ideyatech.com',
'password': 'rey123',
'confirm_password': 'rey123',
}
form = UserRegistrationForm(postdata)
self.assertTrue(form.is_valid())
countBeforeInsert = User.objects.all().count()
form.save()
self.assertTrue(User.objects.all().count() == countBeforeInsert+1)
To execute the test simple run:
./manage.py test myapp
Or to run individual test, run this one:
./manage.py test myapp.RegistrationTestCase