Skip to content

Commit

Permalink
Merge pull request digitalfox#110 from ArnaudChirat/api_account_creation
Browse files Browse the repository at this point in the history
Api account creation
  • Loading branch information
bport authored Oct 23, 2020
2 parents 28c5142 + 4e9d16b commit 72bef7d
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 98 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.7.0 (XXXX-XX-XX)
- Add Api for account creation and delete
- Update django-filter to 2.4.0

# 1.6.0 (2020-07-09)
- Add gantt diagram to show contract start date
- Add list of active sources
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ django-bleach = "==0.3.0"
Django = "==2.2.13"
django-split-settings = "==0.3.0"
requests = '==2.24.0 '
django-filter = "==2.3.0"
django-filter = "==2.4.0"
plotly = "==4.8.2"
numpy = "==1.18.5"
194 changes: 112 additions & 82 deletions Pipfile.lock

Large diffs are not rendered by default.

45 changes: 43 additions & 2 deletions interview/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import datetime
import re
from collections import defaultdict

import json

from plotly.offline import plot
import plotly.figure_factory as ff
Expand All @@ -26,6 +26,9 @@
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import require_http_methods
from django_tables2 import RequestConfig
from django.views.decorators.csrf import csrf_exempt
from django.contrib.admin.views.decorators import staff_member_required
from django.utils.dateparse import parse_date

from interview.filters import ProcessFilter
from interview.forms import (
Expand All @@ -40,7 +43,7 @@
OfferForm,
)
from interview.models import Process, Document, Interview, Sources, SourcesCategory, Candidate, Offer
from ref.models import Consultant, Subsidiary
from ref.models import Consultant, PyouPyouUser, Subsidiary


class ProcessTable(tables.Table):
Expand Down Expand Up @@ -432,6 +435,44 @@ def create_offer_ajax(request):
return JsonResponse(data)


@csrf_exempt
@require_http_methods(["POST"])
@user_passes_test(lambda u: u.is_superuser)
def create_account(request):
data = json.loads(request.body)
subsidiary = Subsidiary.objects.filter(name=data["company"]).first()
if not subsidiary:
return JsonResponse({"error": "Company not found"}, status=404)
try:
extra_fields = {"date_joined": timezone.now()}
if "date_joined" in data:
if parse_date(data["date_joined"]) is None:
return JsonResponse({"error": "ISO 8601 for date format"}, status=400)
extra_fields["date_joined"] = data["date_joined"]
consultant = Consultant.objects.create_consultant(
trigramme=data["trigramme"].lower(),
email=data["email"],
company=subsidiary,
full_name=data["name"],
**extra_fields
)
return JsonResponse({"consultant": consultant.__str__()})
except:
return JsonResponse({"error": "user already register"}, status=400)


@csrf_exempt
@require_http_methods(["DELETE"])
@user_passes_test(lambda u: u.is_superuser)
def delete_account(request, trigramme):
user = PyouPyouUser.objects.filter(trigramme=trigramme.lower()).first()
if not user:
return JsonResponse({"error": "user not found"}, status=404)
user.is_active = False
user.save()
return JsonResponse({"user": user.__str__()})


@login_required
@require_http_methods(["GET", "POST"])
def edit_candidate(request, process_id):
Expand Down
2 changes: 2 additions & 0 deletions pyoupyou/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
url(r"^candidate/(?P<process_id>\d+)/$", views.edit_candidate, name="candidate"),
url(r"^create_source/$", views.create_source_ajax, name="create_source"),
url(r"^create_offer/$", views.create_offer_ajax, name="create_offer"),
url(r"^create_account/$", views.create_account, name="create_acount"),
url(r"^delete_account/(?P<trigramme>[a-z]{3})$", views.delete_account, name="delete_acount"),
url(r"^feed/pyoupyou_full.ics$", feeds.InterviewFeed(), name="calendar_full"),
url(r"^export/all_interviews.tsv$", views.export_interviews_tsv, name="export_interviews_tsv"),
url(r"^export/all_processes.tsv$", views.export_processes_tsv, name="export_processess_tsv"),
Expand Down
4 changes: 2 additions & 2 deletions ref/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def email_user(self, subject, message, from_email=None, **kwargs):

class ConsultantManager(models.Manager):
@transaction.atomic
def create_consultant(self, trigramme, email, company, full_name):
user = PyouPyouUser.objects.create_user(trigramme, email, full_name=full_name)
def create_consultant(self, trigramme, email, company, full_name, **extra_fields):
user = PyouPyouUser.objects.create_user(trigramme, email, full_name=full_name, **extra_fields)
consultant = self.model(user=user, company=company, productive=True)
consultant.save()
return consultant
Expand Down
22 changes: 11 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-i https://pypi.org/simple
bleach==3.1.5
bleach==3.2.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
certifi==2020.6.20
chardet==3.0.4
commonmark==0.8.1
Expand All @@ -8,25 +8,25 @@ django-bleach==0.3.0
django-bootstrap-static==3.3.7.2
django-crispy-forms==1.9.1
django-extensions==2.1.6
django-filter==2.3.0
django-filter==2.4.0
django-ical==1.4
django-markwhat==1.6.1
django-select2==7.0.3
django-split-settings==0.3.0
django-tables2==2.0.6
django==2.2.13
future==0.18.2
icalendar==4.0.6
idna==2.10
future==0.18.2; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'
icalendar==4.0.7; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
idna==2.10; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
numpy==1.18.5
packaging==20.4
packaging==20.4; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
plotly==4.8.2
pyparsing==2.4.7
python-dateutil==2.8.1
pyparsing==2.4.7; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'
python-dateutil==2.8.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
pytz==2020.1
requests==2.24.0
retrying==1.3.3
six==1.15.0
sqlparse==0.3.1
urllib3==1.25.9
six==1.15.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
sqlparse==0.4.1; python_version >= '3.5'
urllib3==1.25.10; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'
webencodings==0.5.1

0 comments on commit 72bef7d

Please sign in to comment.