예제 #1
0
파일: views.py 프로젝트: thechild/giftlist2
def add_gift(request, gift_id=None):
    myself = get_person_from_user(request.user)
    if gift_id:
        gift = get_object_or_404(Gift, pk=gift_id)
        if gift.recipient != myself:
            messages.error(request, "You don't have permission to edit that gift.")
            return HttpResponseRedirect(reverse('Gifts.views.user_home'))
    else:
        gift = None

    if request.method == 'POST':
        form = GiftForm(request.POST, instance=gift)
        if form.is_valid():
            new_gift = form.save(commit=False)
            new_gift.recipient = myself
            if new_gift.url:
                new_gift.url = convert_link(new_gift.url)
            if not new_gift.pk:
                send_all_update_emails(myself)  # this probably needs to somehow be a worker or it might get slow

                analytics.track(request.user.id, 'Added a Gift', {
                    'title': new_gift.title,
                    'url': new_gift.url,
                    'type': 'self'
                    })

                new_gift.save()
            else:
                analytics.track(request.user.id, 'Edited a Gift', {
                    'gift_id': new_gift.pk,
                    'title': new_gift.title,
                    'url': new_gift.url,
                    'type': 'self'
                    })

            return HttpResponseRedirect(reverse('Gifts.views.user_home'))
    else:
        analytics.page(request.user.id, 'giftlist', 'add_gift')
        form = GiftForm(instance=gift)

    if gift_id:
        add_title = 'Edit the gift that you want to receive.'
        submit_text = 'Change'
    else:
        add_title = 'Add a new gift to your list.'
        submit_text = 'Add'

    add_description = ("Enter the details of a gift you would like to receive. "
                       "Note that you can't change this after you save it, since people will be able to immediately reserve it.")

    return render(request, 'add_item.html',
                  {'form': form,
                   'add_title': add_title,
                   'add_description': add_description,
                   'submit_text': submit_text,
                   'giftid': gift_id })
예제 #2
0
파일: views.py 프로젝트: thechild/giftlist2
def add_secret_gift(request, recipient_id):
    myself = get_person_from_user(request.user)
    recipient = get_object_or_404(Person, pk=recipient_id)

    if request.method == 'POST':
        form = GiftForm(request.POST)
        if form.is_valid():
            new_gift = form.save(commit=False)
            # clear_reserved_gifts(myself, recipient)
            new_gift.recipient = recipient
            new_gift.secret = True
            new_gift.reserved_by = myself
            new_gift.date_reserved = datetime.now()
            if new_gift.url:
                new_gift.url = convert_link(new_gift.url)
            if not new_gift.pk:
                analytics.track(request.user.id, 'Added a Gift', {
                    'title': new_gift.title,
                    'url': new_gift.url,
                    'type': 'secret'
                })
            else:
                analytics.track(
                    request.user.id, 'Edited a Gift', {
                        'gift_id': new_gift.pk,
                        'title': new_gift.title,
                        'url': new_gift.url,
                        'type': 'secret'
                    })
            new_gift.save()
            return HttpResponseRedirect(
                reverse('Gifts.views.view_user', args=(recipient.pk, )))
    else:
        analytics.page(request.user.id, 'giftlist', 'add_secret_gift')
        form = GiftForm()

    return render(
        request, 'add_item.html', {
            'form':
            form,
            'add_title':
            'Add a new gift for %s' % recipient.name(),
            'add_description':
            ('Enter the details of the gift you would like to get for %s.  '
             'No one besides you will ever see this information.' %
             recipient.name())
        })
예제 #3
0
파일: views.py 프로젝트: thechild/giftlist2
def add_secret_gift(request, recipient_id):
    myself = get_person_from_user(request.user)
    recipient = get_object_or_404(Person, pk=recipient_id)

    if request.method == 'POST':
        form = GiftForm(request.POST)
        if form.is_valid():
            new_gift = form.save(commit=False)
            # clear_reserved_gifts(myself, recipient)
            new_gift.recipient = recipient
            new_gift.secret = True
            new_gift.reserved_by = myself
            new_gift.date_reserved = datetime.now()
            if new_gift.url:
                new_gift.url = convert_link(new_gift.url)
            if not new_gift.pk:
                analytics.track(request.user.id, 'Added a Gift', {
                    'title': new_gift.title,
                    'url': new_gift.url,
                    'type': 'secret'
                    })
            else:
                analytics.track(request.user.id, 'Edited a Gift', {
                    'gift_id': new_gift.pk,
                    'title': new_gift.title,
                    'url': new_gift.url,
                    'type': 'secret'
                    })
            new_gift.save()
            return HttpResponseRedirect(reverse('Gifts.views.view_user', args=(recipient.pk,)))
    else:
        analytics.page(request.user.id, 'giftlist', 'add_secret_gift')
        form = GiftForm()

    return render(request, 'add_item.html',
                  {'form': form,
                   'add_title': 'Add a new gift for %s' % recipient.name(),
                   'add_description': ('Enter the details of the gift you would like to get for %s.  '
                                       'No one besides you will ever see this information.' % recipient.name())
                   })
예제 #4
0
파일: views.py 프로젝트: thechild/giftlist2
def add_gift(request, gift_id=None):
    myself = get_person_from_user(request.user)
    if gift_id:
        gift = get_object_or_404(Gift, pk=gift_id)
        if gift.recipient != myself:
            messages.error(request,
                           "You don't have permission to edit that gift.")
            return HttpResponseRedirect(reverse('Gifts.views.user_home'))
    else:
        gift = None

    if request.method == 'POST':
        form = GiftForm(request.POST, instance=gift)
        if form.is_valid():
            new_gift = form.save(commit=False)
            new_gift.recipient = myself
            if new_gift.url:
                new_gift.url = convert_link(new_gift.url)
            if not new_gift.pk:
                send_all_update_emails(
                    myself
                )  # this probably needs to somehow be a worker or it might get slow

                analytics.track(request.user.id, 'Added a Gift', {
                    'title': new_gift.title,
                    'url': new_gift.url,
                    'type': 'self'
                })

                new_gift.save()
            else:
                analytics.track(
                    request.user.id, 'Edited a Gift', {
                        'gift_id': new_gift.pk,
                        'title': new_gift.title,
                        'url': new_gift.url,
                        'type': 'self'
                    })

            return HttpResponseRedirect(reverse('Gifts.views.user_home'))
    else:
        analytics.page(request.user.id, 'giftlist', 'add_gift')
        form = GiftForm(instance=gift)

    if gift_id:
        add_title = 'Edit the gift that you want to receive.'
        submit_text = 'Change'
    else:
        add_title = 'Add a new gift to your list.'
        submit_text = 'Add'

    add_description = (
        "Enter the details of a gift you would like to receive. "
        "Note that you can't change this after you save it, since people will be able to immediately reserve it."
    )

    return render(
        request, 'add_item.html', {
            'form': form,
            'add_title': add_title,
            'add_description': add_description,
            'submit_text': submit_text,
            'giftid': gift_id
        })