<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>History.txt</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -2,7 +2,7 @@ module Zena #:nodoc:
   module VERSION #:nodoc:
     MAJOR = 0
     MINOR = 11
-    TINY  = 0
+    TINY  = 1
     REV   = File.exist?(File.join(RAILS_ROOT, 'REVISION')) ? File.read(File.join(RAILS_ROOT, 'REVISION'))[0..5].to_i.to_s : '1280+'
     STRING = [MAJOR, MINOR, TINY].join('.')
   end</diff>
      <filename>config/version.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,103 +1,119 @@
 NodeQuery:
-  # form_dates
+  # find all courses that an employee must follow
   emp_form_date:
+    # find courses assigned_to pages in job assigned_to CURRENT_NODE (employee)
+    main_table: courses
     select:
-      - no1.id
-      - no1.name
-      - no1.publish_from
-      - no1.zip
-      - no1.vclass_id
-      - no1.type
-      - no1.rgroup_id
-      - no1.pgroup_id
-      - no1.ref_lang
-      - MAX(form.event_at) + INTERVAL no1.custom_a MONTH AS log_at
-      - form.event_at AS last_date
-      - form.event_at + INTERVAL no1.custom_a MONTH AS next_date
-      - MAX(form.event_at) AS event_at
-    tables:
-      - nodes
-      - links
-      - nodes AS no1
+      - courses.*
+      - courses.custom_a AS repeat_every
+      - form.last_date AS last_date
+      - form.last_date + INTERVAL courses.custom_a MONTH AS next_date
+      - MAX(IF(assigned_pages.custom_a,assigned_pages.custom_a,5)) AS priority
+    tables:  
+      - nodes AS courses
+      # assigned to
       - links AS li1
+      # pages
+      - nodes AS assigned_pages
+      # in assigned_jobs
+      - links
     join_tables:
-      no1:
-        - LEFT JOIN nodes AS form INNER JOIN links AS flink ON flink.relation_id = RELATION_ID(assigned_formation) AND flink.target_id = NODE_ID AND flink.source_id = form.id AND flink.status = 100 ON form.project_id = no1.id
+      # courses
+      courses:
+        # all formations are created inside the course = project. This is why
+        # form.project_id == course_id.
+        - LEFT JOIN (SELECT nodes.project_id AS course_id, flink.target_id AS emp_id, MAX(nodes.event_at) AS last_date FROM nodes INNER JOIN links AS flink ON nodes.id = flink.source_id AND flink.relation_id = RELATION_ID(assigned_formation) AND (flink.status IS NULL OR flink.status = 100) GROUP BY flink.target_id, nodes.project_id) AS form ON courses.id = form.course_id AND form.emp_id = NODE_ID
     where:
-      - no1.id = li1.source_id AND li1.relation_id = RELATION_ID(assigned_course) AND li1.target_id = nodes.id
-      - nodes.kpath LIKE 'NP%'
-      - nodes.project_id = links.target_id
-      - links.relation_id = RELATION_ID(assigned_job) AND links.source_id = NODE_ID
-    group: no1.id
-    order: event_at ASC, no1.name ASC
+      # get all assigned jobs (links)
+      - links.source_id = NODE_ID
+      - links.relation_id = RELATION_ID(assigned_job)
+      # get all pages in jobs
+      - assigned_pages.project_id = links.target_id
+      # get all courses assigned to these pages
+      - li1.target_id = assigned_pages.id
+      - li1.relation_id = RELATION_ID(assigned_course)
+      - courses.id = li1.source_id
+    group: courses.id
+    order: priority DESC, last_date ASC, courses.name ASC
   
   course_emp_date:
+    main_table: employees
     select:
-      - no1.id
-      - no1.name
-      - no1.publish_from
-      - no1.zip
-      - no1.vclass_id
-      - no1.type
-      - no1.rgroup_id
-      - no1.pgroup_id
-      - no1.ref_lang
+      - employees.id
+      - employees.name
+      - employees.publish_from
+      - employees.zip
+      - employees.vclass_id
+      - employees.type
+      - employees.rgroup_id
+      - employees.pgroup_id
+      - employees.ref_lang
+      - employees.user_id
+      - employees.max_status
       # TODO: next_date = NULL if custom_a is null
