--- a/web/hdabo/admin.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/admin.py Sat Jun 11 03:19:12 2011 +0200
@@ -1,6 +1,7 @@
from django.contrib import admin
+from hdabo.models import (Author, Datasheet, DocumentFormat, Domain, Organisation,
+ Tag, TagCategory, TaggedSheet, TimePeriod)
-from hdabo.models import Author,Datasheet,DocumentFormat,Domain,Organisation,Tag,TagCategory,TaggedSheet,TimePeriod
admin.site.register(Author)
admin.site.register(Datasheet)
--- a/web/hdabo/fields.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/fields.py Sat Jun 11 03:19:12 2011 +0200
@@ -39,7 +39,7 @@
for obj in objs:
if isinstance(obj, self.model):
if not router.allow_relation(obj, self.instance):
- raise ValueError('Cannot add "%r": instance is on database "%s", value is on database "%s"' %
+ raise ValueError('Cannot add "%r": instance is on database "%s", value is on database "%s"' %
(obj, self.instance._state.db, obj._state.db))
new_ids.add(obj.pk)
elif isinstance(obj, Model):
@@ -86,7 +86,7 @@
# Dynamically create a class that subclasses the related
# model's default manager.
- rel_model=self.field.rel.to
+ rel_model = self.field.rel.to
superclass = rel_model._default_manager.__class__
RelatedManager = create_sorted_many_related_manager(superclass, self.field.rel)
--- a/web/hdabo/manage.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/manage.py Sat Jun 11 03:19:12 2011 +0200
@@ -1,6 +1,7 @@
#!/usr/bin/env python
from django.core.management import execute_manager
import imp
+import settings
try:
imp.find_module('settings') # Assumed to be in the same directory.
except ImportError:
@@ -8,7 +9,6 @@
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
sys.exit(1)
-import settings
if __name__ == "__main__":
execute_manager(settings)
--- a/web/hdabo/management/commands/importcsv.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/management/commands/importcsv.py Sat Jun 11 03:19:12 2011 +0200
@@ -70,14 +70,14 @@
def show_progress(self, current_line, total_line, width):
- percent = (float(current_line)/float(total_line))*100.0
+ percent = (float(current_line) / float(total_line)) * 100.0
marks = math.floor(width * (percent / 100.0))
spaces = math.floor(width - marks)
loader = '[' + ('=' * int(marks)) + (' ' * int(spaces)) + ']'
- sys.stdout.write("%s %d%% %d/%d\r" % (loader, percent, current_line-1, total_line-1)) #takes the header into account
+ sys.stdout.write("%s %d%% %d/%d\r" % (loader, percent, current_line - 1, total_line - 1)) #takes the header into account
if percent >= 100:
sys.stdout.write("\n")
sys.stdout.flush()
@@ -98,7 +98,7 @@
return res_list
for label_str in [dstr.strip() for dstr in row_value.split('\x0b')]:
if label_str:
- res_obj, created = klass.objects.get_or_create(label=label_str, school_period=school_period, defaults={"label":label_str,"school_period":school_period}) #@UnusedVariable
+ res_obj, created = klass.objects.get_or_create(label=label_str, school_period=school_period, defaults={"label":label_str, "school_period":school_period}) #@UnusedVariable
res_list.append(res_obj)
return res_list
@@ -136,7 +136,7 @@
town_str = row[u"Ville"]
if town_str:
insee_str = row[u'Insee'].strip() if row[u'Insee'] else row[u'Insee']
- if len(insee_str)>5:
+ if len(insee_str) > 5:
insee_str = ""
loc, created = Location.objects.get_or_create(insee=insee_str, defaults={"name": town_str, "insee": insee_str}) #@UnusedVariable
else:
@@ -163,17 +163,17 @@
url = url.strip()
datasheet = Datasheet.objects.create(
- hda_id = row[u"ID"],
- author = author,
- organisation = org,
- title = row[u"Titre"],
- description = row[u"Desc"],
- url = url,
- town = loc,
- format = format,
- original_creation_date = datetime.datetime.strptime(row[u"Datcre"], "%d/%m/%Y").date(),
- original_modification_date = datetime.datetime.strptime(row[u"Datmaj"], "%d/%m/%Y").date(),
- validated = False
+ hda_id=row[u"ID"],
+ author=author,
+ organisation=org,
+ title=row[u"Titre"],
+ description=row[u"Desc"],
+ url=url,
+ town=loc,
+ format=format,
+ original_creation_date=datetime.datetime.strptime(row[u"Datcre"], "%d/%m/%Y").date(),
+ original_modification_date=datetime.datetime.strptime(row[u"Datmaj"], "%d/%m/%Y").date(),
+ validated=False
)
datasheet.save()
@@ -188,29 +188,29 @@
if row[u'Tag']:
- for i,tag in enumerate([t.strip() for t in row[u'Tag'].split(u";")]):
- if len(tag)==0:
+ for i, tag in enumerate([t.strip() for t in row[u'Tag'].split(u";")]):
+ if len(tag) == 0:
continue
tag_label = self.normalize_tag(tag)
tag_objs = Tag.objects.filter(label__iexact=tag_label)
if len(tag_objs) == 0:
- tag_obj = Tag(label=tag_label,original_label=tag)
+ tag_obj = Tag(label=tag_label, original_label=tag)
tag_obj.save()
else:
tag_obj = tag_objs[0]
- tagged_ds = TaggedSheet(datasheet=datasheet, tag=tag_obj, original_order=i+1, order=i+1)
+ tagged_ds = TaggedSheet(datasheet=datasheet, tag=tag_obj, original_order=i + 1, order=i + 1)
tagged_ds.save()
def handle(self, *args, **options):
- if len(args)==0:
+ if len(args) == 0:
raise CommandError("Gives at lat one csv file to import")
self.encoding = options.get('encoding', "latin-1")
- lines = options.get('lines',0)
+ lines = options.get('lines', 0)
self.ignore_existing = options.get('ignore_existing', False)
- fieldnames = options.get('fieldnames',None)
+ fieldnames = options.get('fieldnames', None)
transaction.commit_unless_managed()
transaction.enter_transaction_management()
@@ -224,16 +224,16 @@
# get the number of lines if necessary
if not lines:
- for i,l in enumerate(csv_file): #@UnusedVariable
+ for i, l in enumerate(csv_file): #@UnusedVariable
pass
- total_line = i+1
+ total_line = i + 1
if fieldnames:
total_line = total_line + 1
csv_file.seek(0)
else:
- total_line = lines+1
+ total_line = lines + 1
- dr_kwargs = {'delimiter':options.get('delimiter',";")}
+ dr_kwargs = {'delimiter':options.get('delimiter', ";")}
if fieldnames is not None:
dr_kwargs['fieldnames'] = [f.strip() for f in fieldnames.split(",")]
dialect = options.get('dialect', "excel")
@@ -242,18 +242,18 @@
reader = csv.DictReader(csv_file, **dr_kwargs)
- for j,row in enumerate(reader):
- if lines and j>=lines:
+ for j, row in enumerate(reader):
+ if lines and j >= lines:
break
- line_num = reader.line_num if fieldnames is None else reader.line_num+1
+ line_num = reader.line_num if fieldnames is None else reader.line_num + 1
self.show_progress(line_num, total_line, 60)
- def safe_decode(val,encoding):
+ def safe_decode(val, encoding):
if val:
return val.decode(encoding)
else:
return val
- row = dict([(safe_decode(key,self.encoding), safe_decode(value,self.encoding)) for key, value in row.items()])
+ row = dict([(safe_decode(key, self.encoding), safe_decode(value, self.encoding)) for key, value in row.items()])
self.create_datasheet(row)
transaction.commit()
--- a/web/hdabo/management/commands/ordertags.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/management/commands/ordertags.py Sat Jun 11 03:19:12 2011 +0200
@@ -6,11 +6,11 @@
from django.core.management.base import NoArgsCommand
from django.core.management.color import no_style
+from haystack.constants import DJANGO_ID
+from haystack.query import SearchQuerySet
+from hdabo.models import Datasheet
import math
import sys
-from hdabo.models import Datasheet
-from haystack.query import SearchQuerySet
-from haystack.constants import DJANGO_ID
class Command(NoArgsCommand):
@@ -25,7 +25,7 @@
def show_progress(self, current_line, total_line, width):
- percent = (float(current_line)/float(total_line))*100.0
+ percent = (float(current_line) / float(total_line)) * 100.0
marks = math.floor(width * (percent / 100.0))
spaces = math.floor(width - marks)
@@ -57,18 +57,18 @@
total = Datasheet.objects.all().count()
- for i,ds in enumerate(Datasheet.objects.all()):
- self.show_progress(i+1, total, 60)
+ for i, ds in enumerate(Datasheet.objects.all()):
+ self.show_progress(i + 1, total, 60)
ts_list = []
for ts in ds.taggedsheet_set.all():
- kwargs = {DJANGO_ID+"__exact": unicode(ds.pk)}
+ kwargs = {DJANGO_ID + "__exact": unicode(ds.pk)}
results = SearchQuerySet().filter(title=ts.tag.label).filter_or(description=ts.tag.label).filter(**kwargs)
if len(results) > 0:
ts.index_note = results[0].score
ts.save()
ts_list.append(ts)
ts_list.sort(key=lambda t: (-t.index_note, t.order))
- for i,ts in enumerate(ts_list):
- ts.order = i+1
+ for i, ts in enumerate(ts_list):
+ ts.order = i + 1
ts.save()
-
\ No newline at end of file
+
--- a/web/hdabo/management/commands/querywikipedia.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/management/commands/querywikipedia.py Sat Jun 11 03:19:12 2011 +0200
@@ -41,7 +41,7 @@
action='store',
type='int',
dest='limit',
- default=-1,
+ default= -1,
help='number of tag to process'),
make_option('--start',
action='store',
@@ -58,13 +58,13 @@
return False
- def process_wp_response(self,label,response):
+ def process_wp_response(self, label, response):
query_dict = response['query']
# get page if multiple pages or none -> return Tag.null_result
pages = query_dict.get("pages", {})
- if len(pages) > 1 or len(pages)==0:
+ if len(pages) > 1 or len(pages) == 0:
return None, Tag.TAG_URL_STATUS_DICT["null_result"], None, None
page = pages.values()[0]
@@ -140,7 +140,7 @@
else:
queryset = queryset.order_by("label")
- if limit>=0:
+ if limit >= 0:
queryset = queryset[start:limit]
else:
queryset = queryset[start:]
@@ -149,7 +149,7 @@
if verbosity > 2 :
print "Tag Query is %s" % (queryset.query)
- site = wiki.Wiki(site_url)
+ site = wiki.Wiki(site_url) #@UndefinedVariable
count = queryset.count()
@@ -158,14 +158,14 @@
- for i,tag in enumerate(queryset):
+ for i, tag in enumerate(queryset):
if verbosity > 1:
- print "processing tag %s (%d/%d)" % (tag.label,i+1,count)
+ print "processing tag %s (%d/%d)" % (tag.label, i + 1, count)
else:
- self.show_progress(i+1, count, tag.label, 60)
+ self.show_progress(i + 1, count, tag.label, 60)
params = {'action':'query', 'titles': tag.label, 'prop':'info|categories', 'inprop':'url'}
- wpquery = api.APIRequest(site,params)
+ wpquery = api.APIRequest(site, params) #@UndefinedVariable
response = wpquery.query()
@@ -173,7 +173,7 @@
print "response from query to %s with parameters %s :" % (site_url, repr(params))
print repr(response)
- new_label, status, url, pageid = self.process_wp_response(tag.label,response)
+ new_label, status, url, pageid = self.process_wp_response(tag.label, response)
if new_label is not None:
tag.label = new_label
@@ -187,4 +187,4 @@
tag.save()
-
\ No newline at end of file
+
--- a/web/hdabo/models.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/models.py Sat Jun 11 03:19:12 2011 +0200
@@ -2,8 +2,8 @@
from django.contrib.auth.models import User
from django.db import models
+from hdabo.fields import SortedManyToManyField
from hdabo.utils import Property
-from hdabo.fields import SortedManyToManyField
import datetime
class Organisation(models.Model):
@@ -20,9 +20,9 @@
class TimePeriod(models.Model):
TIME_PERIOD_CHOICES = (
- (1,u'Primaire'),
- (2,u'Collège'),
- (3,u'Lycée'),
+ (1, u'Primaire'),
+ (2, u'Collège'),
+ (3, u'Lycée'),
)
TIME_PERIOD_DICT = {
u'Primaire': 1,
@@ -41,10 +41,10 @@
class Domain(models.Model):
DOMAIN_PERIOD_CHOICES = (
- (0,u'Global'),
- (1,u'Primaire'),
- (2,u'Collège'),
- (3,u'Lycée'),
+ (0, u'Global'),
+ (1, u'Primaire'),
+ (2, u'Collège'),
+ (3, u'Lycée'),
)
DOMAIN_PERIOD_DICT = {
u'Global': 0,
@@ -70,10 +70,10 @@
class Tag(models.Model):
TAG_URL_STATUS_CHOICES = (
- (0,"null_result"),
- (1,"redirection"),
- (2,"homonyme"),
- (3,"match"),
+ (0, "null_result"),
+ (1, "redirection"),
+ (2, "homonyme"),
+ (3, "match"),
)
TAG_URL_STATUS_DICT = {
@@ -111,7 +111,7 @@
insee = models.CharField(max_length=5, unique=True, blank=False, null=False)
def __unicode__(self):
- return unicode("%s : %s"%(self.name, self.insee))
+ return unicode("%s : %s" % (self.name, self.insee))
class Datasheet(models.Model):
hda_id = models.CharField(max_length=512, unique=True, blank=False, null=False)
@@ -275,4 +275,4 @@
categories = models.ManyToManyField(TagCategory)
-
\ No newline at end of file
+
--- a/web/hdabo/search/sites.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/search/sites.py Sat Jun 11 03:19:12 2011 +0200
@@ -4,4 +4,4 @@
@author: ymh
'''
import haystack
-haystack.autodiscover()
\ No newline at end of file
+haystack.autodiscover()
--- a/web/hdabo/search_indexes.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/search_indexes.py Sat Jun 11 03:19:12 2011 +0200
@@ -18,4 +18,4 @@
description = CharField(model_attr='description', indexed=True, stored=True, boost=1.0)
-site.register(Datasheet, DatasheetIndex)
\ No newline at end of file
+site.register(Datasheet, DatasheetIndex)
--- a/web/hdabo/settings.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/settings.py Sat Jun 11 03:19:12 2011 +0200
@@ -12,11 +12,11 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': '', # Or path to database file if using sqlite3.
- 'USER': '', # Not used with sqlite3.
- 'PASSWORD': '', # Not used with sqlite3.
- 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
- 'PORT': '', # Set to empty string for default. Not used with sqlite3.
+ 'NAME': '', # Or path to database file if using sqlite3.
+ 'USER': '', # Not used with sqlite3.
+ 'PASSWORD': '', # Not used with sqlite3.
+ 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
+ 'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
@@ -114,7 +114,7 @@
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
- 'django.contrib.staticfiles',
+ 'django.contrib.staticfiles',
'django.contrib.admin',
'django_extensions',
'haystack',
--- a/web/hdabo/tests/sortedm2mfield.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/tests/sortedm2mfield.py Sat Jun 11 03:19:12 2011 +0200
@@ -142,7 +142,7 @@
self.assertFalse(form.cleaned_data['values'])
def test_sorted_field_input(self):
- form = SortedForm({'values': [4,2,9]})
+ form = SortedForm({'values': [4, 2, 9]})
self.assertTrue(form.is_valid())
self.assertEqual(list(form.cleaned_data['values']), [
self.books[3],
--- a/web/hdabo/urls.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/urls.py Sat Jun 11 03:19:12 2011 +0200
@@ -13,8 +13,8 @@
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
- url(r'^admin/', include(admin.site.urls)),
- url(r'^search/', include('haystack.urls')),
+ url(r'^admin/', include(admin.site.urls)),
+ url(r'^search/', include('haystack.urls')),
url(r'^$', 'hdabo.views.home', name='home'),
url(r'^list/(?P<orga_id>[\w-]+)$', 'hdabo.views.list_for_orga'),
url(r'^list/(?P<orga_id>[\w-]+)/(?P<valid>[\w-]+)/$', 'hdabo.views.list_for_orga'),
--- a/web/hdabo/views.py Fri Jun 10 20:57:45 2011 +0200
+++ b/web/hdabo/views.py Sat Jun 11 03:19:12 2011 +0200
@@ -69,7 +69,7 @@
return render_to_response("partial/list_for_orga.html",
{'datasheets':datasheets, 'orga_name':orga_name,
- 'nb_sheets':nb_sheets,'orga_id':orga_id, 'ordered_tags':ordered_tags,
+ 'nb_sheets':nb_sheets, 'orga_id':orga_id, 'ordered_tags':ordered_tags,
'prev_index':prev_index, 'next_index':next_index, 'last_index':last_index,
'start_index':start_index, 'displayed_index':displayed_index, 'valid':valid},
context_instance=RequestContext(request))
@@ -90,9 +90,9 @@
tag_order = ts.order
# We get the other TaggedSheet that will be moved
if move == "u" :
- other_ts = ordered_tags[tag_pos-1]
+ other_ts = ordered_tags[tag_pos - 1]
elif move == "d" :
- other_ts = ordered_tags[tag_pos+1]
+ other_ts = ordered_tags[tag_pos + 1]
else :
other_ts = None
# We switch the orders