<?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; Desarrollo</title>
	<atom:link href="http://axiacore.com/blog/tag/desarrollo/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>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>Trabajando con filtros en Symfony (II)</title>
		<link>http://axiacore.com/blog/2009/09/trabajando-con-filtros-en-symfony-ii/</link>
		<comments>http://axiacore.com/blog/2009/09/trabajando-con-filtros-en-symfony-ii/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 23:36:22 +0000</pubDate>
		<dc:creator>Juan Pablo Romero Bernal</dc:creator>
				<category><![CDATA[AxiaCore]]></category>
		<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://axiacore.com/blog/?p=755</guid>
		<description><![CDATA[Esta es una segunda entrega acerca del trabajo con los formularios de filtro en Symfony. He tenido en cuenta los comentarios y sugerencias de  los visitantes del blog,  así que esta entrega integrará el uso de Doctrine.
Antes de comenzar,  aclaro que mucha de la información aquí consignada está basada en el código generado por el [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Esta es una segunda entrega acerca del trabajo con los formularios de filtro en Symfony. He tenido en cuenta los comentarios y sugerencias de  los visitantes del blog,  así que esta entrega integrará el uso de Doctrine.</p>
<p style="text-align: justify;">Antes de comenzar,  aclaro que mucha de la información aquí consignada está basada en el código generado por el generador de administración tanto de Propel como de Doctrine y desde luego en la documentación del API de Symfony 1.2.</p>
<h3 style="text-align: justify;"><strong>Filtros con Doctrine</strong></h3>
<p style="text-align: justify;">En la entrada anterior hablé del uso de los formularios con Propel de manera básica y aunque las forma de trabajar los formularios de filtros con Doctrine no es muy diferente, haré algunas aclaraciones importantes.</p>
<p style="text-align: justify;">Al momento de generar el modelo con Doctrine, con la tarea:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">php symfony doctrine<span style="color: #339933;">:</span>build<span style="color: #339933;">-</span>all</pre></td></tr></table></div>

<p style="text-align: justify;">al igual con con Propel, se genera en el directorio  <strong>lib/filter/doctrine/</strong> el conjunto de clases de formularios de filtro. Tomando como referencia el esquema de datos del tutorial de Jobeet (Día 3 &#8211; <a href="http://www.symfony-project.org/jobeet/1_2/Doctrine/en/03">http://www.symfony-project.org/jobeet/1_2/Doctrine/en/03</a>) los filtros generados son:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">BaseFormFilterDoctrine<span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">.</span>php
JobeetAffiliateFormFilter<span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">.</span>php
JobeetCategoryAffiliateFormFilter<span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">.</span>php
JobeetCategoryFormFilter<span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">.</span>php
JobeetJobFormFilter<span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">.</span>php
base<span style="color: #339933;">/</span></pre></td></tr></table></div>

<p style="text-align: justify;">Estas clases podemos modificarlas según nuestras necesidades, al igual que con los formularios. Ahora, vamos a generar el módulo que permita el CRUD de las ofertas de trabajo (Tabla Jobeet_Job):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">php symfony doctrine<span style="color: #339933;">:</span>generate<span style="color: #339933;">-</span>module frontend job JobeetJob</pre></td></tr></table></div>

<p>Bien, ahora con el módulo generado, vamos a revisar  las acciones y hacer los ajustes para el uso de los filtros. En primera forma, debemos modificar la acción index, para que nos presente el formulario de filtros:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> jobActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #666666; font-style: italic;">// apps/frontend/modules/job/actions/actions.class.php</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeIndex<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">jobeet_job_list</span> <span style="color: #339933;">=</span> Doctrine<span style="color: #339933;">::</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'JobeetJob'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filtro</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JobeetJobFormFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// más código .....</span></pre></td></tr></table></div>

<p>Al igual que con Propel, debemos crear una instancia del filtro, para que sea visualizada en la 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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">// apps/frontend/modules/job/templates/indexSuccess.php
&nbsp;
&lt;h1&gt;Lista de trabajos&lt;/h1&gt;
&lt;h1&gt;Lista de trabajos&lt;/h1&gt;
&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> url_for<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'job/filter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;post&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$filtro</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
 &lt;p&gt;
  &lt;input class=&quot;ui-state-default ui-corner-all&quot; type=&quot;submit&quot; value=&quot;Filtrar&quot; /&gt;
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> link_to<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Quitar filtro'</span><span style="color: #339933;">,</span> url_for<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'job/filter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
     <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'query_string'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'_reset'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
 &lt;/p&gt;
&lt;/form&gt;
&lt;! -- más código html ... --&gt;</pre></td></tr></table></div>

<p>Creamos nuestra acción encargada de filtrar los resultados (filter):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// apps/frontend/modules/job/actions/actions.class.php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeFilter<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filtro</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JobeetJobFormFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">consulta</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filtro</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">buildQuery</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jobeet_job_filters'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">jobeet_job_list</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">consulta</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: justify;">Una de las diferencias importantes con Propel, es el método que se encarga de construir la consulta según el valor de los filtros,  que es buildQuery y que recibe una arreglo de valores a partir de los cuales se construirá la consulta. Este método devuelve un objeto de tipo Doctrine_Query, por eso llamamos al método execute en forma posterior.</p>
<p style="text-align: justify;">Con lo anterior tenemos un sistema de filtros muy básico usando Doctrine como ORM.</p>
<h3 style="text-align: justify;">Adaptando el filtro</h3>
<p style="text-align: justify;">Hasta el momento, ya hemos visto como establecer un filtro, tanto si usamos Propel como Doctrine. Sin embargo, la mayoría de las veces los campos por los cuales deseamos filtrar información no corresponden con todos los de la tabla. El filtro por defecto que se genera contempla todos los campos y por ello es necesario que hagamos algunas modificaciones, para filtrar por los campos deseados.</p>
<p style="text-align: justify;">Siguiendo con el ejemplo del tutorial de Jobeet, supongamos que sólo queremos filtrar la lista de trabajos, por categoría  y tipo (campos category y type, respectivamente), para ello debemos modificar el método configure de la clase JobeetJobFormFilter:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// lib/form/doctrine/JobeetJobFormFilter.class.php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> JobeetJobFormFilter <span style="color: #000000; font-weight: bold;">extends</span> BaseJobeetJobFormFilter
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWidgets</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'category_id'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormDoctrineChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'JobeetCategory'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_empty'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'type'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormFilterInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setValidators</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'category_id'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorDoctrineChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'JobeetCategory'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'column'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'type'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorPass<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setNameFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jobeet_job_filters[%s]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: justify;">Cómo se puede observar, un formulario de filtro es muy similar a un formulario, con algunas diferencias en cuanto a los widgets que se usan y algunos de los métodos.  Con esta modificación, cuando imprimamos el filtro en la plantilla, ahora sólo los campos de categoría y tipo estarán disponibles.  También podemos usar los métodos setLabel y setLabels para cambiar el nombre de las etiquetas que aparecerán al momento de imprimir el formulario de filtros, por ejemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getWidgetSchema</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabels</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
   <span style="color: #0000ff;">'category_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Categoria'</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Tipo'</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p style="text-align: justify;">Uno de los widgets de filtros que considero más útiles es sfWidgetFormFilterDate, ya que con él es posible filtrar información por rangos de fecha, aquí un ejemplo de su uso para el campo de expiración de la oferta de trabajo (campo expires_at):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'expires_at'</span>   <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormFilterDate<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                 <span style="color: #0000ff;">'from_date'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormDate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                 <span style="color: #0000ff;">'to_date'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormDate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                 <span style="color: #0000ff;">'with_empty'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>                   <span style="color: #666666; font-style: italic;">// Para que no salga el checkbox</span>
                 <span style="color: #0000ff;">'template'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'desde %from_date% hasta %to_date%'</span>
                <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Bien, hasta aquí esta segunda entrega del trabajo con filtros en Symfony 1.2. Espero que sea  de utilidad.</p>
]]></content:encoded>
			<wfw:commentRss>http://axiacore.com/blog/2009/09/trabajando-con-filtros-en-symfony-ii/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Trabajando con filtros en Symfony (I)</title>
		<link>http://axiacore.com/blog/2009/09/trabajando-con-filtros-en-symfony-i/</link>
		<comments>http://axiacore.com/blog/2009/09/trabajando-con-filtros-en-symfony-i/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 03:12:32 +0000</pubDate>
		<dc:creator>Juan Pablo Romero Bernal</dc:creator>
				<category><![CDATA[AxiaCore]]></category>
		<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://axiacore.com/blog/?p=744</guid>
		<description><![CDATA[Esta es una entrada bastante rápida, pero que busca mostrar la forma básica en que se pueden usar los formularios de filtros en Symfony (versión 1.2) para facilitar a los usuarios la clasificación y consulta de información.  El manejo de formularios de filtros es muy similar a los formularios que se usan para el ingreso [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Esta es una entrada bastante rápida, pero que busca mostrar la forma básica en que se pueden usar los formularios de filtros en Symfony (versión 1.2) para facilitar a los usuarios la clasificación y consulta de información.  El manejo de formularios de filtros es muy similar a los formularios que se usan para el ingreso y/o edición de información,  con algunas variaciones. Hago claridad que las pruebas que he realizado han sido usando Propel como ORM.</p>
<p style="text-align: justify;">Bien, empecemos por saber que en Symfony existe una tarea que nos permite construir en forma automática los formularios de filtros, de la siguiente forma:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">$ php symfony propel<span style="color: #339933;">:</span>build<span style="color: #339933;">-</span>filters</pre></td></tr></table></div>

<p>Después de la ejecución de esta tarea, en el directorio <strong>lib/filters</strong> de nuestro proyecto, se habrán creado (de acuerdo a nuestro modelo) un conjunto de clases cuyo nombre sigue la siguiente nomenclatura:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">ClaseFormFilter<span style="color: #339933;">.</span><span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">.</span>php</pre></td></tr></table></div>

<p style="text-align: justify;">y al igual que con el modelo y los formularios, tendremos unas clases Base y unas clases que extenderán de esas clases base, las cuales podemos adaptar según nuestras necesidades. Una vez creadas nuestras clases de formularios de filtros, ya podemos usarlas dentro de nuestras acciones. Tomaré como ejemplo, que tenemos un modulo llamado clientes que permite trabajar con el CRUD normal y que cada cliente tiene un nombre, telefono y una ciudad, de modo que nuestra clase base de formulario de filtro lucirá así:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> BaseClienteFormFilter <span style="color: #000000; font-weight: bold;">extends</span> BaseFormFilterPropel
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
&nbsp;
  <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWidgets</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'nombre'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormFilterInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'telefono'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormFilterInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'ciudad_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormPropelChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Ciudad'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_empty'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setValidators</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'nombre'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorPass<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'telefono'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorPass<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'ciudad_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorPropelChoice<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
                                 <span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Ciudad'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'column'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
   <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setNameFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cliente_filters[%s]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errorSchema</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorErrorSchema<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validatorSchema</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   parent<span style="color: #339933;">::</span><span style="color: #004000;">setup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getModelName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'Cliente'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getFields<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
     <span style="color: #0000ff;">'id'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Number'</span><span style="color: #339933;">,</span>
     <span style="color: #0000ff;">'nombre'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Text'</span><span style="color: #339933;">,</span>
     <span style="color: #0000ff;">'telefono'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Text'</span><span style="color: #339933;">,</span>
     <span style="color: #0000ff;">'ciudad_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ForeignKey'</span><span style="color: #339933;">,</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: justify;">Tengamos en cuenta que esta clase es generada automáticamente y podemos hacer las modificaciones necesarias en la clase ClienteFormFilter, como se hace con los formularios.  Ahora bien, vamos a utilizar este formulario de filtro en nuestra acción index de nuestro módulo de clientes, de la siguiente forma:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> clientesActions <span style="color: #000000; font-weight: bold;">extends</span> sfActions
<span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeIndex<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// creamos el filtro ....</span>
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filtro</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClienteFormFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #666666; font-style: italic;">// .....</span>
     <span style="color: #666666; font-style: italic;">// más código ....</span>
     <span style="color: #666666; font-style: italic;">// Típica consulta  ....</span>
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clientes</span> <span style="color: #339933;">=</span> CientePeer<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;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>En nuestra plantilla: (indexSuccess.php)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> url_for<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'clientes/filtrar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;post&quot;&gt;
&lt;table&gt;
 &lt;tbody&gt;
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$filtro</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;input type=&quot;submit&quot; value=&quot;Filtrar&quot; name=&quot;filtrar&quot;/&gt;
&lt;/form&gt;
// otro codigo html ....</pre></td></tr></table></div>

<p style="text-align: justify;">Bien, hasta aquí nada nuevo, simplemente un formulario más, que aparecerá en nuestra acción index de nuestro módulo de clientes, pero con la diferencia que será procesado por la acción filtrar (o como decida llamarse). En este punto es importante mencionar, que para la ejecución del filtrado, se empleará el método buildCriteria, el cuál recibe como parámetro un arreglo (los campos por  los  cuales se desea hacer el filtro) y se encarga de construir las consultas:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeFiltrar<span style="color: #009900;">&#40;</span>sfWebRequest <span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filtro</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ClienteFormFilter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// Construye un objeto criteria con el valor de los filtros</span>
  <span style="color: #000088;">$criteria</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filtro</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">buildCriteria</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cliente_filters'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">clientes</span> <span style="color: #339933;">=</span> ClientePeer<span style="color: #339933;">::</span><span style="color: #004000;">doSelect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$criteria</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTemplate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p style="text-align: justify;">El método buildCriteria es el encargado de construir la consulta según el valor de los filtros (revise la clase sfFormFilterPropel y los métodos addXXXCriteria() de la misma clase). Posteriormente pasamos ese objeto criteria a el método doSelect para devolver la consulta filtrada usando la plantilla de la acción index.  Sencillo, no ??</p>
<p style="text-align: justify;">En una próxima entrada se explicará lo referente al manejo de formularios de filtro y el mantenimiento de los resultados obtenidos por el filtro entre páginas.</p>
]]></content:encoded>
			<wfw:commentRss>http://axiacore.com/blog/2009/09/trabajando-con-filtros-en-symfony-i/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Agregacion en Django</title>
		<link>http://axiacore.com/blog/2009/03/agregacion-en-django/</link>
		<comments>http://axiacore.com/blog/2009/03/agregacion-en-django/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 16:16:14 +0000</pubDate>
		<dc:creator>Camilo Nova</dc:creator>
				<category><![CDATA[AxiaCore]]></category>
		<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[Django]]></category>

		<guid isPermaLink="false">http://axiacore.com/blog/?p=694</guid>
		<description><![CDATA[Trabajando con modelos en Django para aplicaciones web de alto perfil, como las desarrolladas por AxiaCore, nos encontrábamos frecuentemente con tener que hacer cálculos aritméticos básicos manualmente sobre un conjunto de datos en particular.
Por ejemplo si necesitábamos obtener el total de ventas de un mes determinado, se tenia que iterar cada elemento del conjunto de [...]]]></description>
			<content:encoded><![CDATA[<p>Trabajando con modelos en Django para aplicaciones web de alto perfil, como las desarrolladas por AxiaCore, nos encontrábamos frecuentemente con tener que hacer cálculos aritméticos básicos manualmente sobre un conjunto de datos en particular.</p>
<p>Por ejemplo si necesitábamos obtener el total de ventas de un mes determinado, se tenia que iterar cada elemento del conjunto de datos (QuerySet) e ir sumando en una variable cada valor obtenido, los que hemos trabajado con aplicaciones conectadas a una base de datos sabemos que existen funciones de SQL con SUM() que efectúan esa tarea mucho mas cómodamente.</p>
<p>Afortunadamente para la nueva versión de Django, próxima a salir, la v1.1 existe la posibilidad de utilizar &#8216;Agregaciones&#8217; y &#8216;Anotaciones&#8217; que permiten efectuar este tipo de cálculos de una manera mucho mas fácil y recargando la responsabilidad de los cálculos a la base de datos y no a la lógica de la aplicación.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">Factura.<span style="color: black;">objects</span>.<span style="color: black;">aggregate</span><span style="color: black;">&#40;</span>
    Avg<span style="color: black;">&#40;</span><span style="color: #483d8b;">'precio'</span><span style="color: black;">&#41;</span>, Max<span style="color: black;">&#40;</span><span style="color: #483d8b;">'precio'</span><span style="color: black;">&#41;</span>, Min<span style="color: black;">&#40;</span><span style="color: #483d8b;">'precio'</span><span style="color: black;">&#41;</span>, Sum<span style="color: black;">&#40;</span><span style="color: #483d8b;">'precio'</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#41;</span></pre></div></div>

<p>Mas información en la documentación oficial del proyecto.</p>
<p>Enlace: <a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/">http://docs.djangoproject.com/en/dev/topics/db/aggregation/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://axiacore.com/blog/2009/03/agregacion-en-django/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Administrador web Trac</title>
		<link>http://axiacore.com/blog/2008/12/administrador-web-trac/</link>
		<comments>http://axiacore.com/blog/2008/12/administrador-web-trac/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 21:54:37 +0000</pubDate>
		<dc:creator>Camilo Nova</dc:creator>
				<category><![CDATA[AxiaCore]]></category>
		<category><![CDATA[Desarrollo]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://axiacore.com/blog/?p=597</guid>
		<description><![CDATA[Para activar el administrador vía web de Trac, disponible desde la versión 0.11 se ha de usar el siguiente comando:
$ trac-admin /path/to/projenv permission add bob TRAC_ADMIN
Donde &#8216;/path/to/projenv&#8217; es la ruta en donde esta Trac y &#8216;bob&#8217; es el usuario al cual agregar el permiso.
]]></description>
			<content:encoded><![CDATA[<p>Para activar el administrador vía web de Trac, disponible desde la versión 0.11 se ha de usar el siguiente comando:</p>
<blockquote><p>$ trac-admin /path/to/projenv permission add bob TRAC_ADMIN</p></blockquote>
<p>Donde &#8216;/path/to/projenv&#8217; es la ruta en donde esta Trac y &#8216;bob&#8217; es el usuario al cual agregar el permiso.</p>
]]></content:encoded>
			<wfw:commentRss>http://axiacore.com/blog/2008/12/administrador-web-trac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
