Ejemplo n.º 1
0
def edit_user(request):
    form = Edit_User(request.POST, instance=request.user)
    if form.is_valid():
        user = form.save()

        redirect_url = reverse('webapp.pages.user_profile', args=(user.id, ))
        return JsonResponse(data={'redirect_to': redirect_url})

    return JsonResponse(errors=form.errors)
Ejemplo n.º 2
0
def create_house(request):
    form = Create_House(request.POST)
    if form.is_valid():
        house = form.save()

        redirect_url = reverse('webapp.pages.houses')
        return JsonResponse(data={'redirect_to': redirect_url})

    return JsonResponse(errors=form.errors)
Ejemplo n.º 3
0
def edit_flight(request, flight_id):
    flight2 = get_object_or_404(Flight, pk=flight_id)
    form = Edit_Flight(request.POST, instance=flight2)
    if form.is_valid():
        flight = form.save()

        redirect_url = reverse('webapp.pages.homepage')
        return JsonResponse(data={'redirect_to': redirect_url})

    return JsonResponse(errors=form.errors)
Ejemplo n.º 4
0
def login(request):
    """
    Handles the login action.
    """
    form = LoginForm(None, data=request.POST)
    if form.is_valid():
        auth_login(request, form.get_user())
        return JsonResponse(
            data={'redirect_to': reverse('webapp.pages.my_flights')})

    return JsonResponse(errors=form.errors)
Ejemplo n.º 5
0
def sign_up(request):
    """Create a User object"""
    form = ShortSignupForm(request.POST)
    if form.is_valid():
        user = form.save()
        user = authenticate(username=request.POST['email'],
                            password=request.POST['password'])
        auth_login(request, user)

        redirect_url = reverse('webapp.pages.homepage')
        return JsonResponse(data={'redirect_to': redirect_url})

    return JsonResponse(errors=form.errors)
Ejemplo n.º 6
0
def create_flight(request):
    form = Create_Flight(request.POST)
    if form.is_valid():
        flight = form.save(commit=False)

        # set foreign keys
        flight.flyer = request.user

        flight.save()  # persist the object to the DB

        redirect_url = reverse('webapp.pages.my_flights')
        return JsonResponse(data={'redirect_to': redirect_url})

    return JsonResponse(errors=form.errors)
Ejemplo n.º 7
0
def create_wall_post(request, user_id):
    user = get_object_or_404(User, pk=user_id)
    form = Create_Wall_post(request.POST)
    if form.is_valid():
        wall_post = form.save(commit=False)

        # set foreign keys
        wall_post.writer = request.user
        wall_post.wall_owner = user

        wall_post.save()  # persist the object to the DB

        redirect_url = reverse('webapp.pages.homepage')
        return JsonResponse(data={'redirect_to': redirect_url})

    return JsonResponse(errors=form.errors)
Ejemplo n.º 8
0
def create_friendship(request, user_id):
    user = get_object_or_404(User, pk=user_id)
    form = Create_Friendship(request.POST)
    if form.is_valid():
        friendship = form.save(commit=False)

        # set foreign keys
        friendship.requester = request.user
        friendship.accepter = user

        friendship.save()  # persist the object to the DB

        redirect_url = reverse('webapp.pages.friendship_page',
                               args=(friendship.id, ))
        return JsonResponse(data={'redirect_to': redirect_url})

    return JsonResponse(errors=form.errors)