view apps/profile/views.py @ 151:c7be7def8b57

Bundles! (basic functionality) Changes made in this commit: * Added new dependencies (see pip-requirements) * Added new dependency and setup information to README * Deleted the included mptt app (in apps/mptt) in favour of just adding the dependency to pip-requirements (makes it easier to update, etc) * Changed the import convention to use `from apps.bundle.models import Bundle` rather than `from agora.apps.bundle.models import Bundle` because Celery was having problems with the latter style. Everything should still work. * Moved the syntax-highlighting and related code for snippets into separate HTML files so that they can be used by the bundle app And, of course, the ability to upload bundles. But wait! There's more! Changes still to come, for only $19.95 a month: * Bundle versioning * Automatic license integration (i.e. adding headers to files) * The ability to download bundles (zip, tar, etc) * Rating bundles * And much, much more! Batteries not included.
author dellsystem <ilostwaldo@gmail.com>
date Mon, 15 Oct 2012 00:52:00 -0400
parents 5ab229c9d348
children
line wrap: on
line source

from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required

from apps.free_license.models import FreeLicense
from apps.bundle.models import Bundle
from apps.snippet.models import Snippet
from apps.profile.models import Profile
from apps.profile.forms import UserForm, ProfileForm


def showprofile(request, username):
    user = get_object_or_404(User, username=username)
    profile = user.get_profile()

    if user.first_name or user.last_name:
        name = user.get_full_name()
    else:
        name = user.username

    b = Bundle.objects.filter(uploader=user)
    s = Snippet.objects.filter(author=user)

    context = {
        'profile': user.get_profile,
        'name': name,
        'bundles': Bundle.objects.filter(uploader=user),
        'snippets': Snippet.objects.filter(author=user),
    }

    return render(request, 'profile/user.djhtml', context)


@login_required
def editprofile(request):
    user = request.user
    profile = user.get_profile()

    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=user)
        profile_form = ProfileForm(request.POST, instance=profile)

        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            return redirect(user)
    else:
        user_form = UserForm(instance=user)
        profile_form = ProfileForm(instance=profile)

    context = {
        'profile': profile,
        'user_form': user_form,
        'profile_form': profile_form,
    }

    return render(request, 'profile/edit-user.djhtml', context)