How to use django-pagination with django-table

How to use django-pagination

django-pagination allows for easy Digg-style pagination without modifying your views.

There are really 5 steps to setting it up with your projects (not including installation, which is covered in INSTALL.txt in this same directory.)
  1. List this application in the INSTALLED_APPS portion of your settings file. Your settings file might look something like:
    INSTALLED_APPS = (
    # ...
    'pagination',
    )
  2. Install the pagination middleware. Your settings file might look something like:
    MIDDLEWARE_CLASSES = (
    # ...
    'pagination.middleware.PaginationMiddleware',
    )
  3. If it's not already added in your setup, add the request context processor. Note that context processors are set by default implicitly, so to set them explicitly, you need to copy and paste this code into your under the value TEMPLATE_CONTEXT_PROCESSORS:
    ("django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request")
  4. Add this line at the top of your template to load the pagination tags:
    {% load pagination_tags %}
  5. Decide on a variable that you would like to paginate, and use the autopaginate tag on that variable before iterating over it. This could take one of two forms (using the canonical object_list as an example variable):
    {% autopaginate object_list %}
    This assumes that you would like to have the default 20 results per page. If you would like to specify your own amount of results per page, you can specify that like so:
    {% autopaginate object_list 10 %}
    Note that this replaces object_list with the list for the current page, so you can iterate over the object_list like you normally would.
  6. Now you want to display the current page and the available pages, so somewhere after having used autopaginate, use the paginate inclusion tag:
    {% paginate %}
    This does not take any arguments, but does assume that you have already called autopaginate, so make sure to do so first.
That's it! You have now paginated object_list and given users of the site a way to navigate between the different pages--all without touching your views.



Continue reading if you use Django-table and pass a table to the template. You will find that it will fail to show the web in paged style , when you trying to use   {% autopaginate table.rows 25 %}. The following code works this out:

{% extends "base.html" %}
{% load i18n %}
{% load pagination_tags %}
{% block title %}{% trans "Demographics" %}{% endblock %}

{% block content %}
   
   
   
   
        {% for column in table.columns %}
       
       
        {% endfor %}
   
   
    {% with table.rows as rows %}
    {% autopaginate rows 25 %}
    {% for row in rows %}
   
           
            {% for value in row %}
           
           
            {% endfor %}
           
    {% endfor %}
    {% paginate %}
    {% endwith %}
   
       
       
{{ column }}
{{ value }}

{% endblock %}

How to use django-pagination with django-table

How to use django-pagination

django-pagination allows for easy Digg-style pagination without modifying your views.

There are really 5 steps to setting it up with your projects (not including installation, which is covered in INSTALL.txt in this same directory.)
  1. List this application in the INSTALLED_APPS portion of your settings file. Your settings file might look something like:
    INSTALLED_APPS = (
        # ...
        'pagination',
    )
  2. Install the pagination middleware. Your settings file might look something like:
    MIDDLEWARE_CLASSES = (
        # ...
        'pagination.middleware.PaginationMiddleware',
    )
  3. If it's not already added in your setup, add the request context processor. Note that context processors are set by default implicitly, so to set them explicitly, you need to copy and paste this code into your under the value TEMPLATE_CONTEXT_PROCESSORS:
    ("django.core.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request")
  4. Add this line at the top of your template to load the pagination tags:
    {% load pagination_tags %}
  5. Decide on a variable that you would like to paginate, and use the autopaginate tag on that variable before iterating over it. This could take one of two forms (using the canonical object_list as an example variable):
    {% autopaginate object_list %}
    This assumes that you would like to have the default 20 results per page. If you would like to specify your own amount of results per page, you can specify that like so:
    {% autopaginate object_list 10 %}
    Note that this replaces object_list with the list for the current page, so you can iterate over the object_list like you normally would.
  6. Now you want to display the current page and the available pages, so somewhere after having used autopaginate, use the paginate inclusion tag:
    {% paginate %}
    This does not take any arguments, but does assume that you have already called autopaginate, so make sure to do so first.
That's it! You have now paginated object_list and given users of the site a way to navigate between the different pages--all without touching your views.



Continue reading if you use Django-table and pass a table to the template. You will find that it will fail to show the web in paged style , when you trying to use   {% autopaginate table.rows 25 %}. The following code works this out:

{% extends "base.html" %}
{% load i18n %}
{% load pagination_tags %}
{% block title %}{% trans "Demographics" %}{% endblock %}

{% block content %}
    <table width="20%" border="2">
    <tr>
    </tr>
    <tr>
        {% for column in table.columns %}
        <td>       
        <th><a href="?sort={{ column.name_toggled }}">{{ column }}</a></th>
        </td>
        {% endfor %}
    </tr>
   
    {% with table.rows as rows %}
    {% autopaginate rows 25 %}
    {% for row in rows %}
   
            <tr>
            {% for value in row %}
            <td > {{ value }} </td>
           
            {% endfor %}
            </tr>
    {% endfor %}
    {% paginate %}
    {% endwith %}
    </table>
{% endblock %}

Import existing Django project into Eclipse with PyDev


**Here the existing Django project means the project is not created within the eclipse environment

1. Create two files within the current Django project: .project file and .pydevproject. Make sure you make the appropriate changes.

.project contents (must replace the MyProject with the project name)



    MyProject
   
   
   
   
       
            org.python.pydev.PyDevBuilder
           
           
       
   
   
        org.python.pydev.pythonNature
   



.pydevproject contents (must replace the path (/MyProject/src) with the actual folders to be in the PYTHONPATH)

In most situtaions /MyProject/src will be replaced with the Django project name.




    Default
    python 2.7
   
   
   
        /MyProject/src
   



2. Open eclipse and use import>>Existing project into Workspace. In the next screen, the root directory is your current django project root.


Import existing Django project into Eclipse with PyDev


**Here the existing Django project means the project is not created within the eclipse environment

1. Create two files within the current Django project: .project file and .pydevproject. Make sure you make the appropriate changes.

.project contents (must replace the MyProject with the project name)

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>MyProject</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.python.pydev.PyDevBuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.python.pydev.pythonNature</nature>
    </natures>
</projectDescription>


.pydevproject contents (must replace the path (/MyProject/src) with the actual folders to be in the PYTHONPATH)

In most situtaions /MyProject/src will be replaced with the Django project name.

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
    <pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
    <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
    <pydev_variables_property name="org.python.pydev.PROJECT_VARIABLE_SUBSTITUTION">
    </pydev_variables_property>
    <pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
        <path>/MyProject/src</path>
    </pydev_pathproperty>
</pydev_project>


2. Open eclipse and use import>>Existing project into Workspace. In the next screen, the root directory is your current django project root.


How to use rsync for transferring files under Linux or UNIX

rsync command common options

  • --delete : delete files that don't exist on sender (system)
  • -v : Verbose (try -vv for more detailed information)
  • -e "ssh options" : specify the ssh as remote shell
  • -a : archive mode
  • -r : recurse into directories
  • -z : compress file data

Task : Copy file from a remote server to a local computer

Copy file /home/tommy/webroot.txt from a remote server openbsd.nixcraft.in to a local computer /tmp directory:
$ rsync -v -e ssh tommy@openbsd.nixcraft.in:~/webroot.txt /tmp
Password


Task: Synchronize a local directory with a remote directory

$ rsync -r -a -v -e "ssh -l jerry" --delete openbsd.nixcraft.in:/webroot/ /local/webroot


How to use rsync for transferring files under Linux or UNIX

rsync command common options

  • --delete : delete files that don't exist on sender (system)
  • -v : Verbose (try -vv for more detailed information)
  • -e "ssh options" : specify the ssh as remote shell
  • -a : archive mode
  • -r : recurse into directories
  • -z : compress file data

Task : Copy file from a remote server to a local computer

