Пример #1
0
def suggest(request):
    error_message = None
    env = common_env()

    if request.method == 'POST':
        form = SuggestCharityForm(request.POST)
        if form.is_valid():
            try:
                charity = Charity(
                        name=form.cleaned_data['name'],
                        url=form.cleaned_data['url'],
                        description=form.cleaned_data['description'],
                        suggester=request.user,
                        status=STATUS.PENDING)
                charity.save()
            except IntegrityError:
                error_message = \
                        "That charity has already been suggested, thanks."
            else:
                return render(request, 'charities/suggest_done.html', env)
    else:
        form = SuggestCharityForm()

    env['form'] = form
    env['error_message'] = error_message
    return render(request, 'charities/suggest.html', env)
Пример #2
0
def sign_in(request):
    error_message = None

    if request.method == "POST":
        form = SignInForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data["user_name"], password=form.cleaned_data["password"])
            if user:
                if user.is_active:
                    login(request, user)
                    next_url = form.cleaned_data["next"]
                    if not next_url.startswith("/"):
                        raise PermissionDenied
                    return HttpResponseRedirect(next_url)
                else:
                    error_message = "Account disabled"
            else:
                error_message = "Bad username or password"
    else:
        next_url = request.GET.get("next") or "/users"
        form = SignInForm(initial={"next": next_url})

    env = common_env()
    env["form"] = form
    env["error_message"] = error_message
    return render(request, "users/signin.html", env)
Пример #3
0
def sign_in(request):
    error_message = None

    if request.method == 'POST':
        form = SignInForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data['user_name'],
                                password=form.cleaned_data['password'])
            if user:
                if user.is_active:
                    login(request, user)
                    next_url = form.cleaned_data['next']
                    if not next_url.startswith('/'):
                        raise PermissionDenied
                    return HttpResponseRedirect(next_url)
                else:
                    error_message = "Account disabled"
            else:
                error_message = "Bad username or password"
    else:
        next_url = request.GET.get('next') or reverse('blog-home')
        form = SignInForm(initial={'next': next_url})

    env = common_env()
    env['form'] = form
    env['error_message'] = error_message
    return render(request, 'users/signin.html', env)
Пример #4
0
def profile(request, username):
    user = User.objects.get(username=username)
    user_profile = UserProfile.objects.get(user=user)
    env = common_env()
    env['user_'] = user
    env['user_profile'] = user_profile
    return render(request, 'users/profile.html', env)
Пример #5
0
def suggest(request):
    error_message = None
    env = common_env()

    if request.method == 'POST':
        form = SuggestCharityForm(request.POST)
        if form.is_valid():
            try:
                charity = Charity(name=form.cleaned_data['name'],
                                  url=form.cleaned_data['url'],
                                  description=form.cleaned_data['description'],
                                  suggester=request.user,
                                  status=STATUS.PENDING)
                charity.save()
            except IntegrityError:
                error_message = \
                        "That charity has already been suggested, thanks."
            else:
                return render(request, 'charities/suggest_done.html', env)
    else:
        form = SuggestCharityForm()

    env['form'] = form
    env['error_message'] = error_message
    return render(request, 'charities/suggest.html', env)
Пример #6
0
def profile(request, username):
    user = User.objects.get(username=username)
    user_profile = UserProfile.objects.get(user=user)
    env = common_env()
    env['user_'] = user
    env['user_profile'] = user_profile
    return render(request, 'users/profile.html', env)
Пример #7
0
def tag(request, slug):
    entries = Entry.objects.filter(
        tags__slug=slug, status=STATUS.PUBLISHED).order_by('pub_date')
    env = common_env()
    env['entries'] = entries
    env['slug'] = slug
    return render(request, 'blog/tag.html', env)
Пример #8
0
def tag(request, slug):
    entries = Entry.objects.filter(tags__slug=slug,
            status=STATUS.PUBLISHED).order_by('pub_date')
    env = common_env()
    env['entries'] = entries
    env['slug'] = slug
    return render(request, 'blog/tag.html', env)
