Пример #1
0
def create_shed(request, template_name='sheds/create_shed.html'):
    """
    Create a new shed with data from request and add it to database.
    """
    
    if request.method == 'POST':
        form = ShedForm(request.POST, request.FILES)
        if form.is_valid():
            image = None
            if form.cleaned_data['image']:
                image=form.cleaned_data['image']
            shed = Shed(
                name=form.cleaned_data['name'],
                street=form.cleaned_data['street'],
                city=form.cleaned_data['city'],
                state=form.cleaned_data['state'],
                postal_code = form.cleaned_data['postal_code'],
                owner=request.user,
                image=image,
            )
            shed.save()
            if image:
                shed.image.name = rename_file(shed)
                shed.save()
            activity_msg = "Created a new shed (%s)" % (shed.name,)
            Activity.objects.create(user=request.user,
                                                    message=activity_msg)     
            url = reverse('shed_detail', kwargs={'shed_id':shed.id})
            return HttpResponseRedirect(url)
    else: 
        form = ShedForm(initial={'state':'NY'})

    return render(request, template_name, {'form': form})
Пример #2
0
def user_registered_callback(sender, user, request, **kwargs):
    """
    Save name to user and automatically create shed and profile named
    """
    user.first_name = request.POST["first_name"]
    user.last_name = request.POST["last_name"]
    user.save()
    shed = Shed(name="%s's home" % user.username,
                owner=user,
                street=request.POST["street"],
                city=request.POST["city"],
                state=request.POST["state"],
                postal_code=request.POST["postal_code"])
    shed.save()
    profile = UserProfile(user=user, home_shed=shed)
    stats = Stats()
    stats.save()
    profile.stats = stats
    profile.save()
Пример #3
0
def user_registered_callback(sender, user, request, **kwargs):
    """
    Save name to user and automatically create shed and profile named
    """
    user.first_name = request.POST["first_name"]
    user.last_name = request.POST["last_name"]
    user.save()
    shed = Shed( 
            name= "%s's home" % user.username,
            owner=user,
            street=request.POST["street"],
            city=request.POST["city"],
            state=request.POST["state"],
            postal_code=request.POST["postal_code"]
        )
    shed.save()
    profile = UserProfile(user=user, home_shed=shed)
    stats = Stats()
    stats.save()
    profile.stats = stats
    profile.save()
Пример #4
0
def create_shed(request, template_name='sheds/create_shed.html'):
    """
    Create a new shed with data from request and add it to database.
    """

    if request.method == 'POST':
        form = ShedForm(request.POST, request.FILES)
        if form.is_valid():
            image = None
            if form.cleaned_data['image']:
                image = form.cleaned_data['image']
            shed = Shed(
                name=form.cleaned_data['name'],
                street=form.cleaned_data['street'],
                city=form.cleaned_data['city'],
                state=form.cleaned_data['state'],
                postal_code=form.cleaned_data['postal_code'],
                owner=request.user,
                image=image,
            )
            shed.save()
            if image:
                shed.image.name = rename_file(shed)
                shed.save()
            activity_msg = "Created a new shed (%s)" % (shed.name, )
            Activity.objects.create(user=request.user, message=activity_msg)
            url = reverse('shed_detail', kwargs={'shed_id': shed.id})
            return HttpResponseRedirect(url)
    else:
        form = ShedForm(initial={'state': 'NY'})

    return render(request, template_name, {'form': form})