-      - form.event_at + INTERVAL NODE_ATTR(custom_a) MONTH AS next_date
-      - form.event_at AS last_date
-      - MAX(form.event_at) + INTERVAL NODE_ATTR(custom_a) MONTH AS log_at
-      - MAX(form.event_at) AS event_at
-      - NODE_ATTR(custom_a) AS custom_a
+      - form.last_date AS last_date
+      - form.last_date + INTERVAL NODE_ATTR(custom_a) MONTH AS next_date
+      - NODE_ATTR(custom_a) AS repeat_every
+      - MAX(IF(assigned_pages.custom_a,assigned_pages.custom_a,5)) AS priority
     tables:
       # NODE_ID = course
-      # nodes   = pages assigned to course
-      - nodes
-      # no1     = employees with job containing the pages assigned to course
-      - nodes AS no1
+      - nodes AS employees
+      - nodes AS assigned_pages
       - links
       - links AS li1
     join_tables:
-      no1:
-        - LEFT JOIN nodes AS form INNER JOIN links AS flink ON form.id = flink.source_id AND flink.relation_id = RELATION_ID(assigned_formation) AND flink.status = 100 ON flink.target_id = no1.id AND form.project_id = NODE_ID
+      employees:
+        - LEFT JOIN (SELECT nodes.project_id AS project_id, flink.target_id AS emp_id, MAX(nodes.event_at) AS last_date FROM nodes INNER JOIN links AS flink ON nodes.id = flink.source_id AND flink.relation_id = RELATION_ID(assigned_formation) AND (flink.status IS NULL OR flink.status = 100) GROUP BY flink.target_id, nodes.project_id) AS form ON form.emp_id = employees.id AND form.project_id = NODE_ID
     where:
-      - no1.id = li1.source_id AND li1.relation_id = RELATION_ID(assigned_employee) AND li1.target_id = nodes.project_id
-      - nodes.id = links.target_id AND links.relation_id = RELATION_ID(assigned_page) AND links.source_id = NODE_ID
-    group: no1.id
-    order: no1.name ASC, form.event_at ASC
+      - employees.id = li1.source_id AND li1.relation_id = RELATION_ID(assigned_employee) AND li1.target_id = assigned_pages.project_id
+      - assigned_pages.id = links.target_id AND links.relation_id = RELATION_ID(assigned_page) AND links.source_id = NODE_ID
+    group: employees.id
+    order: employees.name ASC, IF(form.last_date,form.last_date,0) ASC
   
   
   all_course_emp_date:
     # assigned_employees from project from assigned_pages from courses in site
     # all courses that need to have a formation created
+    main_table: courses
     select:
-      - nodes.id
-      - nodes.name
-      - nodes.publish_from
-      - nodes.zip
-      - nodes.vclass_id
-      - nodes.type
-      - nodes.rgroup_id
-      - nodes.pgroup_id
-      - nodes.ref_lang
-      - form.event_at AS last_date
-      - form.event_at + INTERVAL nodes.custom_a MONTH AS next_date
-      - MIN(IF(form.event_at,form.event_at,0)) AS event_at
-      - MIN(IF(form.event_at,form.event_at,0)) + INTERVAL nodes.custom_a MONTH AS log_at
-      - COUNT(DISTINCT no2.id) AS custom_b
+      - courses.id
+      - courses.name
+      - courses.publish_from
+      - courses.zip
+      - courses.vclass_id
+      - courses.type
+      - courses.rgroup_id
+      - courses.pgroup_id
+      - courses.ref_lang
+      - courses.user_id
+      - courses.max_status
+      - courses.custom_a AS repeat_every
+      - courses.priority
+      - form_status.last_date AS last_date
+      - form_status.last_date + INTERVAL courses.custom_a MONTH AS next_date
+      - MIN(IF(form_status.last_date,form_status.last_date,0)) AS min_last_date
+      - MIN(IF(form_status.last_date,form_status.last_date,0)) + INTERVAL courses.custom_a MONTH AS min_next_date
+      - COUNT(DISTINCT courses.employee_id) AS emp_count
     tables:
