Пример #1
0
def finalize_registration(self, user): 
    print("sono dentro FINALIZE_REGISTRATION, prima del check di 'numero_iscrizione'")
    if settings.REGISTRATION_AUTO_ADD_GROUP and user.numero_iscrizione: 
        is_registered_a = (user.register_subscription_date != None) and (user.says_is_psicologo_lavoro or user.says_is_psicologo_clinico or user.says_is_psicologo_forense)
        if is_registered_a:
            i = Institution.objects.get(slug="sezione-a")
            member_charge = InstitutionCharge(person=user.person, institution=i, start_date=user.register_subscription_date)
            member_charge.save()
        if user.says_is_psicologo_lavoro:
            g, created = Group.objects.get_or_create(name=settings.SYSTEM_GROUP_NAMES["psicologo_lavoro"])
            g.user_set.add(user)
        if user.says_is_psicologo_clinico:
            g, created = Group.objects.get_or_create(name=settings.SYSTEM_GROUP_NAMES["psicologo_clinico"])
            g.user_set.add(user)
        if user.says_is_psicologo_forense:
            g, created = Group.objects.get_or_create(name=settings.SYSTEM_GROUP_NAMES["psicologo_forense"])
            g.user_set.add(user)

        is_registered_b = (user.register_subscription_date != None) and (user.says_is_dottore_tecniche_psicologiche)

        if user.says_is_dottore_tecniche_psicologiche:
            g, created = Group.objects.get_or_create(name=settings.SYSTEM_GROUP_NAMES["dottore_tecniche_psicologiche"])
            g.user_set.add(user)
        if is_registered_b: # TODO: check the indentation for this IF
            print "Utente registrato ..."
            i = Institution.objects.get(slug=settings.COMMITTEE_SLUGS["dottore_tecniche_psicologiche"])
            print "test verifica contenuto slug: %s ..." % (settings.COMMITTEE_SLUGS["dottore_tecniche_psicologiche"])
            member_charge = InstitutionCharge(person=user.person, institution=i, start_date=user.register_subscription_date)
            member_charge.save()
        print('registrazione avvenuta')
Пример #2
0
def finalize_registration(self, user):
    print(
        "sono dentro FINALIZE_REGISTRATION, prima del check di 'numero_iscrizione'"
    )
    if settings.REGISTRATION_AUTO_ADD_GROUP and user.numero_iscrizione:
        is_registered_a = (user.register_subscription_date != None) and (
            user.says_is_psicologo_lavoro or user.says_is_psicologo_clinico
            or user.says_is_psicologo_forense)
        if is_registered_a:
            i = Institution.objects.get(slug="sezione-a")
            member_charge = InstitutionCharge(
                person=user.person,
                institution=i,
                start_date=user.register_subscription_date)
            member_charge.save()
        if user.says_is_psicologo_lavoro:
            g, created = Group.objects.get_or_create(
                name=settings.SYSTEM_GROUP_NAMES["psicologo_lavoro"])
            g.user_set.add(user)
        if user.says_is_psicologo_clinico:
            g, created = Group.objects.get_or_create(
                name=settings.SYSTEM_GROUP_NAMES["psicologo_clinico"])
            g.user_set.add(user)
        if user.says_is_psicologo_forense:
            g, created = Group.objects.get_or_create(
                name=settings.SYSTEM_GROUP_NAMES["psicologo_forense"])
            g.user_set.add(user)

        is_registered_b = (user.register_subscription_date != None) and (
            user.says_is_dottore_tecniche_psicologiche)

        if user.says_is_dottore_tecniche_psicologiche:
            g, created = Group.objects.get_or_create(
                name=settings.
                SYSTEM_GROUP_NAMES["dottore_tecniche_psicologiche"])
            g.user_set.add(user)
        if is_registered_b:  # TODO: check the indentation for this IF
            print "Utente registrato ..."
            i = Institution.objects.get(
                slug=settings.COMMITTEE_SLUGS["dottore_tecniche_psicologiche"])
            print "test verifica contenuto slug: %s ..." % (
                settings.COMMITTEE_SLUGS["dottore_tecniche_psicologiche"])
            member_charge = InstitutionCharge(
                person=user.person,
                institution=i,
                start_date=user.register_subscription_date)
            member_charge.save()
        print('registrazione avvenuta')
