Exemplo n.º 1
0
def search(request):
    if not authlib.check_authorize(request.session):
        return HttpResponse({'server response': "authentication required"},
                            status=status.HTTP_401_UNAUTHORIZED)

    if request.method != 'GET':
        return HttpResponse('NOT GET')

    src = request.GET['perso']

    # If no query from user
    if not src:
        return HttpResponse('NOT SRC')

    query_list = src.split()
    queryset = Personnel.objects.values(
        "matricule", "nom", "prenom", "email", "raison_sociale",
        'fonction_exacte').filter(
            reduce(
                operator.and_,
                (Q(prenom__istartswith=q) | Q(nom__istartswith=q)
                 | Q(email__icontains=q) | Q(raison_sociale__icontains=q)
                 | Q(fonction_exacte__icontains=q) | Q(matricule__icontains=q)
                 for q in query_list)))
    return Response(list(queryset))

    if match:
        return HttpResponse(queryset, content_type='application/json')

    return HttpResponse('NOT MATCH')
Exemplo n.º 2
0
def post_note_frais(request):
    if not authlib.check_authorize(request.session):
        return Response({'server response': "authentication required"},
                        status=status.HTTP_401_UNAUTHORIZED)

    if not request.method == 'POST':
        return Response(False)
    parser_classes = (FileUploadParser, )
    settings.LOGGER.debug(request.method)
    if request.method == 'PATCH' or request.method == 'POST':
        file_serializer = FileSerializer(Signature, data=request.data)
        settings.LOGGER.debug(file_serializer.is_valid())
        settings.LOGGER.debug(request.data['file'])
        email = authlib.get_jwt(request.session['access_token'])['email']
        name = authlib.get_jwt(request.session['access_token'])['name']
        signature = Signature()
        signature.document = request.data['file']
        signature.sender_email = email
        signature.creation_date = request.data['date']
        signature.name = request.data['name']
        signature.save()
        # Send mail
        server = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT)
        settings.LOGGER.debug("server started")
        server.starttls()
        settings.LOGGER.debug("logging in")
        server.login(settings.EMAIL_HOST_USER, settings.EMAIL_HOST_PASSWORD)
        settings.LOGGER.debug("logged in")
        message = 'Bonjour,<br /> Vous avez un document à signer de la part du: ' + name + '. <br /> Veuillez consulter votre compte: <a href="https://signature.chamberlab.net/">Signature</a>. <br /> <br /> Cordialement, <br /> CCI France.'
        settings.LOGGER.debug("sending")
        msg = EmailMultiAlternatives("Note de frais a signer", message, email,
                                     ["*****@*****.**"])
        msg.attach_alternative(message, "text/html")
        msg.send()
    return Response(True)
Exemplo n.º 3
0
def search(request):
    if not authlib.check_authorize(request.session):
        return HttpResponse({'server response': "authentication required"},
                            status=status.HTTP_401_UNAUTHORIZED)

    if request.method != 'GET':
        return HttpResponse('NOT GET')

    src = request.GET['doc']

    # If no query from user
    if not src:
        return HttpResponse('NOT SRC')

    email = authlib.get_jwt(request.session['access_token'])['email']
    query_list = src.split()
    queryset = Signature.objects.values(
        "id", "name", "description", "document", "signature_image",
        "sender_email", "recipient_email", "creation_date", "date_signature"
    ).filter(Q(recipient_email=email) | Q(sender_email=email)).filter(
        reduce(operator.and_,
               (Q(name__istartswith=q) | Q(name__icontains=q)
                | Q(description__icontains=q) | Q(sender_email__icontains=q)
                | Q(creation_date__icontains=q) for q in query_list)))

    return Response(list(queryset))

    if match:
        return HttpResponse(queryset, content_type='application/json')

    return HttpResponse('NOT MATCH')
