Beispiel #1
0
def maker_create(request):
    if not is_admin(request):
        raise Http404

    if request.method == "POST":
        form = CreateMakerForm(request.POST)

        if form.is_valid():

            username = form.cleaned_data['username']
            if User.objects.filter(username=username):
                return render(request, 'catalog/maker_create.html', {
                    'static_blob': static_blob,
                    'existing_username': True
                })

            user = User()
            user.username = form.cleaned_data['username']
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.email = form.cleaned_data['email']
            user.save()

            user_profile = UserProfile()
            user_profile.added_time = timezone.now()
            user_profile.user = user
            user_profile.save()

            if form.cleaned_data['image_url']:
                image = Image()
                image.user = user
                image.large_url = form.cleaned_data['image_url']
                image.added_time = timezone.now()
                image.save()
                user_profile.profile_pic = image
                user_profile.save()

            return HttpResponseRedirect(reverse('catalog:maker_profile',
                                                args=[user.username]))

    context = {
        'static_blob': static_blob
    }

    return render(request, 'catalog/maker_create.html', context)