Пример #3
0
def finalize_registration(self, user): 
    print("sono dentro FINALIZE_REGISTRATION, prima del check di 'numero_iscrizione'")
    print user.numero_iscrizione
    if settings.REGISTRATION_AUTO_ADD_GROUP and user.numero_iscrizione: 
    	print user.says_is_self_employed
        is_registered_a = (user.register_subscription_date != None) and (user.says_is_psicologo_lavoro or user.says_is_psicologo_clinico or user.says_is_psicologo_forense or user.says_is_self_employed)
        print is_registered_a
        #if is_registered_a:
        print "test 1 - inserisco in albo -> is_registered_a"
        i = Institution.objects.get(slug="sezione-a")             	
        print user.register_subscription_date
        #if InstitutionCharge.objects.filter(person__pk=user.person.id).filter(institution=i).count()  == 0:        		
        member_charge = InstitutionCharge(person=user.person, institution=i, start_date=user.register_subscription_date) 
        member_charge.save() 

        if user.says_is_psicologo_lavoro:
            g, created = Group.objects.get_or_create(name=settings.SYSTEM_GROUP_NAMES["psicologo_lavoro"])
            g.user_set.add(user.user)
        if user.says_is_psicologo_clinico:
            g, created = Group.objects.get_or_create(name=settings.SYSTEM_GROUP_NAMES["psicologo_clinico"])
            g.user_set.add(user.user)
        if user.says_is_psicologo_forense:
            g, created = Group.objects.get_or_create(name=settings.SYSTEM_GROUP_NAMES["psicologo_forense"])
            g.user_set.add(user.user)
        if user.says_is_self_employed:
            g, created = Group.objects.get_or_create(name=settings.SYSTEM_GROUP_NAMES["psicologo"])
            l = user.user.groups.values_list('name',flat=True)
            print "l'utente appartene ad un gruppo: %s" % (l)
            #g.user_set.add(user.user)
            check_group_user_exist(g,user)
            

        is_registered_b = (user.register_subscription_date != None) and (user.says_is_dottore_tecniche_psicologiche)
        if is_registered_b: # TODO: check the indentation for this IF
            print "test 1 - inserisco in albo -> is_registered_b"
            i = Institution.objects.get(slug="sezione-b")
            print "denominazione istituzione" % (d)
            if InstitutionCharge.objects.filter(person__pk=user.person.id).filter(institution=i).count()  == 0: 
        	   	member_charge = InstitutionCharge(person=user.person, institution=i, start_date=user.register_subscription_date) 
        	   	member_charge.save() 


        if user.says_is_dottore_tecniche_psicologiche:
            g, created = Group.objects.get_or_create(name=settings.SYSTEM_GROUP_NAMES["dottore_tecniche_psicologiche"])
            g.user_set.add(user.user)
       
       	            
        print('registrazione avvenuta')