Exemplo n.º 4
0
def get_one_document(request, id_doc):
    if not authlib.check_authorize(request.session):
        return Response({'server response': "authentication required"},
                        status=status.HTTP_401_UNAUTHORIZED)

    document = Signature.objects.values("id", "name", "description",
                                        "document", "signature_image",
                                        "sender_email", "recipient_email",
                                        "creation_date",
                                        "date_signature").get(id=id_doc)
    settings.LOGGER.debug(document)

    return Response(document)
Exemplo n.º 5
0
def get_all_documents(request):
    if not authlib.check_authorize(request.session):
        return Response({'server response': "authentication required"},
                        status=status.HTTP_401_UNAUTHORIZED)

    email = authlib.get_jwt(request.session['access_token'])['email']
    list_document = list(
        Signature.objects.values(
            "id", "name", "description", "document", "signature_image",
            "sender_email", "recipient_email", "creation_date",
            "date_signature").filter(
                Q(sender_email=email) | Q(recipient_email=email)))

    return Response(list_document)
Exemplo n.º 6
0
def get_personnel(request):
    if not authlib.check_authorize(request.session):
        settings.LOGGER.debug('DEBUG authorize session!')
        return Response({'server response': "authentication required"},
                        status=status.HTTP_401_UNAUTHORIZED)

    perso_list = list(
        Personnel.objects.values("id", "matricule", "phone", "civilite", "nom",
                                 "prenom", "email", "direction",
                                 "fonction_exacte", "raison_sociale").order_by(
                                     'matricule').distinct('matricule')[:300])
    cookies = request.COOKIES
    settings.LOGGER.debug(cookies)
    _vars = {'perso_list': perso_list, 'cookies': cookies}
    return Response(perso_list)
Exemplo n.º 7
0
def post_signature(request, id_doc):
    if not authlib.check_authorize(request.session):
        return Response({'server response': "authentication required"},
                        status=status.HTTP_401_UNAUTHORIZED)

    if not request.method == 'POST':
        return Response(False)

    signature = Signature.objects.get(id=id_doc)
    signature.signature_image = request.POST['data']
    signature.date_signature = request.POST['date']
    settings.LOGGER.debug(request.POST['date'])
    settings.LOGGER.debug(request.POST['data'])
    signature.save()
    return Response(True)
Exemplo n.º 8
0
def create_attributes(request, attribute):
    if not authlib.check_authorize(request.session):
        return HttpResponse({'server response': "authentication required"},
                            status=status.HTTP_401_UNAUTHORIZED)

    url = settings.URL_SENDINBLUE

    payload = {"type": "text"}
    headers = {
        'accept': "application/json",
        'content-type': "application/json",
        'api-key': settings.API_KEY_SENDINBLUE
    }
    # Create attributes for sendinblue : add name of attribute in url exp: create_attributes/name_attributes
    response = requests.request("POST",
                                url + '/attributes/normal/' + attribute,
                                data=json.dumps(payload),
                                headers=headers)
    if response.status_code != 201:
        settings.LOGGER.debug(response.text)

    return Response(response)
Exemplo n.º 9
0
def import_contact_sendinblue(request):
    if not authlib.check_authorize(request.session):
        return HttpResponse({'server response': "authentication required"},
                            status=status.HTTP_401_UNAUTHORIZED)

    url = settings.URL_SENDINBLUE
    headers = {
        'accept': "application/json",
        'content-type': "application/json",
        'api-key': settings.API_KEY_SENDINBLUE
    }
    personnel = list(
        Personnel.objects.values(
            "nom", "prenom", "email", "phone",
            "raison_sociale").order_by('email').distinct('email'))

    for i in range(len(personnel)):
        settings.LOGGER.debug(i)
        # Get user by email
        response_user = requests.request("GET",
                                         url + '/' + personnel[i]['email'],
                                         headers=headers)

        # If the request for get the email is success : user already exist
        if response_user.status_code == 200:
            settings.LOGGER.debug('update')
            payload = {
                "attributes": {
                    "lastname": personnel[i]['nom'],
                    "firstname": personnel[i]['prenom'],
                    "phone": personnel[i]['phone'].replace(" ", ""),
                    "social_reason": personnel[i]['raison_sociale']
                }
            }
            settings.LOGGER.debug(personnel[i]['email'])
            settings.LOGGER.debug(url + '/' + personnel[i]['email'])
            settings.LOGGER.debug(json.dumps(payload))
            response = requests.request("PUT",
                                        url + '/' + personnel[i]['email'],
                                        data=json.dumps(payload),
                                        headers=headers)
            if response.status_code != 204:
                settings.LOGGER.debug(response.text)
            continue

        # User not exist : send create
        payload = {
            "email": personnel[i]['email'],
            "attributes": {
                "lastname": personnel[i]['nom'],
                "firstname": personnel[i]['prenom'],
                "phone": personnel[i]['phone'].replace(" ", ""),
                "social_reason": personnel[i]['raison_sociale']
            }
        }
        response = requests.request("POST",
                                    url,
                                    data=json.dumps(payload),
                                    headers=headers)
        if response.status_code != 201:
            settings.LOGGER.debug(response.text)

    return Response(response)
Exemplo n.º 10
0
def import_personnel(request):
    if not authlib.check_authorize(request.session):
        return Response({'server response': "authentication required"},
                        status=status.HTTP_401_UNAUTHORIZED)

    PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
    BASE_DIR = os.path.dirname(PROJECT_ROOT)
    data = open(BASE_DIR + '/test', encoding='ISO-8859-1')
    data.readline()
    cpt_success = 0
    cpt_failure = 0
    for line in data:
        line = line.split(';')
        if (len(line[10]) > 14 or len(line[11]) > 14 or len(line[24]) > 14):
            cpt_failure = cpt_failure + 1
            continue

        if line[43] == 'matricule':
            continue

        if Personnel.objects.filter(matricule=line[43]):
            tmp = Personnel.objects.get(matricule=line[43])
        else:
            tmp = Personnel()
            tmp.matricule = line[43]
        # return Response({'server_response': line})

        tmp.civilite = line[0]
        tmp.prenom = line[1]
        tmp.nom = line[2]
        tmp.direction = line[3]
        tmp.fonction_generique = line[4]
        tmp.fonction_exacte = line[5]
        tmp.date_debut_fonction = line[6]
        tmp.date_fin_fonction = line[7]
        tmp.titre_politesse = line[8]
        tmp.email = line[9]
        tmp.tel_fixe = line[10]
        tmp.tel_mobile = line[11]
        tmp.service = line[12]
        tmp.expertise = line[13]
        tmp.domaine_metier = line[14]
        tmp.centres = line[15]
        tmp.raison_sociale = line[16]
        tmp.n_siret = line[17]
        tmp.adress = line[18]
        tmp.complement_adresse = line[19]
        tmp.BP = line[20]
        tmp.CP = line[21]
        tmp.ville = line[22]
        tmp.pays = line[23]
        tmp.phone = line[24]
        tmp.fax = line[25]
        tmp.site = line[26]
        tmp.type_organisme = line[28]
        tmp.enseigne = line[29]
        tmp.sous_type = line[30]
        tmp.secteur_activite = line[31]
        tmp.code_APE = line[32]
        tmp.effectif = line[33]
        tmp.nombre_ressortissants = line[34]
        tmp.id_annuaire = line[35]
        tmp.source_import = line[36]
        tmp.region = line[37]
        tmp.departement = line[38]
        tmp.linkedin = line[39]
        tmp.facebook = line[40]
        tmp.tweeter = line[41]
        tmp.radiation = line[42]
        tmp.save()
        cpt_success = cpt_success + 1

    data.close()
    #print(request)
    return HttpResponse(cpt_success)