예제 #1
0
 def save(self, validated_data):
     contacts = validated_data.pop('contacts')
     if contacts:
         person = Person(**validated_data)
         person.save()
         for co in contacts:
             Contact.objects.create(person=person,
                                    contact_type=co.get('contact_type'),
                                    value=co.get('value'))
         return person
예제 #2
0
def add_new_record(cleaned_data, person_obj = None):
    if person_obj:
        person_obj.full_name = cleaned_data['full_name']
        person_obj.phone = cleaned_data['phone']
        person_obj.email = cleaned_data['email']
        person_obj.save()
    else:
        person = Person(full_name = cleaned_data['full_name'],
                        phone = cleaned_data['phone'],
                        email = cleaned_data['email'])
        person.save()
예제 #3
0
def getAdd(request):
    if request.method == 'GET':
        return render(request, 'add.html')
    elif request.method == 'POST':
        name = request.POST['name']
        telephone = request.POST['telephone']
        mobile = request.POST['mobilephone']
        email = request.POST['email']
        address = request.POST['location']
        QQ = request.POST['OICQ']
        gender = request.POST['gender']
        person = Person(name=name,
                        telephone=telephone,
                        mobile=mobile,
                        email=email,
                        address=address,
                        QQ=QQ,
                        gender=gender)
        person.save()
        return HttpResponseRedirect("/contacts")
예제 #4
0
def person(request):
    if request.method == 'POST':
        sta = request.POST.get("status")
        se = request.POST.get("sex")
        cat = request.POST.get("category")
        pre = request.POST.get("prenom")
        no = request.POST.get("nom")
        cont = request.POST.get("contact_1")
        # cin = request.POST.get("n_cin")
        nn = request.POST.get("nina")
        prf = request.POST.get("profession")
        nat = request.POST.get("nationnalite")
        nf = request.POST.get("nif")
        ss = request.POST.get("siege_social")
        resp = request.POST.get("responsable")
        ema = request.POST.get("email")
        cret = request.POST.get('created_at')

        data = Person(
            status=sta,
            prenom=pre,
            nom=no,
            sex=se,
            category=cat,
            contact_1=cont,
            # n_cin=cin,
            nina=nn,
            profession=prf,
            nationnalite=nat,
            nif=nf,
            siege_social=ss,
            responsable=resp,
            email=ema,
            created_at=cret)
        data.save()

        return HttpResponseRedirect(reverse('mesure'))
    else:
        form = PersonForm()
    return render(request, 'kalaliso/person.html', {'form': form})
def importCSV(request, template='contacts/person/import.html'):
    """ Import people from csv
    """

    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login/?next=%s' % request.path)

    registres = 0

    if request.method == 'POST':
        form = ImportCSVForm(request.POST, request.FILES)
        if form.is_valid():
            uploaded_file = request.FILES['fitxer']
            uploaded_file.read()
            reader = csv.reader(uploaded_file, delimiter=',', quotechar='"')

            for row in reader:
                person = Person()
                person.first_name = row[0]
                person.last_name = row[1]
                person.contact_type = row[3]
                person.id_card = row[5]

                base_slug = slugify("%s %s %s" % (p.first_name, p.last_name, p.secondlast_name))
                # hem de comprovar que no existeix cap persona amb aquest nom. Si no, hem d'afegir -1
                tmp_slug = base_slug
                trobat = True
                counter = 0

                while trobat:
                    try:
                        Person.objects.get(slug__iexact=tmp_slug)
                        counter = counter + 1
                        tmp_slug = "%s-%s" % (base_slug, str(counter))

                    except Person.DoesNotExist:
                        trobat = False

                person.slug = tmp_slug
                person.save()

                registres = registres + 1

    else:
        form = ImportCSVForm()

    return render_to_response(template, {'registres': registres, 'form': form}, RequestContext(request))
예제 #6
0
 def send_friend_request(self, receiver_id):
     try:
         row = Person.objects.get(requester_id=self.user_id,
                                  receiver_id=receiver_id)
         status = row.status
         if status == 'pending':
             error = "already sent request"
         elif status == 'complete':
             error = "you are friend already"
         else:
             error = ""
         result_dict = dict(error=error)
     except Person.DoesNotExist:
         Person(
             requester_id=self.user_id,
             receiver_id=receiver_id,
             status='pending',
         ).save()
         result_dict = dict(result="success")
     return result_dict