Пример #4
0
    def handle_label(self, op_location_id, **options):

        # cleanup
        Person.objects.all().delete()
        InstitutionCharge.objects.all().delete()
        Group.objects.all().delete()

        # build location url and fetch the response in json format
        location_url = "%s/%s/" % (settings.OP_API_LOCATION_BASE_URL, op_location_id)
        json_data = self.get_json_response(location_url)
        if 'exception' in json_data:
            raise CommandError("%s\n" % json_data['exception'])
        else:
            for organ in ('giunta', 'consiglio'):
                self.stdout.write("%s\n%s\n" % (organ, '='*len(organ)))
                members = json_data[organ]
                for member in members:
                    # date reduction
                    birth_date = member['birth_date'][0:10]
                    start_date = member['date_start'][0:10]
                    if member['sex'] == 'M':
                        member_sex = Person.MALE_SEX
                    else:
                        member_sex = Person.FEMALE_SEX

                    # fetch or create person
                    p, p_created = Person.objects.get_or_create(
                        first_name=member['first_name'],
                        last_name=member['last_name'],
                        birth_date=birth_date,
                        birth_location=member['birth_location'],
                        sex=member_sex
                    )

                    if 'party' in member:
                        party = member['party']
                    if 'group' in member:
                        group = member['group']
                        g, g_created = Group.objects.get_or_create(
                            name=group,
                            acronym=group[0:15]
                        )

                    # create charge description
                    if organ == 'giunta':
                        charge_description = "Assessore %s" % member['charge_descr']
                        charge_institution = Institution.objects.get(institution_type=Institution.CITY_GOVERNMENT)
                    else:
                        charge_description = ""
                        charge_institution = Institution.objects.get(institution_type=Institution.COUNCIL)

                    # membership charge (do not insert vicesindaco now, do that at the end)
                    if member['charge'] != 'Vicesindaco':
                        charge = InstitutionCharge(
                            description=charge_description,
                            start_date = start_date,
                            person = p,
                            institution = charge_institution
                        )
                        charge.save()

                    if organ == 'giunta':
                        # sindaco è membro di giunta con responsability
                        if member['charge'] == 'Sindaco':
                            resp = InstitutionResponsability(
                                description="Sindaco",
                                start_date=start_date,
                                charge=charge,
                                charge_type=InstitutionResponsability.CHARGE_TYPES.mayor
                            )
                            resp.save()
                            # sindaco è anche membro di istituzione sindaco
                            sindaco_charge = InstitutionCharge(
                                description="Sindaco",
                                start_date = start_date,
                                person = p,
                                institution = Institution.objects.get(institution_type=Institution.MAYOR)
                            )
                            sindaco_charge.save()


                    if organ == 'consiglio':
                        # presidente del consiglio è consigliere con responsability
                        if member['charge'] == 'Presidente':
                            resp = InstitutionResponsability(
                                description="Presidente del Consiglio Comunale",
                                start_date=start_date,
                                charge=charge,
                                charge_type=InstitutionResponsability.CHARGE_TYPES.president
                            )
                            resp.save()

                        # vice presidente del consiglio è consigliere con responsability
                        if member['charge'] == 'Vicepresidente':
                            resp = InstitutionResponsability(
                                description="Vicepresidente del Consiglio Comunale",
                                start_date=start_date,
                                charge=charge,
                                charge_type=InstitutionResponsability.CHARGE_TYPES.vice
                            )
                            resp.save()

                        # nel consiglio il sindaco è consigliere con responsability
                        if not p_created and sindaco_charge.person == p:
                            resp = InstitutionResponsability(
                                description="Sindaco",
                                start_date=start_date,
                                charge=charge,
                                charge_type=InstitutionResponsability.CHARGE_TYPES.mayor
                            )
                            resp.save()

                        # group charge
                        gc = GroupCharge.objects.create(group=g, charge=charge, start_date=start_date)
                        gc.save()


                    # output line must be encoded explicitly into utf-8
                    # before being sent to stdout
                    output_line = "%s %s - %s - %s: %s\n" % \
                                (member['first_name'], member['last_name'],
                                 member['birth_date'][0:10], member['birth_location'],
                                 member['textual_rep'])
                    self.stdout.write(output_line.encode('utf-8'))

                self.stdout.write("\n")

                # add vicesindaco now, at the end
                # this is done here, because the Vicesindaco may come with two charges
                # assessore and vicesindaco
                #
                # it would be wrong to have both institutional charges, since
                # vicesindaco is better mapped as a ResponsabilityCharge
                #
                # the following code binds the vicesindaco to a previous
                # assessore charge, if existing, or create a new assessore charge,
                #and binds the responsability to it
                fd = None
                for m in members:
                    if m['charge'] == 'Vicesindaco':
                        fd = m
                        break

                if fd is not None:
                    # get the person (already created)
                    fd_person = Person.objects.get(
                        first_name=fd['first_name'],
                        last_name=fd['last_name'],
                        birth_date=fd['birth_date'][0:10],
                        birth_location=fd['birth_location']
                    )
                    # define institution (city government)
                    fd_charge_institution = Institution.objects.get(institution_type=Institution.CITY_GOVERNMENT)

                    # get or create a city gov charge for the person
                    fd_charge, created = InstitutionCharge.objects.get_or_create(
                        person=fd_person,
                        institution=fd_charge_institution,
                    )

                    # if newly created, then it is starting along with the Vicesindaco
                    # responsability and it is simply marked as Assessore
                    if created:
                        fd_charge.description="Assessore"
                        fd_charge.start_date=fd['date_start'][0:10]
                        fd_charge.save()

                    # responsability added to the charge
                    resp = InstitutionResponsability(
                        description="Vicesindaco",
                        start_date=fd_charge.start_date,
                        charge=fd_charge,
                        charge_type=InstitutionResponsability.CHARGE_TYPES.firstdeputymayor
                    )
                    resp.save()

                    self.stdout.write("Vicesindaco created\n")