Skip to content
Extraits de code Groupes Projets
Valider 8a819237 rédigé par luxcem's avatar luxcem
Parcourir les fichiers

updates to the last version of django-representatives

parent 2294d01f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
from django.contrib import admin
import representatives.models as models
from memopol_representatives.models import MemopolRepresentative
class EmailInline(admin.TabularInline):
model = models.Email
extra = 0
class WebsiteInline(admin.TabularInline):
model = models.WebSite
extra = 0
class AdressInline(admin.StackedInline):
model = models.Address
extra = 0
class PhoneInline(admin.TabularInline):
model = models.Phone
extra = 0
class MandateInline(admin.StackedInline):
model = models.Mandate
extra = 0
class RepresentativeAdmin(admin.ModelAdmin):
list_display = ('full_name', 'gender', 'birth_place')
search_fields = ('first_name', 'last_name', 'birth_place')
list_filter = ('gender', )
inlines = [
PhoneInline,
EmailInline,
WebsiteInline,
AdressInline,
MandateInline
]
class MandateAdmin(admin.ModelAdmin):
list_display = ('kind', 'name', 'constituency', 'representative')
search_fields = ('kind', 'name')
list_filter = ('kind',)
admin.site.register(MemopolRepresentative, RepresentativeAdmin)
admin.site.register(models.Country)
admin.site.register(models.Mandate, MandateAdmin)
from django.core.management.base import BaseCommand
from django.db import transaction
from memopol.utils import progress_bar
from representatives.models import Representative
from memopol_representatives.models import MemopolRepresentative
class Command(BaseCommand):
@transaction.atomic
def handle(self, *args, **options):
n = Representative.objects.all().count()
for i, representative in enumerate(Representative.objects.all()):
memopol_representative = MemopolRepresentative(representative_ptr=representative)
memopol_representative.__dict__.update(representative.__dict__)
# Auto set active flag of the memopol representative
memopol_representative.update_active()
progress_bar(i, n)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('representatives', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='MemopolRepresentative',
fields=[
('representative_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='representatives.Representative')),
('active', models.BooleanField(default=False)),
],
options={
},
bases=('representatives.representative',),
),
]
from django.db import models
from representatives.models import Representative
class MemopolRepresentative(Representative):
active = models.BooleanField(default=False)
def update_active(self):
if self.mandate_set.filter(end_date="9999-12-31"):
self.active = True
else:
self.active = False
self.save()
......@@ -3,13 +3,10 @@
- block content
.row
.large-8.columns
- for representative in memopolrepresentative_list
%p
= representative.full_name
- for email in representative.email_set.all
%p
= email.email
- for representative in representative_list
.row
- include 'memopol_representatives/representative_block.html'
.large-4.columns
%p
hello
%p.small-2.columns
%img{'src':'={representative.photo}'}/
%p.small-4.columns
= representative.full_name
[ ={representative.country.code} ]
%p.small-6.columns
- for mandate in representative.mandate_set.all
={mandate.group.name} - ={mandate.end_date} - ={mandate.active}
%br/a
# from django.shortcuts import render
from django.views import generic
from memopol_representatives.models import MemopolRepresentative
from representatives.models import Representative
class IndexView(generic.ListView):
template_name = 'memopol_representatives/list.html'
def get_queryset(self):
return MemopolRepresentative.objects.all()
return Representative.objects.all()
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter