Skip to content

Commit

Permalink
Primo commit: struttura dati di base e interfaccia di amministrazione
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Ferroni committed Feb 10, 2011
0 parents commit 788f1dc
Show file tree
Hide file tree
Showing 29 changed files with 1,951 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
settings.py
db/
1 change: 1 addition & 0 deletions AUTHORS
1 change: 1 addition & 0 deletions INSTALL
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

Empty file added README
Empty file.
Empty file added __init__.py
Empty file.
Empty file added admin/__init__.py
Empty file.
35 changes: 35 additions & 0 deletions admin/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.contrib import admin
from django.db import models

from gasistafelice.base import models as base_models

class GASUserAdmin(admin.ModelAdmin):
list_display = ('__unicode__', 'gas')
fieldsets = ((None,
{ 'fields' : ('gas', ('name', 'surname'), 'uuid')
}),
)

class SupplierOrderAdmin(admin.ModelAdmin):
fieldsets = ((None,
{ 'fields' : ('supplier',
('date_start', 'date_end'),
('delivery_date', 'delivery_place'),
('withdrawal_date', 'withdrawal_place'),
'product_set'
)
}),
)

admin.site.register(base_models.Person)
admin.site.register(base_models.GASUser, GASUserAdmin)
admin.site.register(base_models.GAS)

admin.site.register(base_models.Supplier)
admin.site.register(base_models.Product)
admin.site.register(base_models.ProductCategory)
admin.site.register(base_models.SupplierStock)
admin.site.register(base_models.SupplierStockGAS)
admin.site.register(base_models.SupplierOrder, SupplierOrderAdmin)


23 changes: 23 additions & 0 deletions admin/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""

from django.test import TestCase

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

__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

1 change: 1 addition & 0 deletions admin/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your views here.
Empty file added base/__init__.py
Empty file.
191 changes: 191 additions & 0 deletions base/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
from django.db import models
from django.utils.translation import ugettext, ugettext_lazy as _
from django.contrib.auth.models import User

STATES_LIST = [
('OPEN', _('open')),
('CLOSED', _('closed')),
('PENDING', _('pending')),
('SENT', _('sent')),
('DELIVERED', _('delivered')),
('ULTIMATED', _('ultimated')),
]

ROLES_LIST = [
('NOBODY', _('Nobody')),
('SUPPLIER_REFERRER', _('Supplier referrer')),
('GAS_USER', _('GAS user')),
('GAS_REFERRER_SUPPLIER', _('GAS supplier referrer')),
('GAS_REFERRER_ORDER', _('GAS order referrer')),
('GAS_REFERRER_WITHDRAWAL', _('GAS withdrawal referrer')),
('GAS_REFERRER_DELIVERY', _('GAS delivery referrer')),
('GAS_REFERRER_CASH', _('GAS cash referrer')),
('GAS_REFERRER_TECH', _('GAS technical referrer')),
]
SUPPLIER_FLAVOUR_LIST = [
('COMPANY', _('Company')),
('COOPERATING', _('Cooperating')),
]
MU_CHOICES = [('Km', 'Km')]
ALWAYS_AVAILABLE = 1000000000

class GAS(models.Model):
name = models.CharField(max_length=128)
description = models.TextField(help_text=_("Who are you? What are yours specialties?"))

#TODO: Prevedere qui tutta la parte di configurazione del GAS

class Meta:
verbose_name_plural = _('GAS')

def __unicode__(self):
return self.name


#class GASRoleMap(models.Model):
# """Dobbiamo semplificare l'assegnazione dei ruoli?
# Memorizzare "nome ruolo" -> "gas" -> "ruolo in ROLES_LIST"?
# Questo serve molto a gestire il GAS come lo si e' sempre fatto
# e con la consapevolezza dei ruoli che ci potrebbero essere.
# Alla fine potremmo farne tranquillamente a meno se e' sempre il tecnico
# che abilita il nuovo utente"""
# name = models.CharField(max_length=128, choices=ROLES_LIST, default=ROLES_LIST[0][0])

class Person(models.Model):
uuid = models.CharField(max_length=128, unique=True, blank=True, null=True, help_text=_('Write your social security number here'))
name = models.CharField(max_length=128)
surname = models.CharField(max_length=128)
contact_email = models.EmailField(blank=True)
contact_phone = models.CharField(max_length=128, blank=True)

def __unicode__(self):
return u"%s %s" % (self.name, self.surname)

#class Role(models.Model):
# name = models.CharField(max_length=128, choices=ROLES_LIST, default=ROLES_LIST[0][0])

class GASUser(Person): #, User):
# I ruoli determinano i diritti di accesso e
# quindi possono essere gestiti con i Gruppi
gas = models.ForeignKey(GAS)
#roles = models.ManyToManyField(Role)

# def save(self):
# self.first_name = self.name
# self.last_name = self.last_name
# super(GASUser, self).save()

class Certification(models.Model):
name = models.CharField(max_length=128)
description = models.TextField()

