예제 #1
0
def create_relationship(request):
    user_id = request.REQUEST.get('user_id', None)
    project_id = request.REQUEST.get('project_id', None)
    url = reverse('dashboard')  # Default if nothing else comes up

    project = None
    if project_id:
        project = get_object_or_404(Project, pk=project_id)
        url = reverse('view_project', args=(project_id,))
    else:  # Adding a user to a specific project
        project_form = SelectProjectForm(request.POST)
        if project_form.is_valid():
            project = project_form.save()

    user = None
    if user_id:
        user = get_object_or_404(User, pk=user_id)
        url = reverse('view_user', args=(user_id,))
    else:  # Adding a project to a specific user
        user_form = SelectUserForm(request.POST)
        if user_form.is_valid():
            user = user_form.save()

    if user and project:
        ProjectRelationship.objects.get_or_create(
                user=user, project=project)

    url = request.REQUEST.get('next', url)
    return HttpResponseRedirect(url)
예제 #2
0
def create_relationship(request):
    user_id = request.REQUEST.get('user_id', None)
    project_id = request.REQUEST.get('project_id', None)
    url = reverse('dashboard')  # Default if nothing else comes up

    project = None
    if project_id:
        project = get_object_or_404(Project, pk=project_id)
        url = reverse('view_project', args=(project_id, ))
    else:  # Adding a user to a specific project
        project_form = SelectProjectForm(request.POST)
        if project_form.is_valid():
            project = project_form.save()

    user = None
    if user_id:
        user = get_object_or_404(User, pk=user_id)
        url = reverse('view_user', args=(user_id, ))
    else:  # Adding a project to a specific user
        user_form = SelectUserForm(request.POST)
        if user_form.is_valid():
            user = user_form.save()

    if user and project:
        ProjectRelationship.objects.get_or_create(user=user, project=project)

    url = request.REQUEST.get('next', url)
    return HttpResponseRedirect(url)
예제 #3
0
def view_user(request, user_id):
    user = get_object_or_404(User, pk=user_id)
    add_project_form = SelectProjectForm()
    return render(request, 'timepiece/user/view.html', {
        'user': user,
        'add_project_form': add_project_form,
    })
예제 #4
0
 def get_context_data(self, **kwargs):
     context = super(ViewUser, self).get_context_data(**kwargs)
     context.update({
         'add_project_form': SelectProjectForm(),
     })
     return context
예제 #5
0
 def get_project(self):
     project_id = self.request.GET.get('project_id', None)
     if project_id:
         return get_object_or_404(Project, pk=project_id)
     return SelectProjectForm(self.request.POST).get_project()