Пример #9
0
def sign_in(request):
    error_message = None

    if request.method == 'POST':
        form = SignInForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data['user_name'],
                    password=form.cleaned_data['password'])
            if user:
                if user.is_active:
                    login(request, user)
                    next_url = form.cleaned_data['next']
                    if not next_url.startswith('/'):
                        raise PermissionDenied
                    return HttpResponseRedirect(next_url)
                else:
                    error_message = "Account disabled"
            else:
                error_message = "Bad username or password"
    else:
        next_url = request.GET.get('next') or reverse('blog-home')
        form = SignInForm(initial={'next': next_url})

    env = common_env()
    env['form'] = form
    env['error_message'] = error_message
    return render(request, 'users/signin.html', env)
Пример #10
0
def page(request, path):
    if request.user.is_superuser:
        page = get_object_or_404(Page, path=path)
    else:
        page = get_object_or_404(Page, path=path, status=STATUS.PUBLISHED)
    env = common_env()
    env['page'] = page
    return render(request, 'wiki/page.html', env)
Пример #11
0
def index(request):
    all_entries = Entry.objects.filter(status=STATUS.PUBLISHED).\
            order_by('-pub_date')
    page = request.GET.get('page', 1)

    env = common_env()
    env['entries'] = _get_paginated_entries(all_entries, page, 5)
    env['formats'] = FORMAT
    return render(request, 'blog/index.html', env)
Пример #12
0
def entry(request, entry_id):
    if request.user.is_superuser:
        entry = Entry.objects.get(pk=entry_id)
    else:
        entry = Entry.objects.get(pk=entry_id, status=STATUS.PUBLISHED)
    env = common_env()
    env['entry'] = entry
    env['formats'] = FORMAT
    return render(request, 'blog/entry.html', env)
Пример #13
0
def tag(request, slug):
    all_entries = Entry.objects.filter(tags__slug=slug,
            status=STATUS.PUBLISHED).order_by('-pub_date')
    page = request.GET.get('page', 1)

    env = common_env()
    env['entries'] = _get_paginated_entries(all_entries, page, 10)
    env['slug'] = slug
    return render(request, 'blog/tag.html', env)
Пример #14
0
def edit_profile(request, username):
    user = User.objects.get(username=username)
    user_profile = UserProfile.objects.get(user=user)
    message = None

    if request.user != user:
        raise PermissionDenied

    elif request.method == 'POST':
        form = UserProfileForm(request.POST)
        if form.is_valid():
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.email = form.cleaned_data['email']

            if form.cleaned_data['password']:
                user.set_password(form.cleaned_data['password'])

            user_profile.alternate_email = form.cleaned_data['alternate_email']
            user_profile.phone = form.cleaned_data['phone']
            user_profile.tshirt = form.cleaned_data['tshirt']
            user_profile.diet = form.cleaned_data['diet']
            user_profile.location = form.cleaned_data['location']
            user_profile.description = form.cleaned_data['description']
            user_profile.notify_by_email = form.cleaned_data['notify_by_email']

            user.save()
            user_profile.save()

            message = 'Updated profile.'

    else:
        form = UserProfileForm(
            initial={
                'first_name': user.first_name,
                'last_name': user.last_name,
                'email': user.email,
                'alternate_email': user_profile.alternate_email,
                'phone': user_profile.phone,
                'tshirt': user_profile.tshirt,
                'diet': user_profile.diet,
                'location': user_profile.location,
                'description': user_profile.description,
                'notify_by_email': user_profile.notify_by_email,
            })

    env = common_env()
    env['form'] = form
    env['user_'] = user
    env['message'] = message
    env['user_profile'] = user_profile
    return render(request, 'users/edit_profile.html', env)
