Permalink
Browse files

elazarg's refactoring - simple changes:

* documentation improvements
* code comments
* removing unused imports
  • Loading branch information...
1 parent f41fef0 commit 29ec6355d90d3c7fc4ba716c746f3aaab586cfa9 @OriHoch OriHoch committed Dec 2, 2013
View
@@ -238,8 +238,7 @@ We use south to manage database migration. The work process looks something like
- ``python manage.py schemamigration sample_app --auto`` this generates a new
migration under `src/knesset/sample_app/migrations`. You should review it to
make sure it does what you expect.
-- ``python manage.py --migrate`` To run un the migration (make the changes on
- the db).
+- ``python manage.py migrate`` To run the migration (make the changes on the db).
- don't forget to git add/commit the migration file.
Updating the translation strings
@@ -2,7 +2,6 @@
from django.core.management.base import NoArgsCommand
from django.db import transaction
-from django.utils.timezone import now
from agendas.models import SummaryAgenda,AgendaVote
@@ -3,7 +3,7 @@
from django.core.management.base import NoArgsCommand
from django.conf import settings
-from mailer import send_html_mail
+from mailer import send_html_mail
from agendas.models import UserSuggestedVote
from django.contrib.auth.models import User
@@ -1,5 +1,4 @@
# encoding: utf-8
-import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
@@ -1,8 +1,6 @@
# encoding: utf-8
-import datetime
from south.db import db
from south.v2 import SchemaMigration
-from django.db import models
class Migration(SchemaMigration):
@@ -1,8 +1,6 @@
# encoding: utf-8
-import datetime
from south.db import db
from south.v2 import SchemaMigration
-from django.db import models
class Migration(SchemaMigration):
@@ -1,8 +1,6 @@
# encoding: utf-8
-import datetime
from south.db import db
from south.v2 import SchemaMigration
-from django.db import models
class Migration(SchemaMigration):
@@ -1,19 +1,15 @@
# encoding: utf-8
-import datetime
from south.db import db
from south.v2 import SchemaMigration
-from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
-
# Adding field 'Agenda.num_followers'
db.add_column('agendas_agenda', 'num_followers', self.gf('django.db.models.fields.IntegerField')(default=0), keep_default=False)
def backwards(self, orm):
-
# Deleting field 'Agenda.num_followers'
db.delete_column('agendas_agenda', 'num_followers')
@@ -1,8 +1,5 @@
# encoding: utf-8
-import datetime
-from south.db import db
from south.v2 import DataMigration
-from django.db import models
class Migration(DataMigration):
@@ -1,8 +1,6 @@
# encoding: utf-8
-import datetime
from south.db import db
from south.v2 import SchemaMigration
-from django.db import models
class Migration(SchemaMigration):
@@ -1,8 +1,6 @@
# encoding: utf-8
-import datetime
from south.db import db
from south.v2 import SchemaMigration
-from django.db import models
class Migration(SchemaMigration):
@@ -1,10 +1,6 @@
# -*- coding: utf-8 -*-
-import datetime
from south.db import db
from south.v2 import SchemaMigration
-from django.db import models
-
-from agendas.models import AgendaVote
class Migration(SchemaMigration):
@@ -1,9 +1,6 @@
# -*- coding: utf-8 -*-
-import datetime
from south.db import db
from south.v2 import SchemaMigration
-from django.db import models
-
class Migration(SchemaMigration):
@@ -16,7 +13,6 @@ def backwards(self, orm):
# Removing index on 'SummaryAgenda', fields ['month']
db.delete_index('agendas_summaryagenda', ['month'])
-
models = {
'agendas.agenda': {
'Meta': {'unique_together': "(('name', 'public_owner_name'),)", 'object_name': 'Agenda'},
@@ -325,4 +321,4 @@ def backwards(self, orm):
}
}
- complete_apps = ['agendas']
+ complete_apps = ['agendas']
View
@@ -5,7 +5,7 @@
from django.contrib.auth.models import User, Group, Permission
from tagging.models import Tag, TaggedItem
from laws.models import Vote, VoteAction, Bill, Law
-from mks.models import Member, Party, WeeklyPresence, Knesset
+from mks.models import Member, Party, Knesset
from agendas.models import Agenda
from committees.models import Committee
from events.models import Event
@@ -96,7 +96,7 @@ run:
.. code-block:: sh
- pip install -r Open-Knesset/requirements.txt
+ pip-2.7 install -r Open-Knesset/requirements.txt
And wait ...
@@ -64,7 +64,6 @@ put in that file:
INTERNAL_IPS = ('127.0.0.1',)
-
Running the Development server
=====================================
View
@@ -107,7 +107,7 @@ A possible session might include:
git pull git@github.com:hasadna/Open-Knesset.git master
cd ..
- pip install -r Open-Knesset/requirements.txt
+ pip-2.7 install -r Open-Knesset/requirements.txt
cd Open-Knesset
./manage.py migrate
@@ -125,3 +125,67 @@ A possible session might include:
make html
popd >/dev/null
}
+
+
+Debugging
+===================================
+During debugging, you can use the Python debugger, pdb_.
+
+Add ``import pbd`` in the code, and ``pdb.set_trace()`` in the line you want to begin debugging from.
+
+Run the server and browse the site as usual. When the code hit the line you set a trace in, the browser will hang, and you will get the pdb shell back:
+
+.. code-block:: bash
+
+ > /home/yourname/workspace/oknesset/Open-Knesset/agendas/models.py(448)get_mks_values()
+ -> summaries_for_ranges = []
+
+ (Pdb)
+
+You can run any python code from there, just like a normal python interpreter, in addition to `control commands`_,
+like ``c`` to continue execution, and ``n`` to step single line.
+
+.. warning::
+
+ The debugger will not work in ``python manage.py``, since the output is blocked. The tests will just hang.
+
+
+.. important::
+
+ Remember to remove any ``set_trace()`` commands from the code before committing.
+
+.. _pdb: http://docs.python.org/2/library/pdb.html
+.. _`control commands`: http://docs.python.org/2/library/pdb.html#debugger-commands
+
+Quicker testing
+===================================
+
+PASSWORD_HASHERS
+~~~~~~~~~~~~~~~~~~
+You may want to add this too to `local_settings.py`, in order to speed up the testing by 25%-30%:
+
+.. code-block:: python
+
+ import sys
+ if 'test' in sys.argv:
+ PASSWORD_HASHERS = (
+ 'django.contrib.auth.hashers.MD5PasswordHasher',
+ )
+
+``--failfast``
+~~~~~~~~~~~~~~~~~~
+if you want the test suite to fail as soon as the first test does, add ``--failfast`` flag:
+
+.. code-block:: sh
+
+ python manage.py test --failfast
+
+alert
+~~~~~~~~~~~~~~~~~~
+In Ubuntu, you can add an ``alert`` after this command:
+
+.. code-block:: sh
+
+ python manage.py test --failfast; alert
+
+This will pop up a notification when the test is finished.
@@ -31,18 +31,18 @@ Enter the `Open-Knesset` directory, and run:
.. code-block:: sh
git pull git@github.com:hasadna/Open-Knesset.git master
-
+
.. note::
Running this command requires having SSH keys registered with github. If you don't have these, or
if you don't understand what this means and do not want to look it up, you can use:
-
+
git pull https://github.com/hasadna/Open-Knesset.git master
If `requirements.txt` was modified, make sure all of them are installed (no harm
running this command even in case of no changes):
- `pip install -r requirements.txt`
+ `pip-2.7 install -r requirements.txt`
.. note::
@@ -51,7 +51,7 @@ running this command even in case of no changes):
packages from git repos. in that case::
- `pip install -r Open-Knesset/requirements.txt`
+ `pip-2.7 install -r Open-Knesset/requirements.txt`
View
@@ -1,6 +1,6 @@
from django.contrib import admin
from models import Link, LinkType
-from django.utils.translation import ugettext_lazy as _, ungettext
+from django.utils.translation import ugettext_lazy as _
def make_active(modeladmin, request, queryset):
queryset.update(active=True)
View
@@ -5,7 +5,7 @@
class KnessetManager(models.Manager):
"""This is a manager for Knesset class"""
-
+
def __init__(self):
super(KnessetManager, self).__init__()
self._current_knesset = None
@@ -15,6 +15,7 @@ def current_knesset(self):
try:
self._current_knesset = self.get_query_set().order_by('-number')[0]
except IndexError:
+ #FIX: should document when and why this should happen
return None
return self._current_knesset
View
@@ -1,4 +1,3 @@
-import re
from StringIO import StringIO
from urllib2 import HTTPError, URLError
from backlinks.pingback.server import default_server
View
@@ -1,6 +1,4 @@
from django.conf.urls import url, patterns
-from django.core.exceptions import ObjectDoesNotExist
-from django.http import HttpResponse, Http404
from mock import mock_reader
from backlinks.pingback.server import PingbackServer
View
@@ -1,6 +1,4 @@
from django.conf.urls import url, patterns
-from django.utils.translation import ugettext
-from models import Person
from views import PersonListView, PersonDetailView
person_list = PersonListView.as_view()

0 comments on commit 29ec635

Please sign in to comment.