-      # nodes: courses
-      - nodes
-      # no1:   assigned_pages
-      # no2:   assigned_employees
-      - links
-      - links AS li1
-      # form.project_id, form.event_at, form.emp_id = formation status for course x (project_id) and employee (emp_id)
+      # course - max(priority) - employee
+      - &quot;(SELECT courses.*, employees.id AS employee_id, MAX(IF(assigned_pages.custom_a,assigned_pages.custom_a,5)) AS priority FROM nodes AS courses, nodes AS employees, nodes AS assigned_pages, links AS li1, links AS li2 WHERE (employees.id = li1.source_id AND li1.relation_id = RELATION_ID(assigned_employee) AND li1.target_id = assigned_pages.project_id) AND (assigned_pages.id = li2.target_id AND li2.relation_id = RELATION_ID(assigned_page) AND li2.source_id = courses.id) GROUP BY id, employee_id) AS courses&quot;
+    join_tables:
+      courses:
+        - &quot;LEFT JOIN (SELECT formations.project_id AS course_id, flink.target_id AS employee_id, MAX(formations.event_at) AS last_date FROM nodes AS formations INNER JOIN links AS flink ON formations.id = flink.source_id AND flink.relation_id = RELATION_ID(assigned_formation) AND (flink.status IS NULL OR flink.status = 100) GROUP BY employee_id, course_id) AS form_status ON form_status.employee_id = courses.employee_id AND form_status.course_id = courses.id&quot;
+    where:
+      - courses.kpath LIKE 'NPPC%'
+    group: courses.priority, courses.id
+    order: min_next_date ASC
+  
+  all_formations_not_over:
+    main_table: formations
+    select:
+      - formations.*
+    tables:
+      - nodes AS formations
     join_tables:
-      nodes:
-        - &quot;INNER JOIN nodes AS no1 INNER JOIN nodes AS no2 LEFT JOIN (SELECT nodes.project_id AS project_id, flink.target_id AS emp_id, MAX(nodes.event_at) AS event_at FROM nodes INNER JOIN links AS flink ON nodes.id = flink.source_id AND flink.relation_id = RELATION_ID(assigned_formation) AND (flink.status IS NULL OR flink.status = 100) GROUP BY flink.target_id, nodes.project_id) AS form ON form.emp_id = no2.id AND form.project_id = nodes.id&quot;
+      formations:
+        - &quot;INNER JOIN links ON formations.id = links.source_id AND links.relation_id = RELATION_ID(assigned_formation) AND (links.status IS NULL OR links.status = 50)&quot;
     where:
-      - no2.id = li1.source_id AND li1.relation_id = RELATION_ID(assigned_employee) AND li1.target_id = no1.project_id
-      - no1.id = links.target_id AND links.relation_id = RELATION_ID(assigned_page) AND links.source_id = nodes.id
-      - nodes.kpath LIKE 'NPPC%'
-    group: nodes.id
-    order: log_at ASC
+      - formations.kpath like 'NNF%'
+    group: formations.id
\ No newline at end of file</diff>
      <filename>lib/custom_queries/complex.host.yml</filename>
    </modified>
    <modified>
      <diff>@@ -1,23 +1,79 @@
