Skip to content

Commit

Permalink
speech models added; admin prototyped
Browse files Browse the repository at this point in the history
  • Loading branch information
guglielmo committed Apr 12, 2013
1 parent 3cfd932 commit 0d42627
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 11 deletions.
21 changes: 21 additions & 0 deletions open_municipio/acts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Meta:

return RuntimeTransitionForm


class PresenterInline(admin.TabularInline):
fields = ['charge', 'support_type', 'support_date']
model = ActSupport
Expand All @@ -35,15 +36,18 @@ class ActInline(admin.TabularInline):
model = Act
extra = 0


class AttachInline(admin.StackedInline):
model = Attach
extra = 0


class AmendmentInline(admin.StackedInline):
fk_name = 'act'
model = Amendment
extra = 0


class TransitionInline(admin.TabularInline):
model = Transition
extra = 0
Expand All @@ -58,6 +62,7 @@ def get_formset(self, request, obj=None, **kwargs):
self.form = transition_form_factory(obj)
return super(TransitionInline, self).get_formset(request, obj, **kwargs)


class ActAdmin(admin.ModelAdmin):
search_fields = ('idnum', 'title',)

Expand Down Expand Up @@ -93,12 +98,15 @@ class CalendarAdmin(admin.ModelAdmin):
models.ManyToManyField: {'widget': FilteredSelectMultiple("verbose name", is_stacked=False)},
}


class ActAdminWithAttaches(admin.ModelAdmin):
inlines = [AttachInline, TransitionInline]


class ActAdminWithAmendments(admin.ModelAdmin):
inlines = [AmendmentInline]


class MotionAdmin(ActAdmin):
fieldsets = (
(None, {
Expand All @@ -122,6 +130,7 @@ class InterrogationAdmin(ActAdmin):
}),
)


class DeliberationAdmin(ActAdmin):
fieldsets = (
(None, {
Expand All @@ -137,6 +146,17 @@ class DeliberationAdmin(ActAdmin):
}),
)

class ActInSpeechInline(admin.TabularInline):
model = ActHasSpeech
extra = 0


class SpeechAdmin(admin.ModelAdmin):
search_fields = ('title',)
inlines = [ActInSpeechInline,]
raw_id_fields = ('charge', 'sitting_item', 'votation', )



admin.site.register(Act, ActAdmin)

Expand All @@ -154,3 +174,4 @@ class DeliberationAdmin(ActAdmin):
admin.site.register(Amendment, ActAdminWithAttaches)
admin.site.register(Attach)
admin.site.register(Transition)
admin.site.register(Speech, SpeechAdmin)
49 changes: 47 additions & 2 deletions open_municipio/acts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from open_municipio.newscache.models import News, NewsTargetMixin

from open_municipio.people.models import Institution, InstitutionCharge, Sitting, Person
from open_municipio.people.models import Institution, InstitutionCharge, Person
from open_municipio.taxonomy.managers import TopicableManager
from open_municipio.monitoring.models import MonitorizedItem, Monitoring

Expand Down Expand Up @@ -644,7 +644,52 @@ class Meta(Document.Meta):

def __unicode__(self):
return u'%s' % self.title



#
# Speech
#
class Speech(Document):
"""
A Speech is a special case of Attachment (it extends Document, too), that is connected
to Acts, Votations and Charges and has field to map the audio content
"""
title = models.CharField(max_length=255, blank=True, null=True)
sitting_item = models.ForeignKey('people.SittingItem')
charge = models.ForeignKey('people.InstitutionCharge')
votation = models.ForeignKey('votations.Votation', blank=True, null=True)
related_act_set = models.ManyToManyField('Act', through='ActHasSpeech')
seq_order = models.IntegerField(default=0)
audio_url = models.URLField(blank=True)
audio_file = models.FileField(upload_to="attached_audio/%Y%m%d", blank=True, max_length=255)

class Meta(Document.Meta):
verbose_name = _('speech')
verbose_name_plural = _('speeches')