Пример #15
0
def edit_profile(request, username):
    user = User.objects.get(username=username)
    user_profile = UserProfile.objects.get(user=user)
    message = None

    if request.user != user:
        raise PermissionDenied

    elif request.method == 'POST':
        form = UserProfileForm(request.POST)
        if form.is_valid():
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.email = form.cleaned_data['email']

            if form.cleaned_data['password']:
                user.set_password(form.cleaned_data['password'])

            user_profile.alternate_email = form.cleaned_data['alternate_email']
            user_profile.phone = form.cleaned_data['phone']
            user_profile.tshirt = form.cleaned_data['tshirt']
            user_profile.diet = form.cleaned_data['diet']
            user_profile.location = form.cleaned_data['location']
            user_profile.description = form.cleaned_data['description']
            user_profile.notify_by_email = form.cleaned_data['notify_by_email']

            user.save()
            user_profile.save()

            message = 'Updated profile.'

    else:
        form = UserProfileForm(initial={
                'first_name': user.first_name,
                'last_name': user.last_name,
                'email': user.email,
                'alternate_email': user_profile.alternate_email,
                'phone': user_profile.phone,
                'tshirt': user_profile.tshirt,
                'diet': user_profile.diet,
                'location': user_profile.location,
                'description': user_profile.description,
                'notify_by_email': user_profile.notify_by_email,
        })

    env = common_env()
    env['form'] = form
    env['user_'] = user
    env['message'] = message
    env['user_profile'] = user_profile
    return render(request, 'users/edit_profile.html', env)
Пример #16
0
def edit_profile(request, username):
    user = User.objects.get(username=username)
    user_profile = UserProfile.objects.get(user=user)
    message = None

    if request.user != user:
        raise PermissionDenied

    elif request.method == "POST":
        form = UserProfileForm(request.POST)
        if form.is_valid():
            user.first_name = form.cleaned_data["first_name"]
            user.last_name = form.cleaned_data["last_name"]
            user.email = form.cleaned_data["email"]

            if form.cleaned_data["password"]:
                user.set_password(form.cleaned_data["password"])

            user_profile.tshirt = form.cleaned_data["tshirt"]
            user_profile.diet = form.cleaned_data["diet"]
            user_profile.location = form.cleaned_data["location"]
            user_profile.description = form.cleaned_data["description"]
            user_profile.notify_by_email = form.cleaned_data["notify_by_email"]

            user.save()
            user_profile.save()

            message = "Updated profile."

    else:
        form = UserProfileForm(
            initial={
                "first_name": user.first_name,
                "last_name": user.last_name,
                "email": user.email,
                "tshirt": user_profile.tshirt,
                "diet": user_profile.diet,
                "location": user_profile.location,
                "description": user_profile.description,
                "notify_by_email": user_profile.notify_by_email,
            }
        )

    env = common_env()
    env["form"] = form
    env["user_"] = user
    env["message"] = message
    env["user_profile"] = user_profile
    return render(request, "users/edit_profile.html", env)
Пример #17
0
def sign_up(request):
    error_message = None

    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            # Create the user
            try:
                user = User.objects.create_user(form.cleaned_data['user_name'],
                                                form.cleaned_data['email'],
                                                form.cleaned_data['password'])
            except IntegrityError:
                error_message = "That username is not available."
            else:
                user.first_name = form.cleaned_data['first_name']
                user.last_name = form.cleaned_data['last_name']
                user.save()

                # Create the user profile
                user_profile = UserProfile(
                    user=user,
                    alternate_email=form.cleaned_data['alternate_email'],
                    phone=form.cleaned_data['phone'],
                    tshirt=form.cleaned_data['tshirt'],
                    diet=form.cleaned_data['diet'],
                    location=form.cleaned_data['location'],
                    description=form.cleaned_data['description'],
                    notify_by_email=form.cleaned_data['notify_by_email'])
                user_profile.save()

                # Log the user in
                user = authenticate(username=user.username,
                                    password=form.cleaned_data['password'])
                login(request, user)

                return HttpResponseRedirect(
                    reverse('users-profile',
                            args=[user.username]))  # Redirect after POST
    else:
        form = SignUpForm()

    env = common_env()
    env['form'] = form
    env['error_message'] = error_message
    return render(request, 'users/signup.html', env)
Пример #18
0
def sign_up(request):
    error_message = None

    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            # Create the user
            try:
                user = User.objects.create_user(
                        form.cleaned_data['user_name'],
                        form.cleaned_data['email'],
                        form.cleaned_data['password'])
            except IntegrityError:
                error_message = "That username is not available."
            else:
                user.first_name = form.cleaned_data['first_name']
                user.last_name = form.cleaned_data['last_name']
                user.save()

                # Create the user profile
                user_profile = UserProfile(
                        user=user,
                        alternate_email=form.cleaned_data['alternate_email'],
                        phone=form.cleaned_data['phone'],
                        tshirt=form.cleaned_data['tshirt'],
                        diet=form.cleaned_data['diet'],
                        location=form.cleaned_data['location'],
                        description=form.cleaned_data['description'],
                        notify_by_email=form.cleaned_data['notify_by_email'])
                user_profile.save()

                # Log the user in
                user = authenticate(username=user.username,
                        password=form.cleaned_data['password'])
                login(request, user)

                return HttpResponseRedirect(reverse('users-profile', args=[user.username])) # Redirect after POST
    else:
        form = SignUpForm()

    env = common_env()
    env['form'] = form
    env['error_message'] = error_message
    return render(request, 'users/signup.html', env)