예제 #7
0
파일: tests.py 프로젝트: NekoVika/RepoT
    def test_creating_a_new_person_and_saving_it_to_the_database(self):
        per = Person()
        per.name = "Neko"
        per.surname="Miko"
        per.dateOfBirth = "1900-04-05"
        per.bio="Bio"
        per.jabber="*****@*****.**"
        per.email="*****@*****.**"
        per.skype="skypeID"
        per.otherContact="Other"

        per.save()

        all_persons_in_database = Person.objects.all()
        self.assertEquals(len(all_persons_in_database), 2)
        test_person_in_database = all_persons_in_database[1]
        self.assertEquals(test_person_in_database, per)

        self.assertEquals(test_person_in_database.name, "Neko")
        self.assertEquals(test_person_in_database.surname, "Miko")
        self.assertEquals(test_person_in_database.dateOfBirth, datetime.date(1900, 4, 5))
        self.assertEquals(test_person_in_database.bio, "Bio")
        self.assertEquals(test_person_in_database.jabber, "*****@*****.**")
        self.assertEquals(test_person_in_database.email, "*****@*****.**")
        self.assertEquals(test_person_in_database.skype, "skypeID")
        self.assertEquals(test_person_in_database.otherContact, "Other")
예제 #8
0
파일: tests.py 프로젝트: NekoVika/RepoT
    def test_creating_a_new_person_and_saving_it_to_the_database(self):
        per = Person()
        per.name = "Neko"
        per.surname = "Miko"
        per.dateOfBirth = "1900-04-05"
        per.bio = "Bio"
        per.jabber = "*****@*****.**"
        per.email = "*****@*****.**"
        per.skype = "skypeID"
        per.otherContact = "Other"

        per.save()

        all_persons_in_database = Person.objects.all()
        self.assertEquals(len(all_persons_in_database), 2)
        test_person_in_database = all_persons_in_database[1]
        self.assertEquals(test_person_in_database, per)

        self.assertEquals(test_person_in_database.name, "Neko")
        self.assertEquals(test_person_in_database.surname, "Miko")
        self.assertEquals(test_person_in_database.dateOfBirth,
                          datetime.date(1900, 4, 5))
        self.assertEquals(test_person_in_database.bio, "Bio")
        self.assertEquals(test_person_in_database.jabber, "*****@*****.**")
        self.assertEquals(test_person_in_database.email, "*****@*****.**")
        self.assertEquals(test_person_in_database.skype, "skypeID")
        self.assertEquals(test_person_in_database.otherContact, "Other")
def synchronizeSPIPForm(request, template='contacts/person/synchronize.html'):
    """ Import inscriptions from spip form
    """

    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login/?next=%s' % request.path)

    registres = 0
    user = request.user

    if request.method == 'POST':
        form = SynchronizeSPIPForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['confirma'] == True:
                lastperson = Person.objects.latest('external_id')

                req = urllib2.Request(settings.SPIP_SYNC_URL  + '?action=get&last_id=' + str(lastperson.external_id) , None, {'user-agent':settings.SPIP_SYNC_AGENT})
                opener = urllib2.build_opener()
                json_data = simplejson.load(opener.open(req))

                person = Person()
                person.external_id = 0
                laboral_levels = []
                courses = []

                for row in json_data['list']:
                    if row['id_donnee'] != str(person.external_id) and person.external_id > 0:
                        # donam d'alta la persona anterior
                        person.slug = calculaSlugPersona(person)
                        person.user_add = user
                        person.user_modify = user
                        person.save()
                        # alta relacio persona cursos
                        for course_id in courses:
                            person.courses.add(Course.objects.get(id=course_id))

                        registres = registres + 1
                        # nova persona
                        person = Person()
                        laboral_levels = []
                        courses = []

                    person.external_id = row['id_donnee']
                    person.date_registration = row['date']


                    if row['champ'] == 'ligne_1':
                        person.first_name = row['valeur'] #.decode("utf8", "ignore")
                    elif row['champ'] == 'ligne_2':
                        person.last_name = row['valeur'] #.decode("utf8", "ignore")
                    elif row['champ'] == 'ligne_3':
                        person.id_card = row['valeur']
                    elif row['champ'] == 'ligne_4':
                        person.home_address = row['valeur'] #.decode("utf8", "ignore")
                    elif row['champ'] == 'ligne_5':
                        person.home_postalcode = row['valeur']
                    elif row['champ'] == 'ligne_6':
                        person.home_town = row['valeur'] #.decode("utf8", "ignore")
                    elif row['champ'] == 'select_5':
                        person.home_province = row['titre'] #.decode("utf8", "ignore")
                    elif row['champ'] == 'email_1':
                        person.email_address = row['valeur']
                    elif row['champ'] == 'ligne_8':
                        person.phone_number = row['valeur']
                    elif row['champ'] == 'ligne_9':
                        person.mobile_number = row['valeur']
                    elif row['champ'] == 'ligne_19':
                        person.twitter = row['valeur'] #.decode("utf8", "ignore")
                    elif row['champ'] == 'select_1':
                        person.laboral_category = row['rang']
                    elif row['champ'] == 'multiple_1':
                        laboral_levels.append(row['rang'])
                        person.laboral_levels = ",".join("'%s'" % str(level)  for level in laboral_levels)
                        # print >> sys.stderr, 'Laboral levels = %s' % person.laboral_levels
                    elif row['champ'] == 'ligne_10':
                        person.laboral_nrp = row['valeur']
                    elif row['champ'] == 'num_1':
                        person.laboral_years = float(row['valeur']) if '.' in row['valeur'] else int(row['valeur'])
                    elif row['champ'] == 'select_2':
                        person.laboral_cuerpo = row['rang']
                    elif row['champ'] == 'ligne_11':
                        person.laboral_degree = row['valeur'] #.decode("utf8", "ignore")
                    elif row['champ'] == 'ligne_12':
                        person.laboral_centername = row['valeur'] #.decode("utf8", "ignore")
                    elif row['champ'] == 'ligne_13':
                        person.laboral_centercode = row['valeur']
                    elif row['champ'] == 'ligne_16':
                        person.laboral_centerpostalcode = row['valeur']
                    elif row['champ'] == 'ligne_14':
                        person.laboral_centertown = row['valeur'] #.decode("utf8", "ignore")
                    elif row['champ'] == 'select_4':
                        person.laboral_centerprovince = row['titre'] #.decode("utf8", "ignore")
                    elif row['champ'] == 'select_3':
                        person.math_society = row['rang']
                    elif row['champ'] == 'texte_1':
                        person.remarks = row['valeur'] #.decode("utf8", "ignore")
                    elif row['champ'] == 'select_6':
                        person.lang = row['rang']
                    # nou, cursos
                    elif row['champ'] == 'multiple_2':
                        courses.append(row['rang'])


                # Hem de donar d'alta la darrera persona
                if person.external_id > 0:
                    person.slug = calculaSlugPersona(person)
                    person.user_add = user
                    person.user_modify = user
                    person.save()
                    # alta relacio persona cursos
                    for course_id in courses:
                        person.courses.add(Course.objects.get(id=course_id))
                    registres = registres + 1


                # Posam a 0 els registres no sincronitzats
                if not request.session:
                    request.session={}
                request.session['regs_not_sync'] = 0

    else:
        form = SynchronizeSPIPForm()
        registres = -1

    return render_to_response(template, {'registres': registres, 'form': form}, RequestContext(request))
def synchronizeSPIPForm(request, template='contacts/person/synchronize.html'):
    """ Import inscriptions from spip form
    """

    if not request.user.is_authenticated():
        return HttpResponseRedirect('/login/?next=%s' % request.path)

    registres = 0
    user = request.user

    if request.method == 'POST':
        form = SynchronizeSPIPForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['confirma'] == True:
                lastperson = Person.objects.latest('external_id')



                db = MySQLdb.connect(host=settings.SPIP_DATABASE_HOST,user=settings.SPIP_DATABASE_USER,
                                     passwd=settings.SPIP_DATABASE_PASSWORD,db=settings.SPIP_DATABASE, charset='utf8')
                cur = db.cursor()
                cur.execute("""
                    SELECT insc.id_donnee, insc.date, camp.champ, camp.valeur, valor.rang, valor.titre
                    FROM spip_forms_donnees insc, spip_forms_donnees_champs camp
                    LEFT OUTER JOIN spip_forms_champs_choix valor ON valor.champ = camp.champ
                    AND valor.choix = camp.valeur
                    WHERE insc.id_donnee = camp.id_donnee
                    AND insc.id_donnee > %s
                    AND insc.id_form = 1
                    AND insc.statut = 'publie'
                    ORDER BY insc.id_donnee, camp.champ
                """ % lastperson.external_id )

                person = Person()
                person.external_id = 0
                laboral_levels = []

                for row in cur.fetchall():
                    if row[0] != person.external_id and person.external_id > 0:
                        # donam d'alta la persona anterior
                        person.slug = calculaSlugPersona(person)
                        person.user_add = user
                        person.user_modify = user
                        person.save()
                        registres = registres + 1
                        # nova persona
                        person = Person()
                        laboral_levels = []

                    person.external_id = row[0]
                    person.date_registration = row[1]


                    if row[2] == 'ligne_1':
                        person.first_name = row[3] #.decode("utf8", "ignore")
                    elif row[2] == 'ligne_2':
                        person.last_name = row[3] #.decode("utf8", "ignore")
                    elif row[2] == 'ligne_3':
                        person.id_card = row[3]
                    elif row[2] == 'ligne_4':
                        person.home_address = row[3] #.decode("utf8", "ignore")
                    elif row[2] == 'ligne_5':
                        person.home_postalcode = row[3]
                    elif row[2] == 'ligne_6':
                        person.home_town = row[3] #.decode("utf8", "ignore")
                    elif row[2] == 'select_5':
                        person.home_province = row[5] #.decode("utf8", "ignore")
                    elif row[2] == 'email_1':
                        person.email_address = row[3]
                    elif row[2] == 'ligne_8':
                        person.phone_number = row[3]
                    elif row[2] == 'ligne_9':
                        person.mobile_number = row[3]
                    elif row[2] == 'ligne_19':
                        person.twitter = row[3] #.decode("utf8", "ignore")
                    elif row[2] == 'select_1':
                        person.laboral_category = row[4]
                    elif row[2] == 'multiple_1':
                        laboral_levels.append(row[4])
                        person.laboral_levels = ",".join("'%s'" % str(level)  for level in laboral_levels)
                        # print >> sys.stderr, 'Laboral levels = %s' % person.laboral_levels
                    elif row[2] == 'ligne_10':
                        person.laboral_nrp = row[3]
                    elif row[2] == 'num_1':
                        person.laboral_years = float(row[3]) if '.' in row[3] else int(row[3])
                    elif row[2] == 'select_2':
                        person.laboral_cuerpo = row[4]
                    elif row[2] == 'ligne_11':
                        person.laboral_degree = row[3] #.decode("utf8", "ignore")
                    elif row[2] == 'ligne_12':
                        person.laboral_centername = row[3] #.decode("utf8", "ignore")
                    elif row[2] == 'ligne_13':
                        person.laboral_centercode = row[3]
                    elif row[2] == 'ligne_16':
                        person.laboral_centerpostalcode = row[3]
                    elif row[2] == 'ligne_14':
                        person.laboral_centertown = row[3] #.decode("utf8", "ignore")
                    elif row[2] == 'select_4':
                        person.laboral_centerprovince = row[5] #.decode("utf8", "ignore")
                    elif row[2] == 'select_3':
                        person.math_society = row[4]
                    elif row[2] == 'texte_1':
                        person.remarks = row[3] #.decode("utf8", "ignore")
                    elif row[2] == 'select_6':
                        person.lang = row[4]



                # Hem de donar d'alta la darrera persona
                if person.external_id > 0:
                    person.slug = calculaSlugPersona(person)
                    person.user_add = user
                    person.user_modify = user
                    person.save()
                    registres = registres + 1

                # Close all cursors
                cur.close()
                # Close all databases
                db.close()
                # Posam a 0 els registres no sincronitzats
                if not request.session:
                    request.session={}
                request.session['regs_not_sync'] = 0

    else:
        form = SynchronizeSPIPForm()
        registres = -1

    return render_to_response(template, {'registres': registres, 'form': form}, RequestContext(request))