Permalink
Browse files

linitification

  • Loading branch information...
1 parent fc30097 commit 944510f7588eb326cc97837f5a2669d3a85bcabc @pydanny pydanny committed Aug 27, 2012
Showing with 85 additions and 86 deletions.
  1. +53 −52 searchv2/builders.py
  2. +3 −2 searchv2/forms.py
  3. +23 −26 searchv2/models.py
  4. +6 −6 searchv2/urls.py
View
@@ -5,103 +5,104 @@
import requests
from grid.models import Grid
-from package.models import Package, Commit, Version
+from package.models import Package, Commit
from searchv2.models import SearchV2
from searchv2.utils import remove_prefix, clean_title
+
def build_1(print_out=True):
-
+
now = datetime.now()
- quarter_delta = timedelta(90)
- half_year_delta = timedelta(182)
+ quarter_delta = timedelta(90)
+ half_year_delta = timedelta(182)
year_delta = timedelta(365)
last_week = now - timedelta(7)
-
+
SearchV2.objects.filter(created__lte=last_week).delete()
for package in Package.objects.filter():
-
+
obj, created = SearchV2.objects.get_or_create(
item_type="package",
slug=package.slug,
)
- obj.slug_no_prefix=remove_prefix(package.slug)
- obj.clean_title=clean_title(remove_prefix(package.slug))
- obj.title=package.title
- obj.title_no_prefix=remove_prefix(package.title)
- obj.description=package.repo_description
- obj.category=package.category.title
- obj.absolute_url=package.get_absolute_url()
- obj.repo_watchers=package.repo_watchers
- obj.repo_forks=package.repo_forks
- obj.pypi_downloads=package.pypi_downloads
- obj.usage=package.usage.count()
- obj.participants=package.participants
-
+ obj.slug_no_prefix = remove_prefix(package.slug)
+ obj.clean_title = clean_title(remove_prefix(package.slug))
+ obj.title = package.title
+ obj.title_no_prefix = remove_prefix(package.title)
+ obj.description = package.repo_description
+ obj.category = package.category.title
+ obj.absolute_url = package.get_absolute_url()
+ obj.repo_watchers = package.repo_watchers
+ obj.repo_forks = package.repo_forks
+ obj.pypi_downloads = package.pypi_downloads
+ obj.usage = package.usage.count()
+ obj.participants = package.participants
+
optional_save = False
try:
- obj.last_committed=package.last_updated
+ obj.last_committed = package.last_updated
optional_save = True
except Commit.DoesNotExist:
pass
-
- last_released=package.last_released
+
+ last_released = package.last_released
if last_released and last_released.upload_time:
- obj.last_released=last_released.upload_time
+ obj.last_released = last_released.upload_time
optional_save = True
-
+
if optional_save:
obj.save()
-
+
# Weighting part
# Weighting part
# Weighting part
weight = 0
optional_save = False
-
+
# Read the docs!
rtfd_url = "http://readthedocs.org/api/v1/build/{0}/".format(obj.slug)
r = requests.get(rtfd_url)
if r.status_code == 200:
data = simplejson.loads(r.content)
if data['meta']['total_count']:
weight += 20
-
+
if obj.description.strip():
weight += 20
-
+
if obj.repo_watchers:
weight += min(obj.repo_watchers, 20)
if obj.repo_forks:
weight += min(obj.repo_forks, 20)
-
+
if obj.pypi_downloads:
weight += min(obj.pypi_downloads / 1000, 20)
if obj.usage:
weight += min(obj.usage, 20)
-
+
# Is there ongoing work or is this forgotten?
if obj.last_committed:
- if now - obj.last_committed < quarter_delta:
+ if now - obj.last_committed < quarter_delta:
weight += 20
elif now - obj.last_committed < half_year_delta:
weight += 10
- elif now - obj.last_committed < year_delta:
+ elif now - obj.last_committed < year_delta:
weight += 5
-
+
# Is the last release less than a year old?
if obj.last_released:
if now - obj.last_released < year_delta:
- weight += 20
+ weight += 20
if weight:
obj.weight = weight
obj.save()
-
+
if print_out:
print >> stdout, obj, created
-
+
print >> stdout, '----------------------'
max_weight = SearchV2.objects.all()[0].weight
increment = max_weight / 6
@@ -110,27 +111,27 @@ def build_1(print_out=True):
item_type="grid",
slug=grid.slug,
)
- obj.slug_no_prefix=remove_prefix(grid.slug)
- obj.clean_title=clean_title(remove_prefix(grid.slug))
- obj.title=grid.title
- obj.title_no_prefix=remove_prefix(grid.title)
- obj.description=grid.description
- obj.absolute_url=grid.get_absolute_url()
-
+ obj.slug_no_prefix = remove_prefix(grid.slug)
+ obj.clean_title = clean_title(remove_prefix(grid.slug))
+ obj.title = grid.title
+ obj.title_no_prefix = remove_prefix(grid.title)
+ obj.description = grid.description
+ obj.absolute_url = grid.get_absolute_url()
+
weight = max_weight - increment
-
+
if not grid.is_locked:
weight -= increment
-
+
if not grid.header:
weight -= increment
-
+
if not grid.packages.count():
weight -= increment
-
+
obj.weight = weight
- obj.save()
-
- print >> stdout, obj, created
-
- return SearchV2.objects.all()
+ obj.save()
+
+ print >> stdout, obj, created
+
+ return SearchV2.objects.all()
View
@@ -1,6 +1,7 @@
from django import forms
+
class SearchForm(forms.Form):
""" Simple q based search form """
-
- q = forms.CharField(label="Search Packages", max_length=100)
+
+ q = forms.CharField(label="Search Packages", max_length=100)
View
@@ -3,17 +3,16 @@
from core.models import BaseModel
-
ITEM_TYPE_CHOICES = (
('package', 'Package'),
- ('grid', 'Grid'),
-
+ ('grid', 'Grid'),
)
+
class SearchV2(BaseModel):
"""
Searches available on:
-
+
title
description
grids
@@ -24,35 +23,33 @@ class SearchV2(BaseModel):
last repo commit
last release on PyPI
"""
-
- weight = models.IntegerField(_("Weight"), default=0)
- item_type = models.CharField(_("Item Type"), max_length=40, choices=ITEM_TYPE_CHOICES)
- title = models.CharField(_("Title"), max_length="100")
+
+ weight = models.IntegerField(_("Weight"), default=0)
+ item_type = models.CharField(_("Item Type"), max_length=40, choices=ITEM_TYPE_CHOICES)
+ title = models.CharField(_("Title"), max_length="100")
title_no_prefix = models.CharField(_("No Prefix Title"), max_length="100")
- slug = models.SlugField(_("Slug"))
- slug_no_prefix = models.SlugField(_("No Prefix Slug"))
- clean_title = models.CharField(_("Clean title with no crud"), max_length="100")
- description = models.TextField(_("Repo Description"), blank=True)
- category = models.CharField(_("Category"), blank=True, max_length=50)
- absolute_url = models.CharField(_("Absolute URL"), max_length="255")
- repo_watchers = models.IntegerField(_("repo watchers"), default=0)
- repo_forks = models.IntegerField(_("repo forks"), default=0)
- pypi_downloads = models.IntegerField(_("Pypi downloads"), default=0)
- usage = models.IntegerField(_("Number of users"), default=0)
- participants = models.TextField(_("Participants"),
+ slug = models.SlugField(_("Slug"))
+ slug_no_prefix = models.SlugField(_("No Prefix Slug"))
+ clean_title = models.CharField(_("Clean title with no crud"), max_length="100")
+ description = models.TextField(_("Repo Description"), blank=True)
+ category = models.CharField(_("Category"), blank=True, max_length=50)
+ absolute_url = models.CharField(_("Absolute URL"), max_length="255")
+ repo_watchers = models.IntegerField(_("repo watchers"), default=0)
+ repo_forks = models.IntegerField(_("repo forks"), default=0)
+ pypi_downloads = models.IntegerField(_("Pypi downloads"), default=0)
+ usage = models.IntegerField(_("Number of users"), default=0)
+ participants = models.TextField(_("Participants"),
help_text="List of collaborats/participants on the project", blank=True)
- last_committed = models.DateTimeField(_("Last commit"), blank=True, null=True)
- last_released = models.DateTimeField(_("Last release"), blank=True, null=True)
-
+ last_committed = models.DateTimeField(_("Last commit"), blank=True, null=True)
+ last_released = models.DateTimeField(_("Last release"), blank=True, null=True)
+
class Meta:
- ordering = ['-weight',]
+ ordering = ['-weight', ]
verbose_name_plural = 'SearchV2s'
def __unicode__(self):
return "{0}:{1}".format(self.weight, self.title)
-
+
@models.permalink
def get_absolute_url(self):
return self.absolute_url
-
-
View
@@ -8,18 +8,18 @@
regex = '^build$',
view = views.build_search,
name = 'build_search',
- ),
-
+ ),
+
url(
regex = '^$',
view = views.search,
name = 'search',
- ),
-
+ ),
+
url(
regex = '^packages/autocomplete/$',
view = views.search_packages_autocomplete,
name = 'search_packages_autocomplete',
- ),
+ ),
-)
+)

0 comments on commit 944510f

Please sign in to comment.