Copy file /home/tommy/webroot.txt from a remote server openbsd.nixcraft.in to a local computer /tmp directory:
$ rsync -v -e ssh tommy@openbsd.nixcraft.in:~/webroot.txt /tmp
Password


Task: Synchronize a local directory with a remote directory

$ rsync -r -a -v -e "ssh -l jerry" --delete openbsd.nixcraft.in:/webroot/ /local/webroot


RSync backups

Syntax

$ rsync options source destination

Example 1. Synchronize Two Directories in a Local Server

$ rsync -zvr /var/opt/installation/inventory/ /root/temp

In the above rsync example:

    -z is to enable compression
    -v verbose
    -r indicates recursive

Example 2. Preserve timestamps during Sync using rsync -a

rsync option -a indicates archive mode. -a option does the following,

    Recursive mode
    Preserves symbolic links
    Preserves permissions
    Preserves timestamp
    Preserves owner and group

$ rsync -azv /var/opt/installation/inventory/ /root/temp/

Example 3. Synchronize Only One File

To copy only one file, specify the file name to rsync command, as shown below.

$ rsync -v /var/lib/rpm/Pubkeys /root/temp/

Example 4. Synchronize Files From Local to Remote

rsync allows you to synchronize files/directories between the local and remote system.

$ rsync -avz /root/temp/ thegeekstuff@192.168.200.10:/home/thegeekstuff/temp/

Example 5. Synchronize Files From Remote to Local

When you want to synchronize files from remote to local, specify remote path in source and local path in target as shown below.

$ rsync -avz thegeekstuff@192.168.200.10:/var/lib/rpm /root/temp

Example 6. Remote shell for Synchronization

rsync allows you to specify the remote shell which you want to use. You can use rsync ssh to enable the secured remote connection.

Use rsync -e ssh to specify which remote shell to use. In this case, rsync will use ssh.

$ rsync -avz -e ssh thegeekstuff@192.168.200.10:/var/lib/rpm /root/temp

Example 7. Do Not Overwrite the Modified Files at the Destination

In a typical sync situation, if a file is modified at the destination, we might not want to overwrite the file with the old file from the source.

Use rsync -u option to do exactly that. (i.e do not overwrite a file at the destination, if it is modified). In the following example, the file called Basenames is already modified at the destination. So, it will not be overwritten with rsync -u.

$ rsync -avzu thegeekstuff@192.168.200.10:/var/lib/rpm /root/temp

Example 8. Synchronize only the Directory Tree Structure (not the files)

Use rsync -d option to synchronize only directory tree from source to the destination. The below example, synchronize only directory tree in recursive manner, not the files in the directories.

$ rsync -v -d thegeekstuff@192.168.200.10:/var/lib/ .

Example 9. View the rsync Progress during Transfer

When you use rsync for backup, you might want to know the progress of the backup. i.e how many files are copies, at what rate it is copying the file, etc.

rsync –progress option displays detailed progress of rsync execution as shown below.

$ rsync -avz --progress thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/

Example 10. Delete the Files Created at the Target

If a file is not present at the source, but present at the target, you might want to delete the file at the target during rsync.

In that case, use –delete option as shown below. rsync delete option deletes files that are not there in source directory.

$ rsync -avz --delete thegeekstuff@192.168.200.10:/var/lib/rpm/ .

Example 11. Do not Create New File at the Target

If you like, you can update (Sync) only the existing files at the target. In case source has new files, which is not there at the target, you can avoid creating these new files at the target. If you want this feature, use –existing option with rsync command.

$ rsync -avz --existing root@192.168.1.2:/var/lib/rpm/ .

Example 12. View the Changes Between Source and Destination

This option is useful to view the difference in the files or directories between source and destination.-i option displays the item changes.

$ rsync -avzi thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/

Example 13. Include and Exclude Pattern during File Transfer

rsync allows you to give the pattern you want to include and exclude files or directories while doing synchronization.