+# FORMATION STATUS
+# roger 10 dangerous[~24] / 2004-03-15
+# mike  10 rmanagement[~24]
+# mike  10 ssite[~24]
+# joe   10 ssite[~24]
+# roger 10 ssite[~24]
+# mike  10 tmotivation[~24]
+# mike  10 wusage[~24]
+# roger 10 wusage[~24]
+# joe   10 wusage[~24]
+# 
+# roger 5  engine[~24]
+# roger 5  fiber[~24] / 2003-03-03
+# joe   5  fiber[~24] / 2003-03-03
+# mike  5  fiber[~24] / 2002-02-02
+# roger 5  fproblems[] / 2006-03-20
+# roger 5  tinformation[~12] / 2002-05-05
+# mike  5  vision[~24] / 2003-04-05
+# 
+# joe   1  fproblems[]
+# mike  1  fproblems[]
+# roger 1  radio[~24]
+# joe   1  radio[~24]
+# mike  1  radio[~24]
+# mike  1  tinformation[~12]
+# joe   1  tinformation[~12] / 2003-03-20
+# 
+# ===============
+# 
+# joe   10 ssite[~24]
+# joe   10 wusage[~24]
+# joe   5  fiber[~24] / 2003-03-03
+# joe   1  fproblems[]
+# joe   1  radio[~24]
+# joe   1  tinformation[~12] / 2003-03-20
+# 
+# mike  10 rmanagement[~24]
+# mike  10 ssite[~24]
+# mike  10 tmotivation[~24]
+# mike  10 wusage[~24]
+# mike  5  fiber[~24] / 2002-02-02
+# mike  5  vision[~24] / 2003-04-05
+# mike  1  fproblems[]
+# mike  1  radio[~24]
+# mike  1  tinformation[~12]
+# 
+# roger 10 dangerous[~24] / 2004-03-15
+# roger 10 ssite[~24]
+# roger 10 wusage[~24]
+# roger 5  engine[~24]
+# roger 5  fiber[~24] / 2003-03-03
+# roger 5  fproblems[] / 2006-03-20
+# roger 5  tinformation[~12] / 2002-05-05
+# roger 1  radio[~24]
+
 default:
   context:
     node_name: '@node'
     node: roger
     visitor: complex_admin
     site: complex
-    ref_date: 2005-03-01
-  src: &quot;&lt;r:emp_form_dates where='custom_a is not null' do='each' join=', '&gt;&lt;r:show attr='name'/&gt; (&lt;r:show date='event_at' format='%Y-%m-%d'/&gt;, &lt;r:show date='log_at' format='%Y-%m-%d'/&gt;)&lt;/r:emp_form_dates&gt;&quot;
-  res: &quot;engine (, ), radio_usage (, ), secure_a_site (, ), winch_usage (, ), transmit_information (2002-05-05, 2003-05-05), fiber_junction (2003-03-03, 2005-03-03), dangerous_transportations (2004-03-15, 2006-03-15), formulate_problems (2006-03-20, 2008-03-20)&quot;
+    ref_date: 2004-09-01
+  src: &quot;&lt;r:emp_form_dates where='repeat_every is not null' do='each' join=', '&gt;&lt;r:show attr='name'/&gt;(&lt;r:show attr='priority'/&gt;, &lt;r:show date='last_date' format='%Y-%m-%d'/&gt;, &lt;r:show date='next_date' format='%Y-%m-%d'/&gt;)&lt;/r:emp_form_dates&gt;&quot;
+  res: &quot;secure_a_site(10, , ), winch_usage(10, , ), dangerous_transportations(10, 2004-03-15, 2006-03-15), engine(5, , ), transmit_information(5, 2002-05-05, 2003-05-05), fiber_junction(5, 2003-03-03, 2005-03-03), radio_usage(1, , )&quot;
   
 courses_in_the_next_6_months:
-  # log_at   = next_date
-  # event_at = last_date
   # custom_a = repetition interval
-  src: &quot;&lt;r:emp_form_dates where='last_date is null or (custom_a is not null and next_date lt REF_DATE + 6 month)' do='each' join=', '&gt;&lt;r:show attr='name'/&gt;: &lt;r:show date='log_at' format='%Y-%m-%d'/&gt;&lt;/r:emp_form_dates&gt;&quot;
-  res: &quot;engine: , radio_usage: , secure_a_site: , winch_usage: , transmit_information: 2003-05-05, fiber_junction: 2005-03-03&quot;
+  src: &quot;&lt;r:emp_form_dates where='last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' order='last_date asc, name asc' do='each' join=', '&gt;&lt;r:show attr='name'/&gt;: &lt;r:show date='next_date' format='%Y-%m-%d'/&gt;&lt;/r:emp_form_dates&gt;&quot;
+  res: &quot;engine: , radio_usage: , secure_a_site: , winch_usage: , transmit_information: 2003-05-05&quot;
 
 courses_in_the_next_6_months_do_syntax:
-  src: &quot;&lt;div do='emp_form_dates where last_date is null or (custom_a is not null and next_date lt REF_DATE + 6 month)' do='each' join=', '&gt;&lt;r:show attr='name'/&gt;: &lt;r:show date='log_at' format='%Y-%m-%d'/&gt;&lt;/div&gt;&quot;
-  res: &quot;&lt;div&gt;engine: , radio_usage: , secure_a_site: , winch_usage: , transmit_information: 2003-05-05, fiber_junction: 2005-03-03&lt;/div&gt;&quot;
+  context:
+    ref_date: 2005-03-01
+    # before 2005-06-01
+  src: &quot;&lt;ol do='emp_form_dates where last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' do='group' by='priority'&gt;&lt;li set_class='priority[priority]' do='each_group' do='each' join=', '&gt;&lt;r:show attr='name'/&gt;: &lt;r:show date='next_date' format='%Y-%m-%d'/&gt;&lt;/li&gt;&lt;/ol&gt;&quot;
+  res: &quot;&lt;ol&gt;&lt;li class='priority10'&gt;secure_a_site: , winch_usage: &lt;/li&gt;&lt;li class='priority5'&gt;engine: , transmit_information: 2003-05-05, fiber_junction: 2005-03-03&lt;/li&gt;&lt;li class='priority1'&gt;radio_usage: &lt;/li&gt;&lt;/ol&gt;&quot;
 
 all_formations:
   src: &quot;&lt;r:formations in='site' do='each' join=', '&gt;&lt;r:show attr='name'/&gt;: &lt;r:show date='event_at'/&gt;&lt;/r:formations&gt;&quot;
@@ -30,44 +86,158 @@ all_formations_with_people:
 all_people_related_to_a_course:
   context:
     node: transmit_information
-  src: &quot;&lt;r:course_emp_dates do='each' join=', '&gt;&lt;r:show attr='name'/&gt; (last:&lt;r:show date='event_at'/&gt;, next:&lt;r:show date='log_at'/&gt;)&lt;/r:course_emp_dates&gt;&quot;
+  src: &quot;&lt;r:course_emp_dates do='each' join=', '&gt;&lt;r:show attr='name'/&gt; (last:&lt;r:show date='last_date'/&gt;, next:&lt;r:show date='next_date'/&gt;)&lt;/r:course_emp_dates&gt;&quot;
   res: &quot;joe (last:2003-03-20, next:2004-03-20), mike (last:, next:), roger (last:2002-05-05, next:2003-05-05)&quot;
 
+all_people_related_to_a_course_group_by_priority:
+  context:
+    node: transmit_information
+  src: |
+    &lt;ol do='course_emp_dates' where='last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' order='priority desc, last_date asc, name asc' do='group' by='priority'&gt;
+      &lt;li set_class='priority[priority]' do='each_group'&gt;
+        &lt;ol&gt;
+          &lt;li do='each'&gt;&lt;r:show attr='name'/&gt; (last:&lt;r:show date='last_date'/&gt;, next:&lt;r:show date='next_date'/&gt;)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+    &lt;/ol&gt;
+  res: |
+    &lt;ol&gt;  &lt;li class='priority5'&gt;
+        &lt;ol&gt;
+          &lt;li&gt;roger (last:2002-05-05, next:2003-05-05)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+      &lt;li class='priority1'&gt;
+        &lt;ol&gt;
+          &lt;li&gt;mike (last:, next:)&lt;/li&gt;
+          &lt;li&gt;joe (last:2003-03-20, next:2004-03-20)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+    &lt;/ol&gt;
+      
 all_people_related_to_a_course_in_6_month:
   context:
     node: transmit_information
     ref_date: 2003-04-04
-  src: &quot;&lt;r:course_emp_dates where='last_date is null or (custom_a is not null and next_date lt REF_DATE + 6 month)' do='each' join=', '&gt;&lt;r:show attr='name'/&gt; (last:&lt;r:show date='event_at'/&gt;, next:&lt;r:show date='log_at'/&gt;)&lt;/r:course_emp_dates&gt;&quot;
+  src: &quot;&lt;r:course_emp_dates where='last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month)' do='each' join=', '&gt;&lt;r:show attr='name'/&gt; (last:&lt;r:show date='last_date'/&gt;, next:&lt;r:show date='next_date'/&gt;)&lt;/r:course_emp_dates&gt;&quot;
   res: &quot;mike (last:, next:), roger (last:2002-05-05, next:2003-05-05)&quot;
 
 all_course_emp_date:
-  # next:
-  # dangerous_transportations: 2006-03-15
-  # fiber_junction: 2004-02-02, 2005-03-03, 2005-03-03
-  # vision: 2005-04-05
-  # transmit_information: --, 2003-05-05, 2004-03-20
-  # engine, formulate_problems, radio_usage, secure_a_site, winch_usage, resp_management, team_motivation: asap
-  src: &quot;&lt;r:all_course_emp_dates order='name asc' do='each' join=', '&gt;&lt;r:show date='log_at'/&gt; &lt;r:show attr='name'/&gt; (&lt;r:show attr='custom_b'/&gt;)&lt;/r:all_course_emp_dates&gt;&quot;
-  res: &quot;2006-03-15 dangerous_transportations (1),  engine (1), 2004-02-02 fiber_junction (3),  formulate_problems (3),  radio_usage (3),  resp_management (1),  secure_a_site (3),  team_motivation (1),  transmit_information (3), 2005-04-05 vision (1),  winch_usage (3)&quot;
+  src: |
+    &lt;ol do='all_course_emp_dates order by priority desc, log_at asc, name asc'&gt;
+    &lt;r:group by='priority'&gt;
+      &lt;li do='each_group' set_class='priority[priority]'&gt;
+        &lt;ol&gt;
+          &lt;li do='each'&gt;&lt;r:if test='min_next_date'&gt;&lt;r:show date='min_next_date' tformat='%Y-%m-%d'/&gt;&lt;r:else&gt;ASAP&lt;/r:else&gt;&lt;/r:if&gt; &lt;r:show attr='name'/&gt; (&lt;r:show attr='emp_count'/&gt;)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+    &lt;/r:group&gt;
+    &lt;/ol&gt;
+  res: |
+    &lt;ol&gt;
+      &lt;li class='priority10'&gt;
+        &lt;ol&gt;
+          &lt;li&gt;2006-03-15 dangerous_transportations (1)&lt;/li&gt;
+          &lt;li&gt;ASAP resp_management (1)&lt;/li&gt;
+          &lt;li&gt;ASAP secure_a_site (3)&lt;/li&gt;
+          &lt;li&gt;ASAP team_motivation (1)&lt;/li&gt;
+          &lt;li&gt;ASAP winch_usage (3)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+      &lt;li class='priority5'&gt;
+        &lt;ol&gt;
+          &lt;li&gt;ASAP engine (1)&lt;/li&gt;
+          &lt;li&gt;2004-02-02 fiber_junction (3)&lt;/li&gt;
+          &lt;li&gt;ASAP formulate_problems (1)&lt;/li&gt;
+          &lt;li&gt;2003-05-05 transmit_information (1)&lt;/li&gt;
+          &lt;li&gt;2005-04-05 vision (1)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+      &lt;li class='priority1'&gt;
+        &lt;ol&gt;
+          &lt;li&gt;ASAP formulate_problems (2)&lt;/li&gt;
+          &lt;li&gt;ASAP radio_usage (3)&lt;/li&gt;
+          &lt;li&gt;ASAP transmit_information (2)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+    &lt;/ol&gt;
 
 all_course_emp_dates_in_six_months:
   context:
     ref_date: 2003-09-01