Пример #19
0
def sign_up(request):
    error_message = None

    if request.method == "POST":
        form = SignUpForm(request.POST)
        if form.is_valid():
            # Create the user
            try:
                user = User.objects.create_user(
                    form.cleaned_data["user_name"], form.cleaned_data["email"], form.cleaned_data["password"]
                )
            except IntegrityError:
                error_message = "That username is not available."
            else:
                user.first_name = form.cleaned_data["first_name"]
                user.last_name = form.cleaned_data["last_name"]
                user.save()

                # Create the user profile
                user_profile = UserProfile(
                    user=user,
                    tshirt=form.cleaned_data["tshirt"],
                    diet=form.cleaned_data["diet"],
                    location=form.cleaned_data["location"],
                    description=form.cleaned_data["description"],
                    notify_by_email=form.cleaned_data["notify_by_email"],
                )
                user_profile.save()

                # Log the user in
                user = authenticate(username=user.username, password=form.cleaned_data["password"])
                login(request, user)

                return HttpResponseRedirect("/users")  # Redirect after POST
    else:
        form = SignUpForm()

    env = common_env()
    env["form"] = form
    env["error_message"] = error_message
    return render(request, "users/signup.html", env)
Пример #20
0
def index(request):
    users = User.objects.exclude(last_name='', first_name='').\
            order_by('last_name', 'first_name', 'username')
    env = common_env()
    env['users'] = users
    return render(request, 'users/index.html', env)
Пример #21
0
def index(request):
    users = User.objects.exclude(last_name='', first_name='').\
            order_by('last_name', 'first_name', 'username')
    env = common_env()
    env['users'] = users
    return render(request, 'users/index.html', env)
Пример #22
0
def index(request):
    charities = Charity.objects.filter(status=STATUS.APPROVED).order_by("name")
    env = common_env()
    env['charities'] = charities
    return render(request, 'charities/index.html', env)
Пример #23
0
def index(request):
    charities = Charity.objects.filter(status=STATUS.APPROVED).order_by("name")
    env = common_env()
    env['charities'] = charities
    return render(request, 'charities/index.html', env)
Пример #24
0
def sign_out(request):
    logout(request)
    env = common_env()
    return render(request, 'users/signout.html', env)
Пример #25
0
def entry(request, entry_id):
    entry = Entry.objects.get(pk=entry_id, status=STATUS.PUBLISHED)
    env = common_env()
    env['entry'] = entry
    return render(request, 'blog/entry.html', env)
Пример #26
0
def index(request):
    latest_entries = Entry.objects.filter(status=STATUS.PUBLISHED).\
            order_by('-pub_date')[:5]
    env = common_env()
    env['latest_entries'] = latest_entries
    return render(request, 'blog/index.html', env)
Пример #27
0
def sign_out(request):
    logout(request)
    env = common_env()
    return render(request, 'users/signout.html', env)
Пример #28
0
def index(request):
    users = User.objects.exclude(last_name="", first_name="").order_by("last_name", "first_name", "username")
    env = common_env()
    env["users"] = users
    return render(request, "users/index.html", env)
Пример #29
0
def index(request):
    latest_entries = Entry.objects.filter(status=STATUS.PUBLISHED).\
            order_by('-pub_date')[:5]
    env = common_env()
    env['latest_entries'] = latest_entries
    return render(request, 'blog/index.html', env)
Пример #30
0
def entry(request, entry_id):
    entry = Entry.objects.get(pk=entry_id, status=STATUS.PUBLISHED)
    env = common_env()
    env['entry'] = entry
    return render(request, 'blog/entry.html', env)