def __unicode__(self):
return self.name

class Supplier(models.Model):
name = models.CharField(max_length=128)
referrers = models.ManyToManyField(Person)
flavour = models.CharField(max_length=128, choices=SUPPLIER_FLAVOUR_LIST, default=SUPPLIER_FLAVOUR_LIST[0][0])
gas_set = models.ManyToManyField(GAS, through='GASSupplierSolidalPact')
cert_set = models.ManyToManyField(Certification)

def __unicode__(self):
return self.name

class GASSupplierSolidalPact(models.Model):
"""Define GAS <-> Supplier relationship agreement"""

gas = models.ForeignKey(GAS)
supplier = models.ForeignKey(Supplier)
date_signed = models.DateField()
minimum_amount = models.PositiveIntegerField(null=True, blank=True)
delivery_cost = models.PositiveIntegerField(null=True, blank=True)
order_deliver_interval = models.TimeField()
price_percent_update = models.FloatField()

class ProductCategory(models.Model):
# Proposal: the name is in the form MAINCATEGORY::SUBCATEGORY
# like sourceforge categories
# Proposta usare solo il nome CATEGORIA::SOTTOCATEGORIA
# Proposta2 ... si potrebbe usare direttamente il nome come PRIMARY KEY della tabella? Utile per ricerche.
name = models.CharField(max_length=128, unique=True, blank=False)

def __unicode__(self):
return self.name

class Product(models.Model):

uuid = models.CharField(max_length=128, unique=True, blank=True, null=True)
producer = models.ForeignKey(Supplier)
category = models.ForeignKey(ProductCategory)
# Fare un riferimento esterno?
mu = models.CharField(max_length=16, choices=MU_CHOICES, default=MU_CHOICES[0][0])
name = models.CharField(max_length=128)
description = models.TextField()

class SupplierStock(models.Model):
# Il prodotto a disposizione del DES

supplier = models.ForeignKey(Supplier)
product = models.ForeignKey(Product)
price = models.FloatField()
amount_available = models.PositiveIntegerField(default=ALWAYS_AVAILABLE)
minimum_amount = models.PositiveIntegerField(null=True, blank=True)
step = models.PositiveSmallIntegerField(null=True, blank=True)

class SupplierStockGAS(models.Model):
# Product as available to GAS
gas = models.ForeignKey(GAS)
supplier_stock = models.ForeignKey(SupplierStock)
minimum_amount = models.PositiveIntegerField(null=True, blank=True)
step = models.PositiveSmallIntegerField(null=True, blank=True)

@property
def supplier(self):
return self.supplier_stock.supplier

@property
def price(self):
# Price is updated by GASSupplierSolidalPact
price_percent_update = self.supplier.gas_set.get(gas=self.gas).price_percent_update
return self.supplier_stock.price*price_percent_update

class Place(models.Model):
name = models.CharField(max_length=128)
description = models.TextField()

#TODO geolocation: use GeoDjango PointField?
lon = models.FloatField()
lat = models.FloatField()


class SupplierOrder(models.Model):

supplier = models.ForeignKey(Supplier)
date_start = models.DateTimeField()
date_end = models.DateTimeField()
# Dove e quando si consegna
delivery_date = models.DateTimeField()
delivery_place = models.ForeignKey(Place, related_name="delivery_for_order_set")
# Quanto ha consegnato
delivery_amount = models.PositiveIntegerField()
# Dove e quando si ritira
withdrawal_date = models.DateTimeField()
withdrawal_place = models.ForeignKey(Place, related_name="withdraw_for_order_set")

status = models.CharField(max_length=32, choices=STATES_LIST)
product_set = models.ManyToManyField(SupplierStock)


#class GasUserOrder(models.Model):
#
# gas_user = models.ForeignKey(GASUser)
# product = models.ForeignKey(Product)
# order_amount = models.PositiveIntegerField()
# withdrawal_amount = models.PositiveIntegerField()
# supplier_order = models.ForeignKey(Supplier)
# status = models.CharField(choices=STATES_LIST)
# date_created = models.DateTimeField()
# date_last_update=models.DateTimeField()
#
#
23 changes: 23 additions & 0 deletions base/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""

from django.test import TestCase

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

__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}

1 change: 1 addition & 0 deletions base/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your views here.
104 changes: 104 additions & 0 deletions default_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Django settings for gasistafelice project.

import os

DEBUG = True
TEMPLATE_DEBUG = DEBUG

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

ADMINS = (
# ('Your Name', '[email protected]'),
)

MANAGERS = ADMINS

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.
}
}

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'

# Make this unique, and don't share it with anybody.
SECRET_KEY = '26lk413y7^-z^t$#u(xh4uv@+##0jh)&_wxzqho655)eux33@k'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'gasistafelice.urls'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
'gasistafelice.base',
'gasistafelice.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',

)

Loading

0 comments on commit 788f1dc

Please sign in to comment.