public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/templatetags/, ...
@ 2012-06-15 23:28 Slava Bacherikov
  0 siblings, 0 replies; 8+ messages in thread
From: Slava Bacherikov @ 2012-06-15 23:28 UTC (permalink / raw
  To: gentoo-commits

commit:     cd472edeab4c8759179b7eb4a89ac6cd7ab4c601
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Fri Jun 15 16:41:16 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Fri Jun 15 16:41:16 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=cd472ede

Save info about repository update time

---
 gpackages/apps/packages/models.py                |    3 +--
 gpackages/apps/packages/scan.py                  |    4 ++++
 gpackages/apps/packages/templatetags/packages.py |   10 ++++++++++
 gpackages/template/base.html                     |    4 +++-
 gpackages/template/last_updated.html             |    1 +
 5 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index 612de5b..c2b62ac 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -28,10 +28,9 @@ class ArchesModel(models.Model):
     def __unicode__(self):
         return self.name
 
-class RepositoryModel(models.Model):
+class RepositoryModel(AbstractDateTimeModel):
     name = models.CharField(unique = True, max_length = 60)
     description = models.TextField(blank = True, null = True)
-    # And other fields
 
     def __unicode__(self):
         return self.name

diff --git a/gpackages/apps/packages/scan.py b/gpackages/apps/packages/scan.py
index f4c6377..d716380 100644
--- a/gpackages/apps/packages/scan.py
+++ b/gpackages/apps/packages/scan.py
@@ -312,6 +312,10 @@ class Scanner(object):
         repo_obj, repo_created = models.RepositoryModel \
             .objects.get_or_create(name = repo.name)
 
+        if not repo_created:
+            #Update modification time
+            repo_obj.save(force_update = True)
+
         self.scanpackages(repo, repo_obj, **kwargs)
         
 

diff --git a/gpackages/apps/packages/templatetags/__init__.py b/gpackages/apps/packages/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29

diff --git a/gpackages/apps/packages/templatetags/packages.py b/gpackages/apps/packages/templatetags/packages.py
new file mode 100644
index 0000000..abe1039
--- /dev/null
+++ b/gpackages/apps/packages/templatetags/packages.py
@@ -0,0 +1,10 @@
+from django import template
+
+register = template.Library()
+
+from ..models import RepositoryModel
+
+@register.inclusion_tag('last_updated.html')
+def last_updated():
+    l = RepositoryModel.objects.only('updated_datetime').latest('updated_datetime')
+    return {'last_updated': l.updated_datetime}

diff --git a/gpackages/template/base.html b/gpackages/template/base.html
index b63314b..5347af5 100644
--- a/gpackages/template/base.html
+++ b/gpackages/template/base.html
@@ -1,4 +1,5 @@
 {% load url from future %}
+{% load packages %}
 <!DOCTYPE html>
 <html lang="en">
   <head>
@@ -102,7 +103,8 @@ Text
                     <div class="well">
                                                         <div id="rightcontent">
                                                         <div>
-                                                            <span class="label label-info" style="display: block"> Last update</span>11 Jun 2012<br/> 10:47 UTC 
+                                                            <span class="label label-info" style="display: block"> Last update</span> 
+                                                            {% last_updated %}
                                                         </div><br/>
                                                       <div>
                                                           <span class="left-legend label label-info" style="display: block;">Legend</span>

diff --git a/gpackages/template/last_updated.html b/gpackages/template/last_updated.html
new file mode 100644
index 0000000..83e9d44
--- /dev/null
+++ b/gpackages/template/last_updated.html
@@ -0,0 +1 @@
+{{ last_updated|date:"d M Y" }} <br /> {{ last_updated|date:"H:i:s" }}



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/templatetags/, ...
@ 2012-06-27 22:52 Slava Bacherikov
  0 siblings, 0 replies; 8+ messages in thread
From: Slava Bacherikov @ 2012-06-27 22:52 UTC (permalink / raw
  To: gentoo-commits

commit:     2b8d34a766395927b86fb0f358442927b6fd6036
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Wed Jun 27 22:52:35 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Wed Jun 27 22:52:35 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=2b8d34a7

Add keywords table.

---
 gpackages/apps/packages/keywords.py              |   25 ++++++++++++
 gpackages/apps/packages/models.py                |   43 ++++++++++++++++++++-
 gpackages/apps/packages/templatetags/packages.py |    4 ++
 gpackages/templates/ebuilds.html                 |   44 +--------------------
 gpackages/templates/keywords_table.html          |   27 +++++++++++++
 gpackages/templates/packages.html                |   46 +---------------------
 6 files changed, 102 insertions(+), 87 deletions(-)

diff --git a/gpackages/apps/packages/keywords.py b/gpackages/apps/packages/keywords.py
new file mode 100644
index 0000000..0ab1e87
--- /dev/null
+++ b/gpackages/apps/packages/keywords.py
@@ -0,0 +1,25 @@
+from functools import total_ordering
+from package_info.generic import ToStrMixin
+
+class KeywordRepr(ToStrMixin):
+
+    __slots__ = ('status', 'arch')
+
+    status_repr_list = ('', '+', '~','-')
+    status_class_list = ('blank', 'stable', 'unstable', 'hardmask')
+    
+    def __init__(self, arch, status):
+        self.arch = arch
+        self.status = status
+
+    @property
+    def status_repr(self):
+        return self.status_repr_list[self.status + 1]
+
+    @property
+    def status_class(self):
+        return self.status_class_list[self.status + 1]
+
+    def __unicode__(self):
+        return unicode(self.status_repr + self.arch)
+

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index 290516c..187088e 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -1,10 +1,11 @@
 from django.db import models
-
 from package_info.abstract import AbstractCategory, AbstarctPackage, \
                                   AbstractEbuild
 import managers
 from package_info.generic import get_from_kwargs_and_del
 from package_info.repo_info import REPOS_TYPE
+# relative
+from .keywords import KeywordRepr
 
 from django.core.validators import URLValidator, validate_email 
 from django.core.exceptions import ValidationError
@@ -305,6 +306,13 @@ class PackageModel(AbstractDateTimeModel):
         self.metadata_hash = package.metadata_sha1
         self.description = package.description
 
+    def get_ebuilds_and_keywords(self, arch_list):
+        l = []
+        for ebuild in self.ebuildmodel_set.order_by('-version', '-revision'):
+            l.extend(ebuild.get_ebuilds_and_keywords(arch_list))
+        return l
+            
+
     class Meta:
         unique_together = ('virtual_package', 'repository')
         ordering = ('-updated_datetime',)
@@ -438,6 +446,39 @@ class EbuildModel(AbstractDateTimeModel):
     def fullversion(self):
         return '%s%s' %  (self.version, ('-'+ self.revision if self.revision else ''))
 
+    def get_keywords(self, arch_list):
+        keywords_dict = self.get_keywords_dict(arch_list)
+        return (KeywordRepr(arch, keywords_dict[arch]) for arch in arch_list)
+
+    def get_keywords_dict(self, arch_list):
+        arch_set = set(arch_list)
+        keywords_list = self.load_keywords(arch_set)
+        keywords_cache_dict = {}
+        for keyword in keywords_list:
+            keywords_cache_dict[keyword.arch.name] = keyword
+
+        keywords_dict = {}
+        keyword_wild = keywords_cache_dict.get('*')
+        for arch in arch_list:
+            keyword_obj = keywords_cache_dict.get(arch)
+            status = -1
+            if keyword_obj is not None:
+                status = keyword_obj.status
+            elif keyword_wild is not None:
+                status = keyword_wild.status
+            keywords_dict[arch] = status
+
+        return keywords_dict
+
+    def load_keywords(self, arch_set):
+        arch_set.add('*')
+        return self.keyword_set.filter(arch__name__in = arch_set).select_related('arch')
+
+    def get_ebuilds_and_keywords(self, arch_list):
+        # Maybe copy object ? !!
+        self.keywords = self.get_keywords(arch_list)
+        return (self, )
+
     class Meta:
         unique_together = ('package', 'version', 'revision')
         ordering = ('-updated_datetime',)

diff --git a/gpackages/apps/packages/templatetags/packages.py b/gpackages/apps/packages/templatetags/packages.py
index 80fe826..45c756d 100644
--- a/gpackages/apps/packages/templatetags/packages.py
+++ b/gpackages/apps/packages/templatetags/packages.py
@@ -10,6 +10,10 @@ def last_updated():
     l = RepositoryModel.objects.only('updated_datetime').latest('updated_datetime')
     return {'last_updated': l.updated_datetime}
 
+@register.inclusion_tag('keywords_table.html')
+def render_keywords_table(obj, *arch_list):
+    ebuilds = obj.get_ebuilds_and_keywords(arch_list)
+    return {'arches': arch_list, 'ebuilds' : ebuilds}
 
 def text_sincode(text):
     text_l = map(lambda x: '&#%s;' % ord(x), text)

diff --git a/gpackages/templates/ebuilds.html b/gpackages/templates/ebuilds.html
index 81ca0b8..ef51a43 100644
--- a/gpackages/templates/ebuilds.html
+++ b/gpackages/templates/ebuilds.html
@@ -1,4 +1,5 @@
 {% extends "base.html" %}
+{% load packages %}
 
 {% block content %}
 {% for ebuild in ebuilds %}
@@ -8,48 +9,7 @@
             <span class="package_update_datetime">{{ ebuild.updated_datetime }}</span>
         </div>
         <div style="padding-bottom: 10px; margin 10px;">{{ ebuild.description }}</div>
-        <table class="keywords table table-bordered table-condensed">
-            <colgroup>
-                <col class="span2">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-            </colgroup>
-            <thead>
-                <tr class="">
-                    <th class=""></th>
-                    <th class="">alpha</th>
-                    <th class="">amd64</th>
-                    <th class="">arm</th>
-                    <th class="">hppa</th>
-                    <th class="">ia64</th>
-                    <th class="">ppc</th>
-                    <th class="">ppc64</th>
-                    <th class="">sparc</th>
-                    <th class="">x86</th>
-                </tr>
-            </thead>
-            <tbody>
-                <tr>
-                    <td class="ebuild">{{ ebuild.fullversion }}</td>
-                    <td class="blank"></td>
-                    <td class="unstable">~</td>
-                    <td class="blank"></td>
-                    <td class="blank"></td>
-                    <td class="blank"></td>
-                    <td class="blank"></td>
-                    <td class="blank"></td>
-                    <td class="blank"></td>
-                    <td class="unstable">~</td>
-                </tr>
-            </tbody>
-        </table>
+        {% render_keywords_table ebuild 'alpha' 'amd64' 'arm' 'hppa' 'ia64' 'ppc' 'ppc64' 'sparc' 'x86' %}
     </div>
 {% endfor %}
 {% include 'paginator.html' %}

diff --git a/gpackages/templates/keywords_table.html b/gpackages/templates/keywords_table.html
new file mode 100644
index 0000000..38cba68
--- /dev/null
+++ b/gpackages/templates/keywords_table.html
@@ -0,0 +1,27 @@
+<table class="keywords table table-bordered table-condensed">
+    <colgroup>
+        <col class="span2">
+        {% for arch in arches %}
+            <col class="span1">
+        {% endfor %}
+
+    </colgroup>
+    <thead>
+        <tr class="">
+            <th class=""></th>
+            {% for arch in arches %}
+                <th class="">{{ arch }}</th>
+            {% endfor %}
+        </tr>
+    </thead>
+    <tbody>
+        {% for ebuild in ebuilds %}
+        <tr>
+            <td class="ebuild">{{ ebuild.fullversion }}</td>
+            {% for keyword in ebuild.keywords %}
+            <td class="{{ keyword.status_class }}">{{ keyword.status_repr }}</td>
+            {% endfor %}
+        </tr>
+        {% endfor %}
+    </tbody> 
+</table>

diff --git a/gpackages/templates/packages.html b/gpackages/templates/packages.html
index adead16..b6600dc 100644
--- a/gpackages/templates/packages.html
+++ b/gpackages/templates/packages.html
@@ -1,4 +1,5 @@
 {% extends "base.html" %}
+{% load packages %}
 
 {% block content %}
 {% for package in packages %}
@@ -10,50 +11,7 @@
         {% if package.description %}
         <div style="padding-bottom: 10px; margin 10px;">{{ package.description }}</div>
         {% endif %}
-        <table class="keywords table table-bordered table-condensed">
-            <colgroup>
-                <col class="span2">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-                <col class="span1">
-            </colgroup>
-            <thead>
-                <tr class="">
-                    <th class=""></th>
-                    <th class="">alpha</th>
-                    <th class="">amd64</th>
-                    <th class="">arm</th>
-                    <th class="">hppa</th>
-                    <th class="">ia64</th>
-                    <th class="">ppc</th>
-                    <th class="">ppc64</th>
-                    <th class="">sparc</th>
-                    <th class="">x86</th>
-                </tr>
-            </thead>
-            <tbody>
-                {% for ebuild in package.ebuildmodel_set.all_by_numbers %}
-                    <tr>
-                        <td class="ebuild">{{ ebuild.fullversion }}</td>
-                        <td class="blank"></td>
-                        <td class="unstable">~</td>
-                        <td class="blank"></td>
-                        <td class="blank"></td>
-                        <td class="blank"></td>
-                        <td class="blank"></td>
-                        <td class="blank"></td>
-                        <td class="blank"></td>
-                        <td class="unstable">~</td>
-                    </tr>
-                {% endfor %}
-            </tbody>
-        </table>
+        {% render_keywords_table package 'alpha' 'amd64' 'arm' 'hppa' 'ia64' 'ppc' 'ppc64' 'sparc' 'x86' %}
     </div>
 {% endfor %}
 {% include 'paginator.html' %}



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/templatetags/, ...
@ 2012-06-28 23:59 Slava Bacherikov
  0 siblings, 0 replies; 8+ messages in thread
From: Slava Bacherikov @ 2012-06-28 23:59 UTC (permalink / raw
  To: gentoo-commits

commit:     43ce171f72aa969fd1d2d87449789867065ae8f1
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Thu Jun 28 12:26:12 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Thu Jun 28 12:26:12 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=43ce171f

Add custom prefetch for keywords.

---
 gpackages/apps/packages/managers.py              |   51 +++++++++++++++++++++-
 gpackages/apps/packages/models.py                |   11 +++--
 gpackages/apps/packages/templatetags/packages.py |    2 +-
 gpackages/apps/packages/views.py                 |    8 ++-
 gpackages/templates/ebuilds.html                 |    2 +-
 gpackages/templates/packages.html                |    2 +-
 6 files changed, 65 insertions(+), 11 deletions(-)

diff --git a/gpackages/apps/packages/managers.py b/gpackages/apps/packages/managers.py
index 557cd48..012b40d 100644
--- a/gpackages/apps/packages/managers.py
+++ b/gpackages/apps/packages/managers.py
@@ -3,6 +3,7 @@ from package_info.abstract import AbstarctPackage, AbstractEbuild, \
                                   AbstractKeywords 
 import packages.models
 from package_info.generic import get_from_kwargs_and_del
+from collections import defaultdict
 
 def _gen_query_and_manager(MixinClass, QueryClassName, ManagerClassName):
     QueryClass = type(QueryClassName, (MixinClass, models.query.QuerySet), {})
@@ -68,7 +69,7 @@ class KeywordMixin(object):#{{{
 
 
 class EbuildMixin(object):#{{{
-    
+
     def get(self, ebuild=None, package = None, *args, **kwargs):
         if ebuild is not None and isinstance(ebuild, AbstractEbuild):
             if package is None:
@@ -84,6 +85,54 @@ class EbuildMixin(object):#{{{
     def all_by_numbers(self):
         return super(EbuildMixin, self).order_by('version', 'revision')
 
+    def __init__(self, *args, **kwargs):
+        super(EbuildMixin, self).__init__(*args, **kwargs)
+        self._arches_set = None
+        self._cache_keywords = None
+    
+    # Maybe use https://github.com/ionelmc/django-prefetch ?
+    def prefetch_with_keywords(self, arch_list):
+        arch_set = set(arch_list)
+        arch_set.add('*')
+        self._arches_set = arch_set
+        return self
+
+    def __old_iter__(self):
+        return super(EbuildMixin, self).__iter__()
+
+    def _clone(self, *args, **kwargs):
+        c = super(EbuildMixin, self)._clone(*args, **kwargs)
+        c._arches_set = self._arches_set
+        return c
+
+    def _prefetch_keywords(self):
+        arch_set = self._arches_set
+        pk_keys = [ebuild.pk for ebuild in self.__old_iter__()]
+        query = packages.models.Keyword.objects.filter(ebuild__in = pk_keys,
+                                                       arch__name__in = arch_set).select_related('arch')
+
+        cache_query = defaultdict(list)
+        for keyword in query:
+            cache_query[keyword.ebuild_id].append(keyword)
+
+        self._cache_keywords = cache_query
+
+    def __iter__(self):
+        arch_set = self._arches_set
+        if arch_set is None:
+            for ebuild in self.__old_iter__():
+                yield ebuild
+        else:
+            if self._cache_keywords is None:
+                self._prefetch_keywords()
+
+            cache_query = self._cache_keywords
+                
+            for ebuild in self.__old_iter__():
+                ebuild._prefetched_keywords = cache_query[ebuild.pk]
+                yield ebuild
+
+            
 
 class HerdsMixin(object):#{{{
     def filter(self, *args, **kwargs):

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index 187088e..caa7156 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -312,7 +312,6 @@ class PackageModel(AbstractDateTimeModel):
             l.extend(ebuild.get_ebuilds_and_keywords(arch_list))
         return l
             
-
     class Meta:
         unique_together = ('virtual_package', 'repository')
         ordering = ('-updated_datetime',)
@@ -381,6 +380,7 @@ class EbuildModel(AbstractDateTimeModel):
         super(EbuildModel, self).__init__(*args, **kwargs)
         if isinstance(ebuild, AbstractEbuild):
             self.init_by_ebuild(ebuild)
+        self._prefetched_keywords = None
     
     def __unicode__(self):
         return self.cpv
@@ -470,9 +470,12 @@ class EbuildModel(AbstractDateTimeModel):
 
         return keywords_dict
 
-    def load_keywords(self, arch_set):
-        arch_set.add('*')
-        return self.keyword_set.filter(arch__name__in = arch_set).select_related('arch')
+    def load_keywords(self, arch_set, flush_cache = False):
+        if self._prefetched_keywords is None or flush_cache:
+            arch_set.add('*')
+            self._prefetched_keywords = self.keyword_set. \
+                filter(arch__name__in = arch_set).select_related('arch')
+        return self._prefetched_keywords
 
     def get_ebuilds_and_keywords(self, arch_list):
         # Maybe copy object ? !!

diff --git a/gpackages/apps/packages/templatetags/packages.py b/gpackages/apps/packages/templatetags/packages.py
index 45c756d..e381cb0 100644
--- a/gpackages/apps/packages/templatetags/packages.py
+++ b/gpackages/apps/packages/templatetags/packages.py
@@ -11,7 +11,7 @@ def last_updated():
     return {'last_updated': l.updated_datetime}
 
 @register.inclusion_tag('keywords_table.html')
-def render_keywords_table(obj, *arch_list):
+def render_keywords_table(obj, arch_list):
     ebuilds = obj.get_ebuilds_and_keywords(arch_list)
     return {'arches': arch_list, 'ebuilds' : ebuilds}
 

diff --git a/gpackages/apps/packages/views.py b/gpackages/apps/packages/views.py
index 6f73fdd..16c74e2 100644
--- a/gpackages/apps/packages/views.py
+++ b/gpackages/apps/packages/views.py
@@ -35,18 +35,20 @@ class LicenseGroupsView(ContextListView):
     context_object_name = 'license_groups'
 
 class EbuildsListView(ContextListView):
+    arches = ['alpha', 'amd64', 'arm', 'hppa', 'ia64', 'ppc', 'ppc64', 'sparc', 'x86']
     paginate_by = 40
-    extra_context = {'page_name': 'Ebuilds',}
+    extra_context = {'page_name': 'Ebuilds', 'arches' : arches}
     template_name = 'ebuilds.html'
     context_object_name = 'ebuilds'
     queryset = EbuildModel.objects.all(). \
         select_related('package',
                        'package__virtual_package',
-                       'package__virtual_package__category')
+                       'package__virtual_package__category').prefetch_with_keywords(arches)
 
 class PackagesListsView(ContextListView):
+    arches = ['alpha', 'amd64', 'arm', 'hppa', 'ia64', 'ppc', 'ppc64', 'sparc', 'x86']
     paginate_by = 40
-    extra_context = {'page_name': 'Packages',}
+    extra_context = {'page_name': 'Packages', 'arches': arches}
     template_name = 'packages.html'
     context_object_name = 'packages'
     queryset = PackageModel.objects.all(). \

diff --git a/gpackages/templates/ebuilds.html b/gpackages/templates/ebuilds.html
index ef51a43..94e1ecd 100644
--- a/gpackages/templates/ebuilds.html
+++ b/gpackages/templates/ebuilds.html
@@ -9,7 +9,7 @@
             <span class="package_update_datetime">{{ ebuild.updated_datetime }}</span>
         </div>
         <div style="padding-bottom: 10px; margin 10px;">{{ ebuild.description }}</div>
-        {% render_keywords_table ebuild 'alpha' 'amd64' 'arm' 'hppa' 'ia64' 'ppc' 'ppc64' 'sparc' 'x86' %}
+        {% render_keywords_table ebuild arches %}
     </div>
 {% endfor %}
 {% include 'paginator.html' %}

diff --git a/gpackages/templates/packages.html b/gpackages/templates/packages.html
index b6600dc..ec6d22a 100644
--- a/gpackages/templates/packages.html
+++ b/gpackages/templates/packages.html
@@ -11,7 +11,7 @@
         {% if package.description %}
         <div style="padding-bottom: 10px; margin 10px;">{{ package.description }}</div>
         {% endif %}
-        {% render_keywords_table package 'alpha' 'amd64' 'arm' 'hppa' 'ia64' 'ppc' 'ppc64' 'sparc' 'x86' %}
+        {% render_keywords_table package arches %}
     </div>
 {% endfor %}
 {% include 'paginator.html' %}



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/templatetags/, ...
@ 2012-07-18 23:03 Slava Bacherikov
  0 siblings, 0 replies; 8+ messages in thread
From: Slava Bacherikov @ 2012-07-18 23:03 UTC (permalink / raw
  To: gentoo-commits

commit:     08eb6c67d4a8d6a39aa198e38c4c9fcfe1d97bd8
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Wed Jul 18 16:36:11 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Wed Jul 18 16:39:28 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=08eb6c67

Return filters back to modal form

---
 gpackages/apps/generic/views.py                  |   26 ++++++++++++++++-----
 gpackages/apps/packages/forms.py                 |    5 +++-
 gpackages/apps/packages/templatetags/packages.py |   16 +++++++++++--
 3 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/gpackages/apps/generic/views.py b/gpackages/apps/generic/views.py
index 27a64eb..08bf734 100644
--- a/gpackages/apps/generic/views.py
+++ b/gpackages/apps/generic/views.py
@@ -30,11 +30,8 @@ def dynamic_filter(filter_set, allowed, many_set = {}):
     for k, v in allowed.iteritems():
         if k in filter_set:
             vv = filter_set[k]
-            if k in many_set:
-                l = vv.split(',')
-                if len(l)>1:
-                    v += '__in'
-                    vv = cut_to_len(l, many_set[k])
+            if k in many_set and isinstance(vv, list):
+                v += '__in'
             result[v] = vv
     return result
 
@@ -74,11 +71,28 @@ class MultipleFilterListViewMixin(object):
     allowed_many = {}
     m2m_filter = set()
 
-    def get_filters(self):
+    def get_context_data(self, **kwargs):
+        cd = super(MultipleFilterListViewMixin, self).get_context_data(**kwargs)
+        cd['filters_dict'] = self.queries_dict
+        return cd
+
+    def get_base_filters(self):
         qs = filter_req(self.request.GET, self.allowed_filter)
         qs.update(filter_req(self.kwargs, self.allowed_filter))
         return qs
 
+    def get_filters(self):
+        qs = self.get_base_filters()
+        newqs = {}
+        for k, v in qs.iteritems():
+            if k in self.allowed_many:
+                vm = v.split(',')
+                if len(vm)>1:
+                    v = cut_to_len(vm, self.allowed_many[k])
+            newqs[k] = v 
+        self.queries_dict = newqs
+        return newqs
+
     def is_reverse(self):
         if self.kwargs.get('rev') is None:
             reverse = bool(self.request.GET.get('rev',False))

diff --git a/gpackages/apps/packages/forms.py b/gpackages/apps/packages/forms.py
index 4784e23..d63751a 100644
--- a/gpackages/apps/packages/forms.py
+++ b/gpackages/apps/packages/forms.py
@@ -37,9 +37,12 @@ def get_all_choices():
     return values
 
 class FilteringForm(forms.Form):
+    names = ['repos', 'categories', 'herds', 'uses', 'licenses']
+    f_names = ['repo', 'category', 'herd', 'use', 'license']
+
     def __init__(self, *args, **kwargs):
         super(FilteringForm, self).__init__(*args, **kwargs)
-        names = ['repos', 'categories', 'herds', 'uses', 'licenses']
+        names = self.names
         names_cache = map(lambda x: x+'_f_list', names)
         cache_vals = cache.get_many(names_cache)
         f = False

diff --git a/gpackages/apps/packages/templatetags/packages.py b/gpackages/apps/packages/templatetags/packages.py
index 093c186..da277d9 100644
--- a/gpackages/apps/packages/templatetags/packages.py
+++ b/gpackages/apps/packages/templatetags/packages.py
@@ -62,7 +62,17 @@ def arch_choice_modal(context):
     return {'form': ArchChoiceForm(initial = {'arches': arches_s}),
             'arches': arches_s}
 
-@register.inclusion_tag('filtering_modal.html')
-def filtering_modal():
-    form = FilteringForm()
+@register.inclusion_tag('filtering_modal.html', takes_context = True)
+def filtering_modal(context):
+    filters = context.get('filters_dict')
+    initial = {}
+    if filters:
+        for item, k in zip(FilteringForm.names, FilteringForm.f_names):
+            if k in filters:
+                v = filters[k]
+                if not isinstance(v, list):
+                    v = [v]
+                initial[item] = v
+
+    form = FilteringForm(initial = initial)
     return {'form': form }



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/templatetags/, ...
@ 2012-07-30 23:30 Slava Bacherikov
  0 siblings, 0 replies; 8+ messages in thread
From: Slava Bacherikov @ 2012-07-30 23:30 UTC (permalink / raw
  To: gentoo-commits

commit:     e2729e6cbb3e938bc676d844a7be27ee16970966
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon Jul 30 23:30:11 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon Jul 30 23:30:11 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=e2729e6c

Add extra data to package view

---
 gpackages/apps/packages/models.py                |    3 +++
 gpackages/apps/packages/templatetags/packages.py |    9 ++++++++-
 gpackages/templates/package.html                 |   20 +++++++++++++++++---
 gpackages/templates/packages_use_flag.html       |   21 +++++++++++++++++++++
 4 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index 238e864..7207ad9 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -687,6 +687,9 @@ class EbuildModel(AbstractDateTimeModel):
             l.append(ko)
         self.keyword_set.add(*l)
 
+    def use_flags_with_descr(self):
+        return self.use_flags.all().prefetch_package_descr(self.package)
+
     @property
     def cp(self):
         return self.package.cp

diff --git a/gpackages/apps/packages/templatetags/packages.py b/gpackages/apps/packages/templatetags/packages.py
index 764f5ab..5f0f3f0 100644
--- a/gpackages/apps/packages/templatetags/packages.py
+++ b/gpackages/apps/packages/templatetags/packages.py
@@ -5,7 +5,7 @@ from package_info.generic_metadata.changelog_highlight import changelog_highligh
 
 register = template.Library()
 
-from ..models import RepositoryModel, EbuildModel
+from ..models import RepositoryModel, EbuildModel, UseFlagDescriptionModel
 from ..views import arches
 from ..forms import ArchChoiceForm, FilteringForm
 from generic.utils import inclusion_cached_tag
@@ -81,3 +81,10 @@ def filtering_modal(context):
 
     form = FilteringForm(initial = initial)
     return {'form': form }
+
+@register.inclusion_tag('packages_use_flag.html')
+def use_flag_table(package):
+    if package.latest_ebuild:
+        use_flags = package.latest_ebuild.use_flags_with_descr()
+
+    return {'use_flags': use_flags}

diff --git a/gpackages/templates/package.html b/gpackages/templates/package.html
index fcc03e3..2b6760c 100644
--- a/gpackages/templates/package.html
+++ b/gpackages/templates/package.html
@@ -3,8 +3,22 @@
 
 {% block content %}
     {% include 'package_object.html' %}
-    <div class="changelog">
-    <h4>Changelog</h4>
-    {{ package.changelog|changelog_highlight }}
+    <div class="tabbable">
+    <ul class="nav nav-tabs">
+      <li class="active"><a href="#tab1" data-toggle="tab">Changelog</a></li>
+      <li><a href="#tab2" data-toggle="tab">Use flags</a></li>
+      <li><a href="#tab3" data-toggle="tab">Licenses</a></li>
+    </ul>
+    <div class="tab-content">
+        <div class="tab-pane active" id="tab1">
+            {{ package.changelog|changelog_highlight }}
+        </div>
+        <div class="tab-pane" id="tab2">
+            {% use_flag_table package %}
+        </div>
+        <div class="tab-pane" id="tab3">
+            {{ package.latest_ebuild.license }}
+        </div>
+    </div>
     </div>
 {% endblock content %}

diff --git a/gpackages/templates/packages_use_flag.html b/gpackages/templates/packages_use_flag.html
new file mode 100644
index 0000000..103e51a
--- /dev/null
+++ b/gpackages/templates/packages_use_flag.html
@@ -0,0 +1,21 @@
+{% load url from future %}
+<table class='table table-striped table-hover'>
+    <colgroup>
+        <col class="span1" >
+        <col class="span8" >
+    </colgroup>
+    <thead>
+            <tr>
+                <th>Use flag</th>
+                <th>Description</th>
+            </tr>
+    </thead>
+    <tbody>
+        {% for use_flag in use_flags %}
+        <tr>
+            <td><a href="{% url 'packages' use=use_flag.name %}">{{ use_flag.name }}</a></td>
+            <td>{{ use_flag.descr|urlize }}</td>
+        </tr>
+        {% endfor %}
+    </tbody>
+</table>


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/templatetags/, ...
@ 2012-07-31 14:22 Slava Bacherikov
  0 siblings, 0 replies; 8+ messages in thread
From: Slava Bacherikov @ 2012-07-31 14:22 UTC (permalink / raw
  To: gentoo-commits

commit:     945c8a65ae75bb0a206d17adcddf35aa9ab9eb17
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jul 31 12:24:02 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jul 31 12:24:02 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=945c8a65

Cache data in package view

---
 gpackages/apps/packages/models.py                |   12 ++++++++++++
 gpackages/apps/packages/templatetags/packages.py |    9 ++++++++-
 gpackages/templates/package.html                 |    2 +-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index 7207ad9..5cf2b03 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -16,6 +16,9 @@ from package_info.validators import validate_url, validate_email, \
 from package_info.parse_cp import VersionParse
 
 from django.utils.html import urlize, linebreaks
+from package_info.generic_metadata.changelog_highlight import changelog_highlight
+from django.utils.safestring import mark_safe
+from django.core.cache import cache
 
 
 def simple_markup(value):
@@ -456,6 +459,15 @@ class PackageModel(StatsModel, AbstractDateTimeModel):
     def short_description(self):
         return self.latest_ebuild.description
 
+    @property
+    def highlighted_changelog(self):
+        key = 'changelog_package_' + str(self.pk)
+        c = cache.get(key)
+        if c is None:
+            c = mark_safe(changelog_highlight(self.changelog))
+            cache.set(key, c)
+        return c
+
     def init_by_package(self, package, category = None, virtual_package = None):
         #self.name = package.name
         self.update_info(package)

diff --git a/gpackages/apps/packages/templatetags/packages.py b/gpackages/apps/packages/templatetags/packages.py
index 5f0f3f0..820daaf 100644
--- a/gpackages/apps/packages/templatetags/packages.py
+++ b/gpackages/apps/packages/templatetags/packages.py
@@ -82,7 +82,14 @@ def filtering_modal(context):
     form = FilteringForm(initial = initial)
     return {'form': form }
 
-@register.inclusion_tag('packages_use_flag.html')
+def use_flag_table_key(package):
+    if package.latest_ebuild:
+        return 'use_flag_table_ebuild' + str(package.latest_ebuild.pk)
+    else:
+        return 'use_flag_table_package' + str(package.pk)
+
+@inclusion_cached_tag('packages_use_flag.html', register, use_flag_table_key,
+                                                        time_zone = False)
 def use_flag_table(package):
     if package.latest_ebuild:
         use_flags = package.latest_ebuild.use_flags_with_descr()

diff --git a/gpackages/templates/package.html b/gpackages/templates/package.html
index 2b6760c..00f1191 100644
--- a/gpackages/templates/package.html
+++ b/gpackages/templates/package.html
@@ -11,7 +11,7 @@
     </ul>
     <div class="tab-content">
         <div class="tab-pane active" id="tab1">
-            {{ package.changelog|changelog_highlight }}
+            {{ package.highlighted_changelog }}
         </div>
         <div class="tab-pane" id="tab2">
             {% use_flag_table package %}


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/templatetags/, ...
@ 2012-07-31 14:22 Slava Bacherikov
  0 siblings, 0 replies; 8+ messages in thread
From: Slava Bacherikov @ 2012-07-31 14:22 UTC (permalink / raw
  To: gentoo-commits

commit:     61701beabd3f081ab54d04c4e61aa538fcc76441
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jul 31 13:56:05 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jul 31 13:56:05 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=61701bea

Add urlize license text

---
 gpackages/apps/packages/templatetags/packages.py |    2 +
 gpackages/apps/packages/utils.py                 |   40 ++++++++++++++++++++++
 gpackages/templates/package.html                 |    2 +-
 3 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/gpackages/apps/packages/templatetags/packages.py b/gpackages/apps/packages/templatetags/packages.py
index 820daaf..4839dfa 100644
--- a/gpackages/apps/packages/templatetags/packages.py
+++ b/gpackages/apps/packages/templatetags/packages.py
@@ -8,6 +8,7 @@ register = template.Library()
 from ..models import RepositoryModel, EbuildModel, UseFlagDescriptionModel
 from ..views import arches
 from ..forms import ArchChoiceForm, FilteringForm
+from ..utils import license_urlize
 from generic.utils import inclusion_cached_tag
 
 def last_updated_key():
@@ -45,6 +46,7 @@ def changelog_highlight_filter(text):
     return mark_safe(changelog_highlight(text))
 
 register.filter('obfuscate', text_sincode)
+register.filter('license_urlize', license_urlize)
 
 def recent_ebuilds_cache_key(num = 10):
     return 'recent_ebuilds_th_' + str(num)

diff --git a/gpackages/apps/packages/utils.py b/gpackages/apps/packages/utils.py
index 25150c2..c0ffbee 100644
--- a/gpackages/apps/packages/utils.py
+++ b/gpackages/apps/packages/utils.py
@@ -1,4 +1,13 @@
 from package_info.generic import ToStrMixin
+from django.utils.html import escape
+from django.utils.safestring import mark_safe
+from django.core.urlresolvers import reverse
+from django.core.urlresolvers import NoReverseMatch
+import re
+LICENSE_STR_RE = r'[a-zA-Z0-9_\-\+\.]+'
+USE_FLAG_RE = r'[a-zA-Z0-9]+\?'
+license_re = re.compile(LICENSE_STR_RE)
+use_re = re.compile(USE_FLAG_RE)
 
 def gen_args(args):
     t = '%s=%s'
@@ -10,3 +19,34 @@ def get_link(host, script, args):
                                                    'script': script,
                                                    'args': get_args(args)}
 
+def license_tokenize(license_str):
+    s, l = 0, len(license_str)
+    while s<l:
+        m = use_re.match(license_str, s)
+        if m is not None:
+            yield ('use', m.group())
+            s = m.end()
+            continue
+        m = license_re.match(license_str, s)
+        if m is not None:
+            yield ('license', m.group())
+            s = m.end()
+            continue
+        
+        yield (None, license_str[s])
+        s += 1
+
+def license_urlize(license_str):
+    res_str = u''
+    for token, value in license_tokenize(license_str):
+        value = escape(value)
+        if token == 'license':
+            try:
+                link = reverse('license', kwargs = {'slug': value})
+            except NoReverseMatch:
+                pass
+            else:
+                value = mark_safe('<a href="{1}">{0}</a>'.format(value, link))
+
+        res_str += value
+    return mark_safe(res_str)

diff --git a/gpackages/templates/package.html b/gpackages/templates/package.html
index 00f1191..d1d4640 100644
--- a/gpackages/templates/package.html
+++ b/gpackages/templates/package.html
@@ -17,7 +17,7 @@
             {% use_flag_table package %}
         </div>
         <div class="tab-pane" id="tab3">
-            {{ package.latest_ebuild.license }}
+            {{ package.latest_ebuild.license|license_urlize }}
         </div>
     </div>
     </div>


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/templatetags/, ...
@ 2012-08-02 22:44 Slava Bacherikov
  0 siblings, 0 replies; 8+ messages in thread
From: Slava Bacherikov @ 2012-08-02 22:44 UTC (permalink / raw
  To: gentoo-commits

commit:     4b711746de61ce9d808d265a55aad129675ba64f
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Thu Aug  2 12:49:30 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Thu Aug  2 12:49:30 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=4b711746

Success url in arches choice will be current page

---
 gpackages/apps/packages/forms.py                 |    1 +
 gpackages/apps/packages/templatetags/packages.py |    4 ++--
 gpackages/apps/packages/views.py                 |    9 +++++++++
 gpackages/templates/arch_choice.html             |    1 +
 gpackages/templates/arch_choice_modal.html       |    1 +
 5 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gpackages/apps/packages/forms.py b/gpackages/apps/packages/forms.py
index d63751a..3bc07df 100644
--- a/gpackages/apps/packages/forms.py
+++ b/gpackages/apps/packages/forms.py
@@ -13,6 +13,7 @@ class ArchChoiceForm(forms.Form):
             widget = DivCheckboxSelectMultiple,
             #widget = forms.CheckboxSelectMultiple(attrs = {'class': 'inline checkbox'}),
             choices = arches)
+    next = forms.CharField(widget = forms.HiddenInput, initial = '/')
 
 def get_all_choices():
     repos = RepositoryModel.objects.all().order_by('name'). \

diff --git a/gpackages/apps/packages/templatetags/packages.py b/gpackages/apps/packages/templatetags/packages.py
index 5f3f966..77e0f65 100644
--- a/gpackages/apps/packages/templatetags/packages.py
+++ b/gpackages/apps/packages/templatetags/packages.py
@@ -66,8 +66,8 @@ def arch_choice_modal(context):
     request = context['request']
     arches_s = request.session.get('arches')
     arches_s = arches_s or arches
-    return {'form': ArchChoiceForm(initial = {'arches': arches_s}),
-            'arches': arches_s}
+    initial = {'arches': arches_s, 'next' : request.path}
+    return {'form': ArchChoiceForm(initial = initial), 'arches': arches_s}
 
 @register.inclusion_tag('filtering_modal.html', takes_context = True)
 def filtering_modal(context):

diff --git a/gpackages/apps/packages/views.py b/gpackages/apps/packages/views.py
index b6ddb97..4a5d509 100644
--- a/gpackages/apps/packages/views.py
+++ b/gpackages/apps/packages/views.py
@@ -219,15 +219,24 @@ class ArchChoiceView(ContextView, ArchesViewMixin, FormView):
     extra_context = {'page_name': 'Select arches', 
                      'default_arches': arches}
 
+    def __init__(self, *args, **kwargs):
+        super(ArchChoiceView, self).__init__(*args, **kwargs)
+        self.next_url = None
+
     def get_initial(self):
         arches = self.get_arches()
         return {'arches': arches }
 
+    def get_success_url(self):
+        val = super(ArchChoiceView, self).get_success_url()
+        return  self.next_url or val
+
     def form_valid(self, form):
         arches = sorted(form.cleaned_data['arches'])
         # Maybe save it to cookies ?
         # arches_str = ','.join(arches)
         self.request.session['arches'] = arches
+        self.next_url = form.cleaned_data['next']
         return super(ArchChoiceView, self).form_valid(form)
 
 class FilteringView(FormView):

diff --git a/gpackages/templates/arch_choice.html b/gpackages/templates/arch_choice.html
index d55c96e..1fc8403 100644
--- a/gpackages/templates/arch_choice.html
+++ b/gpackages/templates/arch_choice.html
@@ -15,6 +15,7 @@
 </script>
 <div class="arches">
 <form action="./" method="post" enctype="multipart/form-data">{% csrf_token %}
+{{ form.next }}
 <fieldset>
     <div class="control-group">
         {% if form.arches.errors %}

diff --git a/gpackages/templates/arch_choice_modal.html b/gpackages/templates/arch_choice_modal.html
index 0f236ee..2785415 100644
--- a/gpackages/templates/arch_choice_modal.html
+++ b/gpackages/templates/arch_choice_modal.html
@@ -18,6 +18,7 @@
     </div>
     <form action="{% url 'archchoice' %}" method="post" enctype="multipart/form-data">
     {% csrf_token %}
+    {{ form.next }}
     <div class="arches modal-body">
         <fieldset>
             {{ form.arches }}


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-08-02 22:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-02 22:44 [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/templatetags/, Slava Bacherikov
  -- strict thread matches above, loose matches on Subject: below --
2012-07-31 14:22 Slava Bacherikov
2012-07-31 14:22 Slava Bacherikov
2012-07-30 23:30 Slava Bacherikov
2012-07-18 23:03 Slava Bacherikov
2012-06-28 23:59 Slava Bacherikov
2012-06-27 22:52 Slava Bacherikov
2012-06-15 23:28 Slava Bacherikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox