예제 #1
0
파일: views.py 프로젝트: bot242/djangocrm
def team_create(request):
    context = {}
    if request.user.role == 'ADMIN' or request.user.is_superuser:
        print('enter')
        teams = Teams.objects.all()
        context['teams'] = teams
    else:
        raise PermissionDenied

    if request.method == 'GET':
        form = TeamForm()
        context['form'] = TeamForm()
        return render(request, 'team_create.html', context)

    if request.method == 'POST':
        form = TeamForm(request.POST)
        if form.is_valid():
            task_obj = form.save(commit=False)
            print('full value',task_obj)
            task_obj.created_by=request.user
            task_obj.save()
            form.save_m2m()
            return JsonResponse({'error': False, 'success_url': reverse('teams:teams_list')})
        else:
            return JsonResponse({'error': True, 'errors': form.errors})
예제 #2
0
def team_create(request):
    context = {}
    if request.user.is_superuser:
        teams = Teams.objects.all()
        context['teams'] = teams
    else:
        raise PermissionDenied

    if request.method == 'GET':
        context['form'] = TeamForm()
        return render(request, 'teams/new.html', context)

    if request.method == 'POST':
        form = TeamForm(request.POST, request.FILES)
        print(form)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.created_by = request.user
            # obj.picture = request.FILES['picture']
            # obj.picture = request.POST['picture']
            # file_type = obj.picture.url.split('.')[-1]
            # if file_type.lower() not in IMAGE_FILE_TYPES:
            #     return render(request, 'profile_maker/error.html')
            obj.save()
            obj.users.set(
                User.objects.filter(id__in=request.POST.getlist('users')))
            form.save_m2m()
            return redirect('/teams/')
예제 #3
0
def team_create(request):
    context = {}
    if request.user.role == "ADMIN" or request.user.is_superuser:
        teams = Teams.objects.filter(company=request.company)
        context["teams"] = teams
    else:
        raise PermissionDenied

    if request.method == "GET":
        form = TeamForm(request_obj=request)
        context["form"] = form
        return render(request, "team_create.html", context)

    if request.method == "POST":
        form = TeamForm(request.POST, request_obj=request)
        if form.is_valid():
            task_obj = form.save(commit=False)
            task_obj.created_by = request.user
            task_obj.company = request.company
            task_obj.save()
            form.save_m2m()
            return JsonResponse({
                "error": False,
                "success_url": reverse("teams:teams_list")
            })
        else:
            return JsonResponse({"error": True, "errors": form.errors})
예제 #4
0
파일: views.py 프로젝트: bot242/djangocrm
def team_edit(request, team_id):
    if not (request.user.role == 'ADMIN' or request.user.is_superuser):
        raise PermissionDenied
    team_obj = get_object_or_404(Teams, pk=team_id)
    context = {}

    if request.method == 'GET':
        form = TeamForm(instance=team_obj)
        context['form'] = form
        return render(request, 'team_create.html', context)

    if request.method == 'POST':
        form = TeamForm(request.POST, instance=team_obj)
        if form.is_valid():
            task_obj = form.save(commit=False)
            if 'users' in form.changed_data:
                update_team_users.delay(team_id)
                # pass
                # print('celery task')
            task_obj.save()
            form.save_m2m()
            return JsonResponse({
                'error': False,
                'success_url': reverse('teams:teams_list')
            })
        else:
            return JsonResponse({'error': True, 'errors': form.errors})
예제 #5
0
 def post(self, request):
     form = TeamForm(request.POST)
     errors = ''
     if form.is_valid():
         url = '{}/teams'.format(settings.TSURU_HOST)
         response = requests.post(url, data=json.dumps(form.data), headers=self.authorization)
         if response.status_code == 200:
             return redirect(reverse("team-list"))
         errors = response.content
     return TemplateResponse(request, 'auth/team.html', {'form': form, 'errors': errors})
예제 #6
0
파일: views.py 프로젝트: pombredanne/abyss
 def post(self, request):
     form = TeamForm(request.POST)
     errors = ''
     if form.is_valid():
         authorization = {'authorization':
                          request.session.get('tsuru_token')}
         response = requests.post('{0}/teams'.format(settings.TSURU_HOST),
                                  data=json.dumps(form.data),
                                  headers=authorization)
         if response.status_code == 200:
             return redirect(reverse("team-list"))
         errors = response.content
     return TemplateResponse(request, 'auth/team.html',
                             {'form': form, 'errors': errors})
예제 #7
0
def team_member(request, id):
	team = Team.objects.get(id=id)
	team_form = TeamForm(request.POST or None, request.FILES or None)
        if request.method == 'POST':
            
            if not TeamMember.objects.filter(team_id=team).filter(user=request.user).exists():
                if team_form.is_valid():
                    new_form = team_form.save(commit=False)
                    new_form.user = request.user
                    new_form.team_id = team
                    new_form.save()
                    
		response_data = {}




		new_data = json.dumps(response_data)

		return HttpResponse(new_data, content_type='application/json')
예제 #8
0
파일: views.py 프로젝트: GMladen18/python
def create_team_view(request, *args, ** kwargs):
    if request.method == 'GET':

        context = {
            'form': TeamForm(),
        }
        return render(request, 'create_team.html', context)
    else:
        team_form = TeamForm(request.POST, request.FILES)
        if team_form.is_valid():
            name = team_form.cleaned_data['name']
            image = team_form.cleaned_data['image']
            team = Team.objects.create(
                name=name, image=image, created_by=request.user)
            team.save()
            return redirect('home view')

        context = {
            'form': team_form,
        }
        return render(request, 'create-team/', context)
예제 #9
0
def team_edit(request, team_id):
    if not (request.user.role == "ADMIN" or request.user.is_superuser):
        raise PermissionDenied
    team_obj = get_object_or_404(Teams, pk=team_id)
    if team_obj.company != request.company:
        raise PermissionDenied
    actual_users = team_obj.get_users()
    context = {}

    if request.method == "GET":
        form = TeamForm(instance=team_obj, request_obj=request)
        context["form"] = form
        return render(request, "team_create.html", context)

    if request.method == "POST":
        removed_users = []
        form = TeamForm(request.POST, instance=team_obj, request_obj=request)
        if form.is_valid():
            task_obj = form.save(commit=False)
            if "users" in form.changed_data:
                update_team_users.delay(team_id)
                # pass
            task_obj.save()
            form.save_m2m()
            latest_users = task_obj.get_users()
            for user in actual_users:
                if user in latest_users:
                    pass
                else:

                    removed_users.append(user)
            remove_users.delay(removed_users, team_id)
            return JsonResponse({
                "error": False,
                "success_url": reverse("teams:teams_list")
            })
        else:
            return JsonResponse({"error": True, "errors": form.errors})