def __unicode__(self):
return u'%s' % self.title


class ActHasSpeech(models.Model):
"""
Relation between a speech and an act.
A speech can be related to one or more acts.
"""
RELATION_TYPE = Choices(
('REQ', 'request', _('request')),
('RESP', 'response', _('response')),
('REF', 'reference', _('reference')),
)

speech = models.ForeignKey('acts.Speech')
act = models.ForeignKey('acts.Act')
relation_type = models.CharField(choices=RELATION_TYPE, max_length=4)

class Meta(Document.Meta):
verbose_name = _('act mentioned in speech')
verbose_name_plural = _('acts mentioned in speech')


#
# Calendar
Expand Down
40 changes: 35 additions & 5 deletions open_municipio/people/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,35 @@ class PersonResourceInline(admin.TabularInline):
model = PersonResource
extra = 0


class PersonAdminWithResources(AdminImageMixin, admin.ModelAdmin):
list_display = ('id', '__unicode__', 'has_current_charges', 'birth_date', 'birth_location' )
list_display_links = ('__unicode__',)
search_fields = ['^first_name', '^last_name']
prepopulated_fields = {"slug": ("first_name","last_name","birth_date", "birth_location",)}
inlines = [PersonResourceInline, ]


class ChargeAdmin(admin.ModelAdmin):
raw_id_fields = ('person', )


class GroupResourceInline(admin.TabularInline):
model = GroupResource
extra = 0


class GroupChargeInline(admin.TabularInline):
model = GroupCharge
raw_id_fields = ('charge', )
extra = 1


class GroupIsMajorityInline(admin.TabularInline):
model = GroupIsMajority
extra = 1


class GroupAdminWithCharges(AdminImageMixin, admin.ModelAdmin):
prepopulated_fields = {"slug": ("name",)}
list_display = ('name', 'acronym', 'is_majority_now')
Expand All @@ -56,17 +62,21 @@ class ChargeInline(admin.StackedInline):
})
)
extra = 1



class CompanyChargeInline(ChargeInline):
model = CompanyCharge


class AdministrationChargeInline(ChargeInline):
model = AdministrationCharge


class InstitutionResourceInline(admin.TabularInline):
model = InstitutionResource
extra = 0


class InstitutionChargeInline(ChargeInline):
model = InstitutionCharge
raw_id_fields = ('person', 'substitutes', 'substituted_by')
Expand All @@ -85,10 +95,12 @@ class ResponsabilityInline(admin.TabularInline):
raw_id_fields = ('charge',)
extra = 0


class InstitutionResponsabilityInline(ResponsabilityInline):
model = InstitutionResponsability
fields = ('charge', 'charge_type', 'start_date', 'end_date', 'description')


class GroupResponsabilityInline(admin.TabularInline):
model = GroupResponsability
raw_id_fields = ('charge',)
Expand All @@ -98,7 +110,8 @@ class GroupResponsabilityInline(admin.TabularInline):

class ChargeAdmin(admin.ModelAdmin):
pass



class CompanyChargeAdmin(ChargeAdmin):
model = CompanyCharge
raw_id_fields = ('person', 'company')
Expand All @@ -110,6 +123,7 @@ class CompanyChargeAdmin(ChargeAdmin):
}),
)


class AdministrationChargeAdmin(ChargeAdmin):
model = AdministrationCharge
raw_id_fields = ('person', 'office')
Expand All @@ -121,6 +135,7 @@ class AdministrationChargeAdmin(ChargeAdmin):
}),
)


class InstitutionChargeAdmin(ChargeAdmin):
model = InstitutionCharge
raw_id_fields = ('person', 'substitutes', 'substituted_by', 'original_charge')
Expand All @@ -139,6 +154,7 @@ class InstitutionChargeAdmin(ChargeAdmin):
list_filter = ['institution__name']
inlines = [InstitutionResponsabilityInline]


