Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
jbzdak committed Jan 10, 2012
1 parent 9f04cd1 commit c298771
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions hufcemain/models.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from django.db import models

__LICENSE__ = u"""
Expand Down
2 changes: 1 addition & 1 deletion hufcemain/tests.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from django.test import TestCase

__LICENSE__ = u"""
This file is part of Hufrce Program.
Expand Down
Empty file added registry/__init__.py
Empty file.
105 changes: 105 additions & 0 deletions registry/models.py
@@ -0,0 +1,105 @@
# -*- coding: utf-8 -*-

__LICENSE__ = u"""
This file is part of Hufrce Program.
Hufrce Program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Hufrce Program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hufrce Program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Ten plik jest częścią Hufrce Program.
Program Hufce jest wolnym oprogramowaniem; możesz go rozprowadzać dalej
i/lub modyfikować na warunkach Powszechnej Licencji Publicznej GNU,
wydanej przez Fundację Wolnego Oprogramowania - według wersji 2 tej
Licencji lub (według twojego wyboru) którejś z późniejszych wersji.
Niniejszy program rozpowszechniany jest z nadzieją, iż będzie on
użyteczny - jednak BEZ JAKIEJKOLWIEK GWARANCJI, nawet domyślnej
gwarancji PRZYDATNOŚCI HANDLOWEJ albo PRZYDATNOŚCI DO OKREŚLONYCH
ZASTOSOWAŃ. W celu uzyskania bliższych informacji sięgnij do
Powszechnej Licencji Publicznej GNU.
Z pewnością wraz z niniejszym programem otrzymałeś też egzemplarz
Powszechnej Licencji Publicznej GNU (GNU General Public License);
jeśli nie - napisz do Free Software Foundation, Inc., 59 Temple
Place, Fifth Floor, Boston, MA 02110-1301 USA
"""

from django.db import models

# Create your models here.

CHAR_FIELD_MAX_LEN = 250


class RecordHistory(models.Model):
class Meta:
abstract = True
ordering = ('save_date', )

# parent_instance = models.ForeignKey(Meta.registry_parent, blank=False, null=False)
save_date = models.DateField(auto_now_add=True)

def save(self, force_insert=False, force_update=False, using=None):
assert not force_update
force_insert = True
super(RecordHistory, self).save(force_insert, force_update, using)


class Record(models.Model):

registry_child = None

class Meta:
abstract = True

def save(self, force_insert=False, force_update=False, using=None):
if self.pk is not None and not force_update:
old = type(self).objects.get(pk = self.pk)
hist = self.create_history_objecy()
hist.save()
super(Record, self).save(force_insert, force_update, using)

def create_history_objecy(self):
hist = self.registry_child()
hist.parent_instance = self

for field in self._meta.fields:
if not field.primary_key:
setattr(hist, field.name, getattr(self, field.name, None))
return hist


class Srodowisko(models.Model):

name = models.CharField(max_length=CHAR_FIELD_MAX_LEN)

class Troop(models.Model):

name = models.CharField(max_length=CHAR_FIELD_MAX_LEN)

class ScoutBook:
name = models.CharField(max_length=CHAR_FIELD_MAX_LEN)
surname = models.CharField(max_length=CHAR_FIELD_MAX_LEN)
srodowisko = models.ForeignKey('Srodowisko')
troop = models.ForeignKey('Troop')
book_no = models.CharField(max_length=CHAR_FIELD_MAX_LEN)
issue_date = models.DateField(blank=True, null=False)


class ScoutBookHistory(ScoutBook, RecordHistory):
parent_instance = models.ForeignKey("ScoutBookRegistry", blank=False, null=False, related_name='history')


class ScoutBookRegistry(ScoutBook, Record):
registry_child = ScoutBookHistory
77 changes: 77 additions & 0 deletions registry/tests.py
@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-
__LICENSE__ = u"""
This file is part of Hufrce Program.
Hufrce Program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Hufrce Program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hufrce Program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Ten plik jest częścią Hufrce Program.
Program Hufce jest wolnym oprogramowaniem; możesz go rozprowadzać dalej
i/lub modyfikować na warunkach Powszechnej Licencji Publicznej GNU,
wydanej przez Fundację Wolnego Oprogramowania - według wersji 2 tej
Licencji lub (według twojego wyboru) którejś z późniejszych wersji.
Niniejszy program rozpowszechniany jest z nadzieją, iż będzie on
użyteczny - jednak BEZ JAKIEJKOLWIEK GWARANCJI, nawet domyślnej
gwarancji PRZYDATNOŚCI HANDLOWEJ albo PRZYDATNOŚCI DO OKREŚLONYCH
ZASTOSOWAŃ. W celu uzyskania bliższych informacji sięgnij do
Powszechnej Licencji Publicznej GNU.
Z pewnością wraz z niniejszym programem otrzymałeś też egzemplarz
Powszechnej Licencji Publicznej GNU (GNU General Public License);
jeśli nie - napisz do Free Software Foundation, Inc., 59 Temple
Place, Fifth Floor, Boston, MA 02110-1301 USA
"""




from django.test import TestCase

import models

class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)



class RegisteryTest(TestCase):

def create_registry(self):
sb = models.ScoutBookRegistry()
sb.book_no = 'xxx'
sb.name = 'name'
sb.surname = 'surname'
return sb


def testSimpleSave(self):
sb = self.create_registry()
sb.save()

def testSaveHistory(self):
sb = self.create_registry()
sb.save()
sb_new = models.ScoutBookRegistry.objects.get(pk = sb.pk)
self.assertEquals(len(sb_new.history.all()), 0)
sb.save()
self.assertEquals(len(sb_new.history.all()), 1)




1 change: 1 addition & 0 deletions registry/views.py
@@ -0,0 +1 @@
# Create your views here.
Empty file added roles.sql
Empty file.
14 changes: 11 additions & 3 deletions settings.py
Expand Up @@ -48,11 +48,17 @@
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'hufce_dev', # Or path to database file if using sqlite3.
'USER': 'jb', # Not used with sqlite3.
'PASSWORD': 'foo', # Not used with sqlite3.
'USER': 'jb',
'PASSWORD': 'foo',
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '5432', # Set to empty string for default. Not used with sqlite3.
'TEST_NAME' : 'default_test'
},
'default_test' : {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'hufce_test',
}

}

# Local time zone for this installation. Choices can be found here:
Expand Down Expand Up @@ -150,7 +156,9 @@
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'hufce.hufcemain',
'hufcemain',
'registry',
'south'
)

# A sample logging configuration. The only tangible logging
Expand Down

0 comments on commit c298771

Please sign in to comment.