예제 #1
0
def user_profile(request):
    if request.method == 'POST':
        user = request.user
        form = EditUserModelForm(request.POST, request.FILES, instance=user)

        if form.is_valid():
            print request.POST
            if not request.POST.get('organization'):
                response_data = {'error': True, "response": {"organization": 'Please provide organization name'}}
                return HttpResponse(json.dumps(response_data))
            organization = Organization.objects.get(id=request.user.organization.id)
            organization.name = request.POST.get('organization')
            organization.domain = request.POST.get('domain').lower()
            organization.save()

            if 'profile_pic' in request.FILES:

                user.profile_pic = request.FILES['profile_pic']
                try:
                    shutil.rmtree(settings.MEDIA_ROOT + 'profile/' + user.username)
                except:
                    pass

            form.save()
            response_data = {'error': False, "response": 'Successfully updated'}
            messages.success(request, 'Your profile updated successfully !')
        else:
            response_data = {'error': True, 'response': form.errors}

        return HttpResponse(json.dumps(response_data))
    return render(request, 'user/user_profile.html', {'notification_list': get_notification_list(request.user)})
예제 #2
0
def change_password(request):
    if request.method == 'POST':
        user = request.user
        form = ChangePasswordForm(request.POST, request=request)
        if form.is_valid():
            user.set_password(request.POST['password1'])
            user.save()
            response_data = {'error': False, "response": 'Your password is updated !'}
            messages.success(request, 'Your password updated successfully!')
        else:
            response_data = {'error': True, 'response': form.errors}

        return HttpResponse(json.dumps(response_data))
    return render(request, 'user/change_password.html', {'notification_list': get_notification_list(request.user)})
예제 #3
0
def add_task(request, slug, milestone_slug):
    project_obj = Project.objects.get(slug=slug, organization=request.user.organization)
    if request.method == 'POST':
        add_task_dict = request.POST.copy()
        add_task_dict['project'] = project_obj.id
        json_data = {}
        add_task_form = TaskForm(add_task_dict, project=project_obj, user=request.user)
        if add_task_form.is_valid():
            json_data['error'] = False
            task = add_task_form.save()

            task.order = project_obj.project_tickets.count() + 1
            task.save()

            msg = "created " + task.name + " of milestone " + task.milestone.name

            create_timeline.send(sender=request.user, content_object=task, namespace=msg, event_type="task created",
                                 project=project_obj)
            try:
                msg = "task " + task.name + " is assigned to " + task.assigned_to.username
                create_timeline.send(sender=request.user, content_object=task.assigned_to, namespace=msg,
                                     event_type="task assigned", project=project_obj)
            except:
                pass
            return HttpResponse(json.dumps(json_data), content_type='application/json')
        else:
            json_data['error'] = True
            json_data['form_errors'] = add_task_form.errors
            return HttpResponse(json.dumps(json_data), content_type='application/json')
    else:
        milestone_list = project_obj.milestones.all()
        ticket_status_list = TicketStatus.objects.filter(project=project_obj).order_by('order')
        if not ticket_status_list:
            return HttpResponseRedirect(reverse("project:ticket_status",kwargs={'slug':slug}))
        assigned_to_list = []
        for member in project_obj.members.all():
            try:
                Role.objects.get(users__email=member.email, project=project_obj)
                assigned_to_list.append(member)
            except:
                pass
        milestone = project_obj.milestones.get(slug=milestone_slug)
        return render(request, 'task/add_task.html', {'ticket_status_list': ticket_status_list,
                                                      'assigned_to_list': assigned_to_list, 'slug': slug,
                                                      'milestone_list': milestone_list,
                                                      'milestone': milestone,
                                                      'notification_list': get_notification_list(request.user)})