$ rsync -avz --include 'P*' --exclude '*' thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/

Example 14. Do Not Transfer Large Files

You can tell rsync not to transfer files that are greater than a specific size using rsync –max-size option.

$ rsync -avz --max-size='100K' thegeekstuff@192.168.200.10:/var/lib/rpm/ /root/temp/

max-size=100K makes rsync to transfer only the files that are less than or equal to 100K. You can indicate M for megabytes and G for gigabytes.

Use wget to repeat download the similar items from a site

1.This command will repeat the wget command for each number enumerated in the { }

wget -nd http://www.cracked.com/blog/wp-content/uploads/2009/12/zorklon{1,2,3,4,5}.jpg

2. use -i option. You can put all the links in one txt file and use -i option to download them one by one.

wget -i fedoraisos.txt

3. Some other options

-c to resume an interrupted download session

--user=user_name

--password=password

--user-agent=agent-string: used when a site denies access to non-browser user agents.

Use wget to repeat download the similar items from a site

1.This command will repeat the wget command for each number enumerated in the { }

wget -nd http://www.cracked.com/blog/wp-content/uploads/2009/12/zorklon{1,2,3,4,5}.jpg

2. use -i option. You can put all the links in one txt file and use -i option to download them one by one.

wget -i fedoraisos.txt

3. Some other options

-c to resume an interrupted download session

--user=user_name

--password=password

--user-agent=agent-string: used when a site denies access to non-browser user agents.

Oil filter wrench cap for 09' Toyota Highalnder

Last week I was trying to change engine oil for my 09 highlander. But I had a hard time to take the engine oil filter cap off. I have tried couple wrench caps from Auto Zone. But they did not work. If you are in the same situation me, try this tool from Amazon.

Oil filter wrench cap for 09' Toyota Highalnder

Last week I was trying to change engine oil for my 09 highlander. But I had a hard time to take the engine oil filter cap off. I have tried couple wrench caps from Auto Zone. But they did not work. If you are in the same situation me, try this tool from Amazon.

CPAN error: failed with code[400] message[URL must be absolute}

While I was trying to install Imager::QRCode using cpan, I have this problem: failed with code[400] message[URL must be absolute]

Searching online I found that my urllist for cpan is empty. To correct problem:

run this command with in cpan O conf urllist push "Your_cpan_mirror_url" for example,

S sudo cpan

cpan> o conf urllist push http://cpan.yahoo.com/

Here are other o conf related commands for use:

To view the urllist: o conf urllist

To remove the first url from the urllist: o conf urllist shift

To save the configuration after you made modification: o conf commit

CPAN error: failed with code[400] message[URL must be absolute}

While I was trying to install Imager::QRCode using cpan, I have this problem: failed with code[400] message[URL must be absolute]

Searching online I found that my urllist for cpan is empty. To correct problem:

run this command with in cpan O conf urllist push "Your_cpan_mirror_url" for example,

S sudo cpan

cpan> o conf urllist push http://cpan.yahoo.com/

Here are other o conf related commands for use:

To view the urllist: o conf urllist

To remove the first url from the urllist: o conf urllist shift

To save the configuration after you made modification: o conf commit

Cannot print a pdf file?

Because you forget your password?

Try this command:

$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output_file.pdf -c .setpdfwrite -f source.pdf

If you want to combine more than one pdf file into one pdf file:

$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=new_3000.pdf -c .setpdfwrite -f /mnt/ncsfile01/3000/*.pdf

Cannot print a pdf file?

Because you forget your password?

Try this command:

$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output_file.pdf -c .setpdfwrite -f source.pdf

If you want to combine more than one pdf file into one pdf file:

$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=new_3000.pdf -c .setpdfwrite -f /mnt/ncsfile01/3000/*.pdf

Datatable static image not found on the server

When you use ```datatables.min.css``` and ```datatables.min.js``` locally, instead of datatables CDN, you may have encountered that ```sort...