-    # next:
-    # dangerous_transportations: 2006-03-15
-    # fiber_junction: 2004-02-02, 2005-03-03, 2005-03-03
-    # vision: 2005-04-05
-    # transmit_information: --, 2003-05-05, 2004-03-20
-  src: &quot;&lt;r:all_course_emp_dates where='custom_a is not null and (last_date is null or next_date lt REF_DATE + 6 month) order by name asc' do='each' join=', '&gt;&lt;r:show date='log_at'/&gt; &lt;r:show attr='name'/&gt; (&lt;r:show attr='custom_b'/&gt;)&lt;/r:all_course_emp_dates&gt;&quot;
-  res: &quot; engine (1), 2004-02-02 fiber_junction (1),  formulate_problems (2),  radio_usage (3),  resp_management (1),  secure_a_site (3),  team_motivation (1),  transmit_information (2),  winch_usage (3)&quot;
+    # in 6 months = before 2004-03-01
+  src: |
+    &lt;ol do='all_course_emp_dates where last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month) order by priority desc, log_at asc, name asc'&gt;
+    &lt;r:group by='priority'&gt;
+      &lt;li do='each_group' set_class='priority[priority]'&gt;
+        &lt;ol&gt;
+          &lt;li do='each'&gt;&lt;r:if test='min_next_date'&gt;&lt;r:show date='min_next_date' tformat='%Y-%m-%d'/&gt;&lt;r:else&gt;ASAP&lt;/r:else&gt;&lt;/r:if&gt; &lt;r:show attr='name'/&gt; (&lt;r:show attr='emp_count'/&gt;)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+    &lt;/r:group&gt;
+    &lt;/ol&gt;
+  res: |
+    &lt;ol&gt;
+      &lt;li class='priority10'&gt;
+        &lt;ol&gt;
+          &lt;li&gt;ASAP resp_management (1)&lt;/li&gt;
+          &lt;li&gt;ASAP secure_a_site (3)&lt;/li&gt;
+          &lt;li&gt;ASAP team_motivation (1)&lt;/li&gt;
+          &lt;li&gt;ASAP winch_usage (3)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+      &lt;li class='priority5'&gt;
+        &lt;ol&gt;
+          &lt;li&gt;ASAP engine (1)&lt;/li&gt;
+          &lt;li&gt;2004-02-02 fiber_junction (1)&lt;/li&gt;
+          &lt;li&gt;2003-05-05 transmit_information (1)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+      &lt;li class='priority1'&gt;
+        &lt;ol&gt;
+          &lt;li&gt;ASAP formulate_problems (2)&lt;/li&gt;
+          &lt;li&gt;ASAP radio_usage (3)&lt;/li&gt;
+          &lt;li&gt;ASAP transmit_information (1)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+    &lt;/ol&gt;
 
 all_course_emp_dates_in_six_months_later:
   context:
-    ref_date: 2007-06-01
-    # next:
-    # dangerous_transportations: 2006-03-15
-      # fiber_junction: 2004-02-02, 2005-03-03, 2005-03-03
-    # vision: 2005-04-05
-    # transmit_information: --, 2003-05-05, 2004-03-20
-  src: &quot;&lt;r:all_course_emp_dates where='custom_a is not null and (last_date is null or next_date lt REF_DATE + 6 month) order by name asc' do='each' join=', '&gt;&lt;r:show date='log_at'/&gt; &lt;r:show attr='name'/&gt; (&lt;r:show attr='custom_b'/&gt;)&lt;/r:all_course_emp_dates&gt;&quot;
-  res: &quot;2006-03-15 dangerous_transportations (1),  engine (1), 2004-02-02 fiber_junction (3),  formulate_problems (2),  radio_usage (3),  resp_management (1),  secure_a_site (3),  team_motivation (1),  transmit_information (3), 2005-04-05 vision (1),  winch_usage (3)&quot;
\ No newline at end of file
+    ref_date: 2004-03-01
+    # in 6 months = before 2004-09-01
+  src: |
+    &lt;ol do='all_course_emp_dates where last_date is null or (repeat_every is not null and next_date lt REF_DATE + 6 month) order by priority desc, log_at asc, name asc'&gt;
+    &lt;r:group by='priority'&gt;
+      &lt;li do='each_group' set_class='priority[priority]'&gt;
+        &lt;ol&gt;
+          &lt;li do='each'&gt;&lt;r:if test='min_next_date'&gt;&lt;r:show date='min_next_date' tformat='%Y-%m-%d'/&gt;&lt;r:else&gt;ASAP&lt;/r:else&gt;&lt;/r:if&gt; &lt;r:show attr='name'/&gt; (&lt;r:show attr='emp_count'/&gt;)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+    &lt;/r:group&gt;
+    &lt;/ol&gt;
+  res: |
+    &lt;ol&gt;
+      &lt;li class='priority10'&gt;
+        &lt;ol&gt;
+          &lt;li&gt;ASAP resp_management (1)&lt;/li&gt;
+          &lt;li&gt;ASAP secure_a_site (3)&lt;/li&gt;
+          &lt;li&gt;ASAP team_motivation (1)&lt;/li&gt;
+          &lt;li&gt;ASAP winch_usage (3)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+      &lt;li class='priority5'&gt;
+        &lt;ol&gt;
+          &lt;li&gt;ASAP engine (1)&lt;/li&gt;
+          &lt;li&gt;2004-02-02 fiber_junction (1)&lt;/li&gt;
+          &lt;li&gt;2003-05-05 transmit_information (1)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+      &lt;li class='priority1'&gt;
+        &lt;ol&gt;
+          &lt;li&gt;ASAP formulate_problems (2)&lt;/li&gt;
+          &lt;li&gt;ASAP radio_usage (3)&lt;/li&gt;
+          &lt;li&gt;ASAP transmit_information (2)&lt;/li&gt;
+        &lt;/ol&gt;
+      &lt;/li&gt;
+    &lt;/ol&gt;
+    
\ No newline at end of file</diff>
      <filename>test/helpers/zena_parser/complex.yml</filename>
    </modified>
    <modified>
      <diff>@@ -67,6 +67,7 @@ driver_security:
   class:           Page
   parent:          driver
   v_title:         security
+  custom_a:        10
 
 driver_team:
   class:           Page
@@ -87,11 +88,13 @@ technician_security:
   class:           Page
   parent:          technician
   v_title:         security
+  custom_a:        10
 
 technician_team:
   class:           Page
   parent:          technician
   v_title:         team work
+  custom_a:        1
 
 technician_fiber:
   class:           Page
@@ -108,6 +111,7 @@ chief_motivation:
   class:           Page
   parent:          chief
   v_title:         team motivation
+  custom_a:        10
 
 chief_image:
   class:           Page
@@ -130,7 +134,6 @@ dangerous_transportations:
 formulate_problems:
   class:           Course
   parent:          courses
-  custom_a:        24
   v_title:         problem formulation
 
 transmit_information:</diff>
      <filename>test/sites/complex/nodes.yml</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>c53d2470d6fc1f830b1603d9ecd4e354faff8fe1</id>
    </parent>
  </parents>
  <author>
    <name>Gaspard Bucher</name>
    <email>gaspard@teti.ch</email>
  </author>
  <url>http://github.com/zena/zena/commit/a30c637a68827181c10b70a630c59c4aa346404e</url>
  <id>a30c637a68827181c10b70a630c59c4aa346404e</id>
  <committed-date>2009-04-05T14:51:14-07:00</committed-date>
  <authored-date>2009-04-05T14:51:14-07:00</authored-date>
  <message>More tests for custom queries using latest querybuilder (0.5.2).</message>
  <tree>00c24ab5df0a0e8ef60ca244f90f7dfd9d79c6c7</tree>
  <committer>
    <name>Gaspard Bucher</name>
    <email>gaspard@teti.ch</email>
  </committer>
</commit>
