Showing posts with label startups. Show all posts
Showing posts with label startups. Show all posts
, ,

How to check if you respect web design standards and best practices?

webmaster desktop
webmaster desktop (Photo credit: FSA 2006-07)
Do you know how to check if your web page respect web design standards and best practices?

If no, the following web page provides a great checklist, which permits you to verify (or discover) if you have designed your website correctly:
 http://webdevchecklist.com/
It may be a good idea too to learn about responsive design, if you want your page to work on all screens. We are in the mobile era !



Share:
Read More
,

How to know the size (number of row/records) of a mysql database?


In this post, I will show you how to know the size (number of row/records) of a MySql database.

I wanted to host an app on heroku. They offer free database for up to 10000 rows. So, I needed to know if my database fits into that limit...


$ mysql -u root -p 

mysql> use my_site_db
mysql> SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'my_site_db';
+-----------------+
| SUM(TABLE_ROWS) |
+-----------------+
| 9662 |
+-----------------+
1 row in set (0.03 sec)

My database contains 9662 records.


Share:
Read More
,

How to solve svn arborescence conflicts?

Check Out from Subversion Server
Check Out from Subversion Server (Photo credit: xmodulo)
SVN is a great version control sytem. I use it to have all my files synchronized among the many computers I use.

SVN arborescence conflicts typically occur when you delete a folder without using the appropriate SVN commands (e.g., "rm -Rf myfolder" instead" of "svn delete myfolder"). The easiest solution to solve such conflicts is is to do a "revert", as follows:

cd my_folder
svn revert
svn update
svn delete the_folders_I_want_to_delete
svn commit


Share:
Read More
,

Using files in a django models.py

Django logo
Django logo (Photo credit: Wikipedia)
Django is a great web development framework. It provides a lot of features to setup a professional website in minutes. However, sometimes the errors messages that it provides are complex to understand. I am describing below how to solve an error that occurs if you want the user to upload a file to a django-based website. In this case, you need to define a file field in models.py:

    originalTextFile = models.FileField(upload_to='documents/%Y/%m/%d') # original text if it was submitted as a file
If you forget the upload_to attribute you will have the following error: 

./manage.py syncdb
Error: One or more models did not validate:
textModif.texttask: "originalTextFile": FileFields require an "upload_to" attribute.
To solve this error, you need to define the following elements in the settings.py Django configuration file:

MEDIA_ROOT = '/path/to/myproject/media/'
MEDIA_URL = '/media/'
With all these parameters correctly positioned, Django will store files to "media/documents/2012/11/24/" based on the current date and the content of the MEDIA_ROOT variable.

Acknowledgment: this post is largely inspired from the following page.



Share:
Read More
, ,

Discovering Django on Debian - part 3: creating the models (example of a text processing web app)


Django logo
Django logo (Photo credit: Wikipedia)
Have a look to the first two parts of this serie of Django tutorials, to see how to install virtualenv and django, and how to configure django with a mysql database.

First a bit of vocabulary. We have seen that Django creates a package that contains the configuration of our website and various management scripts. The content of our website will be a single web application that will process a user's input submitted through a form. Let's initialize this app:

python manage.py startapp textModif
This command will create a folder (a python package) named textModif. 

geany textModif/*.py &
The most important part of our website's design comes now. We need to identify the pieces of data that we will manipulate in our web app. This is called the model of our web app. We edit models.py and write: 

from django.db import models

# Create your models here.
class TextTask(models.Model):
description = "A query submitted to the web app and the result of the web app operations"
originalText = models.CharField(max_length=10000)
finalText = models.CharField(max_length=10000)
task_date = models.DateTimeField('date requested')
def __unicode__(self):
return self.originalText


class TextOperation(models.Model):
description = "A type of operation the web app did on the submitted text"
modifType = models.CharField(max_length=1000)
modifDescription = models.CharField(max_length=1000)
def __unicode__(self):
return self.modifTypeclass TextModification(models.Model):
description = "A specific change the web add did on the text. For instance, delete a word in a sentence."
task = models.ForeignKey(TextTask)
operation = models.ForeignKey(TextOperation)
originalText = models.CharField(max_length=1000)
finalText = models.CharField(max_length=1000)
def __unicode__(self):
return self.originalText

Now we can indicate to Django that we want to use our web app in the scope of the django project on which we work (that I named "djangoProj_1"). To do this, we edit the settings.py of our project and add:

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'textModif',
We request Django to create the tables in our database in accordance to our model: 
python manage.py sql textModif
If everything looks ok; we can commit the SQL configuration: 
python manage.py syncdb
This commands configures mysql and also creates apis so that we can access the database conveniently through python instructions. Let's try a few things as in Django's official tutorial. We first launch django's python shell (it's configured with appropriate environment variables) 

python manage.py shell
Then, let's play 

from textModif.models import *
from django.utils import timezone
# let's list our tasks (none exists for the moment)
TextTask.objects.all()
t1 = TextTask(originalText = "INFANDUM, REGINA, JUBES RENAVARE DOLOREM",
finalText = "Queen, you order to re-open cruel injuries",
task_date = timezone.now())
# let's list our tasks in the database (none exists for the moment as we have not committed our changes to mysql)
TextTask.objects.all()
t1.save
# let's see the id of our object in the database
t1.id
t1.originalText
Now our item is correctly saved in the database: 

>>> TextTask.objects.all()
[]

Note that in the list, our object is described through a call to the "__unicode__" method that we have defined in models.py.


Share:
Read More