class GroupChargeAdmin(admin.ModelAdmin):
raw_id_fields = ('charge', )
list_display = ('__unicode__', 'start_date', 'end_date')
Expand All @@ -147,12 +163,14 @@ class GroupChargeAdmin(admin.ModelAdmin):
inlines = [GroupResponsabilityInline]



class BodyAdmin(admin.ModelAdmin):
prepopulated_fields = {"slug": ("name",)}


class CompanyAdmin(BodyAdmin):
inlines = [CompanyChargeInline]


class OfficeAdmin(BodyAdmin):
inlines = [AdministrationChargeInline]

Expand Down Expand Up @@ -201,9 +219,21 @@ def move_up_down_links(self, obj):
list_display = ('name', 'institution_type', 'move_up_down_links')


class SittingItemInline(admin.TabularInline):
model = SittingItem
fields = ('title', 'related_act_set', 'item_type', 'seq_order')
raw_id_fields = ['related_act_set',]
extra = 0


class SittingItemAdmin(admin.ModelAdmin):
raw_id_fields = ['related_act_set',]

class SittingAdmin(admin.ModelAdmin):
inlines = [VotationsInline]

inlines = [SittingItemInline, VotationsInline]


admin.site.register(SittingItem, SittingItemAdmin)
admin.site.register(Sitting, SittingAdmin)
admin.site.register(Person, PersonAdminWithResources)
admin.site.register(Group, GroupAdminWithCharges)
Expand Down
53 changes: 49 additions & 4 deletions open_municipio/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django.utils.translation import ugettext_lazy as _
from django.template.defaultfilters import slugify
from django.core.urlresolvers import reverse
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType

from model_utils import Choices
Expand Down Expand Up @@ -1042,20 +1041,27 @@ def charges(self):
associated with this office.
"""
return self.charge_set.current()



#
# Sittings
#
class Sitting(models.Model):
"""
WRITEME
A sitting models a gathering of people in a give institution.
Usually votations and speeches occur, during a sitting.
A sitting is broken down into SittingItems, and each item may be related to one or more acts.
Each item contains Speeches, which are a very special extension of Document
(audio attachments, with complex relations with votations, charges and acts).
"""
idnum = models.CharField(blank=True, max_length=64)
date = models.DateField()
number = models.IntegerField(blank=True, null=True)
call = models.IntegerField(blank=True, null=True)
institution = models.ForeignKey(Institution, on_delete=models.PROTECT)

class Meta:
verbose_name = _('sitting')
verbose_name_plural = _('sittings')
Expand All @@ -1064,6 +1070,45 @@ def __unicode__(self):
return u'seduta num. %s del %s (%s)' % (self.number, self.date.strftime('%d/%m/%Y'), self.institution.name)


class SittingItem(models.Model):
"""
A SittingItem maps a single point of discussion in a Sitting.
It can be of type:
- odg - a true items of discussion
- procedural - a procedural issue, discussed, mostly less relevant
- intt - interrogations and interpellances (questions and answers), usually discussed at the beginning of the sitting
SittingItems are ordered through the seq_order field.
"""

ITEM_TYPE = Choices(
('ODG', 'odg', _('ordine del giorno')),
('PROC', 'procedural', _('questione procedurale')),
('INTT', 'intt', _('interrogation')),
)

sitting = models.ForeignKey(Sitting)
title = models.CharField(max_length=512)
item_type = models.CharField(choices=ITEM_TYPE, max_length=4)
seq_order = models.IntegerField(default=0)
related_act_set = models.ManyToManyField('acts.Act', blank=True, null=True)

class Meta:
verbose_name = _('sitting item')
verbose_name_plural = _('sitting items')

def __unicode__(self):
return unicode(self.title)

@property
def long_repr(self):
"""
long unicode representation, contains the sitting details
"""
return u'%s - %s' % (self.sitting, self)


## Private DB access API

class Mayor(object):
Expand Down

1 comment on commit 0d42627

@guglielmo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I aligned the spaces between the lines according to PEP8 standards (2 lines between classes)

Please sign in to comment.