<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AxiaCore Blog &#187; Python</title>
	<atom:link href="http://axiacore.com/blog/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://axiacore.com/blog</link>
	<description>Implementamos tecnologia y es asi como lo hacemos</description>
	<lastBuildDate>Fri, 29 Jan 2010 17:22:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Paginacion en Django estilo Digg</title>
		<link>http://axiacore.com/blog/2010/01/paginacion-en-django-estilo-digg/</link>
		<comments>http://axiacore.com/blog/2010/01/paginacion-en-django-estilo-digg/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 17:20:57 +0000</pubDate>
		<dc:creator>Camilo Nova</dc:creator>
				<category><![CDATA[AxiaCore]]></category>
		<category><![CDATA[Codigo Fuente]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://axiacore.com/blog/?p=800</guid>
		<description><![CDATA[La Paginación en django es excelente, permite una flexibilidad importante para solucionar muchos problemas que se presentan al paginar resultados, por ejemplo el problema del cacheo, que se presenta al realizar una consulta que pide todos los datos sabiendo que solo vamos a mostrar unos pocos.
Gracias a la excelente documentación podemos encontrar toda la información [...]]]></description>
			<content:encoded><![CDATA[<p>La Paginación en django es excelente, permite una flexibilidad importante para solucionar muchos problemas que se presentan al paginar resultados, por ejemplo el problema del cacheo, que se presenta al realizar una consulta que pide todos los datos sabiendo que solo vamos a mostrar unos pocos.</p>
<p>Gracias a la excelente documentación podemos encontrar toda la información aquí: <a href="http://docs.djangoproject.com/en/1.1/topics/pagination/#topics-pagination">http://docs.djangoproject.com/en/1.1/topics/pagination/#topics-pagination</a></p>
<p>Sin embargo, cuando se trabajan volúmenes grandes de información, digamos mas de 50 paginas, se hace dispendioso pasar entre paginas hasta llegar a la que buscamos, por eso es muy útil tener una paginación al estilo Digg que muestra algunas paginas adicionales y no solo el enlace a la anterior y la siguiente.</p>
<p>Tomando como base este excelente trabajo: <a href="http://krisje8.com/blog/2009/jul/02/django-pagination-template-tag-digg-style/ ">http://krisje8.com/blog/2009/jul/02/django-pagination-template-tag-digg-style/ </a>realice algunas modificaciones para que muestre &#8216;&#8230;&#8217; entre las paginas iniciales y la pagina actual, para darle una mejor ubicación al usuario sobre donde se encuentra.</p>
<p>Tenemos el siguiente <a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/">template_tag</a>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># -*- coding: utf8 -*-</span>
<span style="color: #808080; font-style: italic;"># render_paginator.py</span>
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span> <span style="color: #ff7700;font-weight:bold;">import</span> Library
&nbsp;
register = Library<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> render_paginator<span style="color: black;">&#40;</span>context, first_last_amount=<span style="color: #ff4500;">2</span>, before_after_amount=<span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>:
    page_obj = context<span style="color: black;">&#91;</span><span style="color: #483d8b;">'page_obj'</span><span style="color: black;">&#93;</span>
    paginator = context<span style="color: black;">&#91;</span><span style="color: #483d8b;">'paginator'</span><span style="color: black;">&#93;</span>
    page_numbers = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Pages before current page</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> page_obj.<span style="color: black;">number</span> <span style="color: #66cc66;">&gt;</span> first_last_amount + before_after_amount:
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, first_last_amount + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
            page_numbers.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
&nbsp;
        page_numbers.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #008000;">None</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>page_obj.<span style="color: black;">number</span> - before_after_amount, page_obj.<span style="color: black;">number</span><span style="color: black;">&#41;</span>:
            page_numbers.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, page_obj.<span style="color: black;">number</span><span style="color: black;">&#41;</span>:
            page_numbers.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Current page and pages after current page</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> page_obj.<span style="color: black;">number</span> + first_last_amount + before_after_amount <span style="color: #66cc66;">&lt;</span> paginator.<span style="color: black;">num_pages</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>page_obj.<span style="color: black;">number</span>, page_obj.<span style="color: black;">number</span> + before_after_amount + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
            page_numbers.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
&nbsp;
        page_numbers.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #008000;">None</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>paginator.<span style="color: black;">num_pages</span> - first_last_amount + <span style="color: #ff4500;">1</span>, paginator.<span style="color: black;">num_pages</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
            page_numbers.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>page_obj.<span style="color: black;">number</span>, paginator.<span style="color: black;">num_pages</span> + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
            page_numbers.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#123;</span>
        <span style="color: #483d8b;">'paginator'</span>: paginator,
        <span style="color: #483d8b;">'page_obj'</span>: page_obj,
        <span style="color: #483d8b;">'page_numbers'</span>: page_numbers
    <span style="color: black;">&#125;</span>
&nbsp;
register.<span style="color: black;">inclusion_tag</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'layout/pagination.html'</span>, takes_context=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span><span style="color: black;">&#40;</span>render_paginator<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Con la siguiente plantilla:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">{% if page_obj.has_previous %}
  &lt;a href=&quot;?page={{ page_obj.previous_page_number }}&quot;&gt;Previous&lt;/a&gt;
{% endif %}
{% for page in page_numbers %}
  {% if page %}
    {% ifequal page page_obj.number %}
      &lt;b&gt;{{ page }}&lt;/b&gt;
    {% else %}
      &lt;a href=&quot;?page={{ page }}&quot;&gt;{{ page }}&lt;/a&gt;
    {% endifequal %}
  {% else %}
    ...
  {% endif %}
{% endfor %}
{% if page_obj.has_next %}
  &lt;a href=&quot;?page={{ page_obj.next_page_number }}&quot;&gt;Next&lt;/a&gt;
{% endif %}</pre></td></tr></table></div>

<p>Para usarlo se coloca el siguiente codigo en cualquiera de las plantillas que queramos paginar:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">    {% if is_paginated %}
      {% load render_paginator %}
      {% render_paginator 2 3 %}
    {% endif %}</pre></td></tr></table></div>

<p>Lo que genera un código como:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">Previous  1  2  ... 5  6  7  8  9  10  11  ... 25  26  Next</pre></td></tr></table></div>

<p>Lo mejor de todo es que no necesita ningún componente adicional ni interfiere con la paginación por defecto que traen las vistas genéricas en django.</p>
]]></content:encoded>
			<wfw:commentRss>http://axiacore.com/blog/2010/01/paginacion-en-django-estilo-digg/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Trabajando con Symfony en forma interactiva</title>
		<link>http://axiacore.com/blog/2009/11/trabajando-con-symfony-en-forma-interactiva/</link>
		<comments>http://axiacore.com/blog/2009/11/trabajando-con-symfony-en-forma-interactiva/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 06:23:33 +0000</pubDate>
		<dc:creator>Juan Pablo Romero Bernal</dc:creator>
				<category><![CDATA[AxiaCore]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://axiacore.com/blog/?p=781</guid>
		<description><![CDATA[Para algunos desarrolladores nos es muy cómodo trabajar desde la línea de comandos, ya que diez dedos hacen más que dos. De hecho cuando se desarrollan aplicaciones con Symfony, el uso de la terminal de comandos es fundamental para muchas tareas (generación del modelo, creación de esquemas de base de datos, limpiar la cache, etc,.) [...]]]></description>
			<content:encoded><![CDATA[<p>Para algunos desarrolladores nos es muy cómodo trabajar desde la línea de comandos, ya que diez dedos hacen más que dos. De hecho cuando se desarrollan aplicaciones con Symfony, el uso de la terminal de comandos es fundamental para muchas tareas (generación del modelo, creación de esquemas de base de datos, limpiar la cache, etc,.) que simplifican el trabajo significativamente.</p>
<p>Desde luego, todo esto es gracias a la interfaz en línea de comandos del ínterprete php (más conocido como php-cli), que en algunos casos se queda corto para ejecutar algunas pruebas: ver el estado de un objeto, insertar datos en la base de datos,  probar métodos de manera interactiva, etc,. Sé que algunos dirán que php-cli tiene un modo interactivo, pero en realidad desde mi punto de vista es muy limitado.  Sería muy interesante contar con algo similar a la terminal interactiva de python y desde luego que se pueda trabajar con nuestros proyectos en Symfony.</p>
<p>Lo mejor de todo, es que la gente de facebook liberó bajo licencia BSD una shell interactiva para php y como sus mismos credadores dicen: &#8220;&#8230; irónicamente escrita en python &#8230;.&#8221;; se llama <a href="http://www.phpsh.org/">phpsh</a> y realmente es un gran trabajo. He realizado algunas pruebas de integración con Symfony y creo que puede ser de gran apoyo para pruebas y aún más para las personas que están aprendiendo a trabajar con el framework.</p>
<p>A continuación van algunos de los sencillos experimentos realizados:</p>
<p>Una vez se haya instalado phpsh (leer el README), podemos trabajar  con sentencias de php y usar las funciones:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">test$ phpsh
Starting php
type <span style="color: #0000ff;">'h'</span> or <span style="color: #0000ff;">'help'</span> to see instructions <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> features
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Hola mundo&quot;</span>
Hola mundo
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span>
<span style="color: #cc66cc;">5</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'uno'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'dos'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tres'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$n</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$n</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #cc66cc;">123</span>
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$n</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$n</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #cc66cc;">1</span>
<span style="color: #cc66cc;">2</span>
<span style="color: #cc66cc;">3</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$n</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #339933;">...</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$n</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">...</span> <span style="color: #009900;">&#125;</span>
<span style="color: #cc66cc;">1</span>
<span style="color: #cc66cc;">2</span>
<span style="color: #cc66cc;">3</span>
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #cc66cc;">3</span></pre></div></div>

<p>Bien, pero ahora viene algo un poco más interesante: usar a través del shell interactivo nuestra aplicación hecha en Symfony.</p>
<p>No requiere ninguna configuración especial, simplemente cargar un archivo y listo; se trata del controlador frontal de nuestra aplicación (alguno de los que se encuentra en web), así:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">test$ phpsh web<span style="color: #339933;">/</span>index<span style="color: #339933;">.</span>php
Starting php with extra includes<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'web/index.php'</span><span style="color: #009900;">&#93;</span>
&nbsp;
  <span style="color: #339933;">.......................</span>
&nbsp;
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Para obviar la salida html, podemos crear una copia de ese archivo y evitar la llamada al método dispatch(), así:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/config/ProjectConfiguration.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$configuration</span> <span style="color: #339933;">=</span> ProjectConfiguration<span style="color: #339933;">::</span><span style="color: #004000;">getApplicationConfiguration</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'frontend'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'prod'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
sfContext<span style="color: #339933;">::</span><span style="color: #004000;">createInstance</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$configuration</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ahora, de nuevo lo cargamos (ese archivo lo he llamado shell.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">test$ phpsh shell<span style="color: #339933;">.</span>php
Starting php with extra includes<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'shell.php'</span><span style="color: #009900;">&#93;</span>
type <span style="color: #0000ff;">'h'</span> or <span style="color: #0000ff;">'help'</span> to see instructions <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> features
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> CiudadPeer<span style="color: #339933;">::</span><span style="color: #004000;">doSelect</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Criteria<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ciudad</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #339933;">...</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ciudad</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #339933;">...</span> <span style="color: #009900;">&#125;</span>
Barranquilla
Bogota
Constantinopla
Medellin
&nbsp;
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Como se puede ver, puedo acceder a las clases de mi modelo (disculpas a los usuarios de Doctrine) y desde luego a las clases que nos proporciona Symfony, por ejemplo si mi archivo <strong>apps/frontend/config/app.yml</strong> es:</p>

<div class="wp_syntax"><div class="code"><pre class="yml" style="font-family:monospace;">all:
 resultados_por_pagina: 15
 sf_phpmailer:
   mailer:                    true
   smtp_auth:                 true
   smtp_secure:               &quot;ssl&quot;
   host:                      &quot;smtp.mihost&quot;
   port:                      600
   username:                  &quot;miusuario&quot;
   password:                  &quot;miclave&quot;
   from:                      &quot;nosesabe@example.com&quot;
   from_name:                 &quot;Anonimo&quot;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">test$ phpsh shell<span style="color: #339933;">.</span>php
Starting php with extra includes<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'shell.php'</span><span style="color: #009900;">&#93;</span>
type <span style="color: #0000ff;">'h'</span> or <span style="color: #0000ff;">'help'</span> to see instructions <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> features
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$conf</span> <span style="color: #339933;">=</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'app_sf_phpmailer_port'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$conf</span><span style="color: #339933;">;</span>
<span style="color: #cc66cc;">600</span>
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> sfConfig<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'app_resultados_por_pagina'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #cc66cc;">15</span>
php<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Bueno, esos han sido los experimentos que he alcanzado a realizar. Espero trabajar más en detalle y publicar los resultados. Hasta una próxima.</p>
]]></content:encoded>
			<wfw:commentRss>http://axiacore.com/blog/2009/11/trabajando-con-symfony-en-forma-interactiva/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mostrar numero de version en django</title>
		<link>http://axiacore.com/blog/2009/11/mostrar-numero-de-version-en-django/</link>
		<comments>http://axiacore.com/blog/2009/11/mostrar-numero-de-version-en-django/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 13:31:17 +0000</pubDate>
		<dc:creator>Camilo Nova</dc:creator>
				<category><![CDATA[AxiaCore]]></category>
		<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://axiacore.com/blog/?p=776</guid>
		<description><![CDATA[En AxiaCore utilizamos subversion para llevar el control de versiones de los proyectos, junto a nuestro esquema de desarrollo ágil manejamos ciclos cortos de lanzamiento de nuevas funcionalidades, por eso para nosotros es necesario conocer el numero de revisión del SVN y publicarlo en un lugar fácilmente accesible para los usuarios, de tal forma que [...]]]></description>
			<content:encoded><![CDATA[<p>En AxiaCore utilizamos subversion para llevar el control de versiones de los proyectos, junto a nuestro esquema de desarrollo ágil manejamos ciclos cortos de lanzamiento de nuevas funcionalidades, por eso para nosotros es necesario conocer el numero de revisión del SVN y publicarlo en un lugar fácilmente accesible para los usuarios, de tal forma que rápidamente nos puedan indicar la versión que están utilizando.</p>
<p>La aproximación inicial es tener un parámetro donde se indique un numero de versión de la aplicación, pero esta fue rápidamente descartada porque no es flexible y se tendría que cambiar la versión manualmente en cada nuevo cambio, así que decidimos manejar el numero de revisión del repositorio como el indicador de la versión. Ahora bien, se necesita una manera automática de obtener dicho numero y publicarlo en una plantilla HTML para verlo en la interfaz de usuario.</p>
<p>Lo resolvimos así:</p>
<p>Partimos de la plantilla donde básicamente django nos permite lo siguiente:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">{% load version_tag %}
&lt;p&gt;Version: {% get_version %}&lt;/p&gt;</pre></td></tr></table></div>

<p>Entonces cargamos un &#8216;custom tag&#8217; que nos retorna la versión actual de la aplicación, el cual es:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># -*- coding: utf8 -*-</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">subprocess</span>
<span style="color: #ff7700;font-weight:bold;">from</span> django <span style="color: #ff7700;font-weight:bold;">import</span> template
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">core</span>.<span style="color: black;">cache</span> <span style="color: #ff7700;font-weight:bold;">import</span> cache
&nbsp;
register = template.<span style="color: black;">Library</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
@register.<span style="color: black;">simple_tag</span>
<span style="color: #ff7700;font-weight:bold;">def</span> get_version<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    Retorna el numero de version para la aplicacion y lo almacena en
    cache para evitar ser llamado multiples veces y mejorar el rendimiento
    de la aplicacion.
    &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> cache.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'version'</span><span style="color: black;">&#41;</span>:
        comando = <span style="color: #483d8b;">'svn info | grep Rev | head -1'</span>
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            proc = <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span>comando, shell=<span style="color: #008000;">True</span>, 
                stdout=<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">PIPE</span>, stderr=<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">PIPE</span>
            <span style="color: black;">&#41;</span>
            line = proc.<span style="color: black;">communicate</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
            version = line<span style="color: black;">&#91;</span>line.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#41;</span>+<span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span>.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span>:
            version = <span style="color: #483d8b;">'---'</span>
&nbsp;
        tiempo = <span style="color: #ff4500;">24</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">60</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">60</span>   <span style="color: #808080; font-style: italic;">#Tiempo en segundos de un dia</span>
        cache.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'version'</span>, version, tiempo<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> cache.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'version'</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Este archivo (version_tag.py) debe estar dentro de una carpeta llamada &#8216;templatetags&#8217; de alguna aplicación del proyecto.</p>
<p>Lo interesante de esta solución es:</p>
<ol>
<li>Obtiene el numero de versión por el comando &#8217;svn info&#8217;</li>
<li>Reduce las llamadas al comando ubicando la información en cache durante un día</li>
<li>Es totalmente desacoplado del proyecto y se puede reutilizar fácilmente</li>
<li>Se puede adaptar para otros sistemas de control de versiones</li>
</ol>
<p>Que les parece?</p>
]]></content:encoded>
			<wfw:commentRss>http://axiacore.com/blog/2009/11/mostrar-numero-de-version-en-django/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cambiar el QuerySet de un ForeingKey de un modelo en Django</title>
		<link>http://axiacore.com/blog/2009/01/cambiar-el-queryset-de-un-foreingkey-de-un-modelo-en-django/</link>
		<comments>http://axiacore.com/blog/2009/01/cambiar-el-queryset-de-un-foreingkey-de-un-modelo-en-django/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 17:07:05 +0000</pubDate>
		<dc:creator>Camilo Nova</dc:creator>
				<category><![CDATA[AxiaCore]]></category>
		<category><![CDATA[Codigo Fuente]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://axiacore.com/blog/?p=628</guid>
		<description><![CDATA[Es posible declarar tipos ForeignKey en un modelo de datos de Django, pero puede que necesitemos filtrar los valores de esta relación, para efectuar tal cambio necesitamos recurrir al Form que muestra ese modelo y modificar el método __init__ de la siguiente manera:

1
2
3
4
class MyModelForm&#40;forms.Form&#41;:
    def __init__&#40;self, *args, **kwargs&#41;:
     [...]]]></description>
			<content:encoded><![CDATA[<p>Es posible declarar tipos ForeignKey en un modelo de datos de Django, pero puede que necesitemos filtrar los valores de esta relación, para efectuar tal cambio necesitamos recurrir al Form que muestra ese modelo y modificar el método __init__ de la siguiente manera:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> MyModelForm<span style="color: black;">&#40;</span>forms.<span style="color: black;">Form</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>MyModelForm, <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">fields</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;myFKField&quot;</span><span style="color: black;">&#93;</span>.<span style="color: black;">queryset</span> = MyModel.<span style="color: black;">objects</span>.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Esto permite cambiar los datos que son mostrados por el campo en el Form por unos filtrados que nosotros queramos, existe tambien la posibilidad de trabajar con limit_choices_to de ForeignKey pero esta solución me funciono de inmediato.</p>
]]></content:encoded>
			<wfw:commentRss>http://axiacore.com/blog/2009/01/cambiar-el-queryset-de-un-foreingkey-de-un-modelo-en-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adicionar o Sustraer Dias en Python</title>
		<link>http://axiacore.com/blog/2009/01/adicionar-o-sustraer-dias-en-python/</link>
		<comments>http://axiacore.com/blog/2009/01/adicionar-o-sustraer-dias-en-python/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 20:22:02 +0000</pubDate>
		<dc:creator>Camilo Nova</dc:creator>
				<category><![CDATA[AxiaCore]]></category>
		<category><![CDATA[Codigo Fuente]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://axiacore.com/blog/?p=624</guid>
		<description><![CDATA[Para agregar o sustraer días a una fecha determinada en python lo mejor es hacerlo así:

1
2
3
4
5
from datetime import date, timedelta
#Agregar
d=date.today&#40;&#41;+timedelta&#40;days=dias&#41;
#Sustraer
d=date.today&#40;&#41;-timedelta&#40;days=dias&#41;

La operación respeta los días al cambiar de mes y funciona perfecto.
]]></description>
			<content:encoded><![CDATA[<p>Para agregar o sustraer días a una fecha determinada en python lo mejor es hacerlo así:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">datetime</span> <span style="color: #ff7700;font-weight:bold;">import</span> date, timedelta
<span style="color: #808080; font-style: italic;">#Agregar</span>
d=date.<span style="color: black;">today</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>+timedelta<span style="color: black;">&#40;</span>days=dias<span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;">#Sustraer</span>
d=date.<span style="color: black;">today</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>-timedelta<span style="color: black;">&#40;</span>days=dias<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>La operación respeta los días al cambiar de mes y funciona perfecto.</p>
]]></content:encoded>
			<wfw:commentRss>http://axiacore.com/blog/2009/01/adicionar-o-sustraer-dias-en-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
