Example #1
0
File: views.py Project: lite/djsite
def edit_post(request, post_id):
    from apps.jsjtbb.templatetags.forum_extras import forum_editable_by

    post = get_object_or_404(Post, pk=post_id)
    topic = post.topic
    if not forum_editable_by(post, request.user):
        return HttpResponseRedirect(post.get_absolute_url())
    form = build_form(EditPostForm, request, topic=topic, instance=post)
    if form.is_valid():
        post = form.save(commit=False)
        post.updated_by = request.user
        post.save()
        return HttpResponseRedirect(post.get_absolute_url())

    return {'form': form,
            'post': post,
            }
Example #2
0
File: views.py Project: lite/djsite
def reputation(request, username):
    user = get_object_or_404(User, username=username)
    form = build_form(ReputationForm,
                      request,
                      from_user=request.user,
                      to_user=user)

    if 'action' in request.GET:
        if request.user == user:
            return HttpResponseForbidden(
                u'You can not change the reputation of yourself')

        if 'post_id' in request.GET:
            sign = 0
            post_id = request.GET['post_id']
            form.fields['post'].initial = post_id
            print form.fields['post']
            if request.GET['action'] == 'plus':
                form.fields['sign'].initial = 1
            elif request.GET['action'] == 'minus':
                form.fields['sign'].initial = -1
            return {'form': form, 'TEMPLATE': 'forum/reputation_form.html'}
        else:
            raise Http404

    elif request.method == 'POST':
        if 'del_reputation' in request.POST and request.user.is_superuser:
            reputation_list = request.POST.getlist('reputation_id')
            for reputation_id in reputation_list:
                reputation = get_object_or_404(Reputation, pk=reputation_id)
                reputation.delete()
            return HttpResponseRedirect(reverse('jsjtbb:index'))
        elif form.is_valid():
            form.save()
            post_id = request.POST['post']
            post = get_object_or_404(Post, id=post_id)
            return HttpResponseRedirect(post.get_absolute_url())
        else:
            return {'form': form, 'TEMPLATE': 'forum/reputation_form.html'}
    else:
        reputations = Reputation.objects.filter(
            to_user=user).order_by('-time').select_related()
        return {
            'reputations': reputations,
            'profile': user.forum_profile,
        }
Example #3
0
File: views.py Project: lite/djsite
def edit_post(request, post_id):
    from apps.jsjtbb.templatetags.forum_extras import forum_editable_by

    post = get_object_or_404(Post, pk=post_id)
    topic = post.topic
    if not forum_editable_by(post, request.user):
        return HttpResponseRedirect(post.get_absolute_url())
    form = build_form(EditPostForm, request, topic=topic, instance=post)
    if form.is_valid():
        post = form.save(commit=False)
        post.updated_by = request.user
        post.save()
        return HttpResponseRedirect(post.get_absolute_url())

    return {
        'form': form,
        'post': post,
    }
Example #4
0
File: views.py Project: lite/djsite
def reputation(request, username):
    user = get_object_or_404(User, username=username)
    form = build_form(ReputationForm, request, from_user=request.user, to_user=user)

    if 'action' in request.GET:
        if request.user == user:
            return HttpResponseForbidden(u'You can not change the reputation of yourself')

        if 'post_id' in request.GET:
            sign = 0
            post_id = request.GET['post_id']
            form.fields['post'].initial = post_id
            print form.fields['post']
            if request.GET['action'] == 'plus':
                form.fields['sign'].initial = 1
            elif request.GET['action'] == 'minus':
                form.fields['sign'].initial = -1
            return {'form': form,
                    'TEMPLATE': 'forum/reputation_form.html'
                    }
        else:
            raise Http404

    elif request.method == 'POST':
        if 'del_reputation' in request.POST and request.user.is_superuser:
            reputation_list = request.POST.getlist('reputation_id')
            for reputation_id in reputation_list:
                    reputation = get_object_or_404(Reputation, pk=reputation_id)
                    reputation.delete()
            return HttpResponseRedirect(reverse('jsjtbb:index'))
        elif form.is_valid():
            form.save()
            post_id = request.POST['post']
            post = get_object_or_404(Post, id=post_id)
            return HttpResponseRedirect(post.get_absolute_url())
        else:
            return {'form': form,
                    'TEMPLATE': 'forum/reputation_form.html'
                    }
    else:
        reputations = Reputation.objects.filter(to_user=user).order_by('-time').select_related()
        return {'reputations': reputations,
                'profile': user.forum_profile,
               }
Example #5
0
File: views.py Project: lite/djsite
def add_post(request, forum_id, topic_id):
    forum = None
    topic = None
    posts = None

    if forum_id:
        forum = get_object_or_404(Forum, pk=forum_id)
        if not forum.category.has_access(request.user):
            return HttpResponseForbidden()
    elif topic_id:
        topic = get_object_or_404(Topic, pk=topic_id)
        posts = topic.posts.all().select_related()
        if not topic.forum.category.has_access(request.user):
            return HttpResponseForbidden()
    if topic and topic.closed:
        return HttpResponseRedirect(topic.get_absolute_url())

    ip = request.META.get('REMOTE_ADDR', None)
    form = build_form(AddPostForm,
                      request,
                      topic=topic,
                      forum=forum,
                      user=request.user,
                      ip=ip,
                      initial={'markup': request.user.forum_profile.markup})

    if 'post_id' in request.GET:
        post_id = request.GET['post_id']
        post = get_object_or_404(Post, pk=post_id)
        form.fields['body'].initial = "[quote=%s]%s[/quote]" % (post.user,
                                                                post.body)

    if form.is_valid():
        post = form.save()
        return HttpResponseRedirect(post.get_absolute_url())

    return {
        'form': form,
        'posts': posts,
        'topic': topic,
        'forum': forum,
    }
Example #6
0
File: views.py Project: lite/djsite
def misc(request):
    if 'action' in request.GET:
        action = request.GET['action']
        if action == 'markread':
            user = request.user
            PostTracking.objects.filter(user=user).update(
                last_read=datetime.now(), topics=None)
            return HttpResponseRedirect(reverse('jsjtbb:index'))

        elif action == 'report':
            if request.GET.get('post_id', ''):
                post_id = request.GET['post_id']
                post = get_object_or_404(Post, id=post_id)
                form = build_form(ReportForm,
                                  request,
                                  reported_by=request.user,
                                  post=post_id)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                    return HttpResponseRedirect(post.get_absolute_url())
                return {'form': form}

    elif 'submit' in request.POST and 'mail_to' in request.GET:
        form = MailToForm(request.POST)
        if form.is_valid():
            user = get_object_or_404(User, username=request.GET['mail_to'])
            subject = form.cleaned_data['subject']
            body = form.cleaned_data['body'] + '\n %s %s [%s]' % (
                Site.objects.get_current().domain, request.user.username,
                request.user.email)
            user.email_user(subject, body, request.user.email)
            return HttpResponseRedirect(reverse('jsjtbb:index'))

    elif 'mail_to' in request.GET:
        user = get_object_or_404(User, username=request.GET['mail_to'])
        form = MailToForm()
        return {'form': form, 'user': user, 'TEMPLATE': 'forum/mail_to.html'}
Example #7
0
File: views.py Project: lite/djsite
def add_post(request, forum_id, topic_id):
    forum = None
    topic = None
    posts = None

    if forum_id:
        forum = get_object_or_404(Forum, pk=forum_id)
        if not forum.category.has_access(request.user):
            return HttpResponseForbidden()
    elif topic_id:
        topic = get_object_or_404(Topic, pk=topic_id)
        posts = topic.posts.all().select_related()
        if not topic.forum.category.has_access(request.user):
            return HttpResponseForbidden()
    if topic and topic.closed:
        return HttpResponseRedirect(topic.get_absolute_url())
    
    ip = request.META.get('REMOTE_ADDR', None)
    form = build_form(AddPostForm, request, topic=topic, forum=forum,
                      user=request.user, ip=ip,
                      initial={'markup': request.user.forum_profile.markup})

    if 'post_id' in request.GET:
        post_id = request.GET['post_id']
        post = get_object_or_404(Post, pk=post_id)
        form.fields['body'].initial = "[quote=%s]%s[/quote]" % (post.user, post.body)

    if form.is_valid():
        post = form.save();
        return HttpResponseRedirect(post.get_absolute_url())

    return {'form': form,
            'posts': posts,
            'topic': topic,
            'forum': forum,
            }
Example #8
0
File: views.py Project: lite/djsite
def misc(request):
    if 'action' in request.GET:
        action = request.GET['action']
        if action =='markread':
            user = request.user
            PostTracking.objects.filter(user=user).update(last_read=datetime.now(), topics=None)
            return HttpResponseRedirect(reverse('jsjtbb:index'))

        elif action == 'report':
            if request.GET.get('post_id', ''):
                post_id = request.GET['post_id']
                post = get_object_or_404(Post, id=post_id)
                form = build_form(ReportForm, request, reported_by=request.user, post=post_id)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                    return HttpResponseRedirect(post.get_absolute_url())
                return {'form':form}

    elif 'submit' in request.POST and 'mail_to' in request.GET:
        form = MailToForm(request.POST)
        if form.is_valid():
            user = get_object_or_404(User, username=request.GET['mail_to'])
            subject = form.cleaned_data['subject']
            body = form.cleaned_data['body'] + '\n %s %s [%s]' % (Site.objects.get_current().domain,
                                                                  request.user.username,
                                                                  request.user.email)
            user.email_user(subject, body, request.user.email)
            return HttpResponseRedirect(reverse('jsjtbb:index'))

    elif 'mail_to' in request.GET:
        user = get_object_or_404(User, username=request.GET['mail_to'])
        form = MailToForm()
        return {'form':form,
                'user': user,
               'TEMPLATE': 'forum/mail_to.html'
               }
Example #9
0
File: views.py Project: lite/djsite
def user(request, username):
    user = get_object_or_404(User, username=username)
    if request.user.is_authenticated() and user == request.user or request.user.is_superuser:
        if 'section' in request.GET:
            section = request.GET['section']
            if section == 'privacy':
                form = build_form(PrivacyProfileForm, request, instance=user.forum_profile)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                return {'active_menu':'privacy',
                        'profile': user,
                        'form': form,
                        'TEMPLATE': 'forum/profile/profile_privacy.html'
                       }
            elif section == 'display':
                form = build_form(DisplayProfileForm, request, instance=user.forum_profile)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                return {'active_menu':'display',
                        'profile': user,
                        'form': form,
                        'TEMPLATE': 'forum/profile/profile_display.html'
                       }
            elif section == 'personality':
                form = build_form(PersonalityProfileForm, request, instance=user.forum_profile)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                return {'active_menu':'personality',
                        'profile': user,
                        'form': form,
                        'TEMPLATE': 'forum/profile/profile_personality.html'
                        }
            elif section == 'messaging':
                form = build_form(MessagingProfileForm, request, instance=user.forum_profile)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                return {'active_menu':'messaging',
                        'profile': user,
                        'form': form,
                        'TEMPLATE': 'forum/profile/profile_messaging.html'
                       }
            elif section == 'personal':
                form = build_form(PersonalProfileForm, request, instance=user.forum_profile, user=user)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                return {'active_menu':'personal',
                        'profile': user,
                        'form': form,
                        'TEMPLATE': 'forum/profile/profile_personal.html'
                       }
            elif section == 'essentials':
                form = build_form(EssentialsProfileForm, request, instance=user.forum_profile, 
                                  user_view=user, user_request=request.user)
                if request.method == 'POST' and form.is_valid():
                    profile = form.save()
                    set_language(request, profile.language)
                    return HttpResponseRedirect(reverse('jsjtbb:forum_profile', args=[user.username]))
                    
                return {'active_menu':'essentials',
                        'profile': user,
                        'form': form,
                        'TEMPLATE': 'forum/profile/profile_essentials.html'
                        }
                
        elif 'action' in request.GET:
            action = request.GET['action']
            if action == 'upload_avatar':
                form = build_form(UploadAvatarForm, request, instance=user.forum_profile)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                    return HttpResponseRedirect(reverse('jsjtbb:forum_profile', args=[user.username]))
                return {'form': form,
                        'avatar_width': forum_settings.AVATAR_WIDTH,
                        'avatar_height': forum_settings.AVATAR_HEIGHT,
                        'TEMPLATE': 'forum/upload_avatar.html'
                       }
            elif action == 'delete_avatar':
                profile = get_object_or_404(Profile, user=request.user)
                profile.avatar = None
                profile.save()
                return HttpResponseRedirect(reverse('jsjtbb:forum_profile', args=[user.username]))
         
        else:
            form = build_form(EssentialsProfileForm, request, instance=user.forum_profile, 
                                  user_view=user, user_request=request.user)
            if request.method == 'POST' and form.is_valid():
                profile = form.save()
                set_language(request, profile.language)
                return HttpResponseRedirect(reverse('jsjtbb:forum_profile', args=[user.username]))
            return {'active_menu':'essentials',
                    'profile': user,
                    'form': form,
                    'TEMPLATE': 'forum/profile/profile_essentials.html'
                   }
            
    else:
        topic_count = Topic.objects.filter(user=user).count()
        if user.forum_profile.post_count < forum_settings.POST_USER_SEARCH and not request.user.is_authenticated():
            #FIXME: problem with redirect to unicoded url; blocker - django ticket #11522
            return HttpResponseRedirect(reverse('user_signin') + '?next=%s' % request.path) 
        return {'profile': user,
                'topic_count': topic_count,
               }
Example #10
0
File: views.py Project: lite/djsite
def user(request, username):
    user = get_object_or_404(User, username=username)
    if request.user.is_authenticated(
    ) and user == request.user or request.user.is_superuser:
        if 'section' in request.GET:
            section = request.GET['section']
            if section == 'privacy':
                form = build_form(PrivacyProfileForm,
                                  request,
                                  instance=user.forum_profile)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                return {
                    'active_menu': 'privacy',
                    'profile': user,
                    'form': form,
                    'TEMPLATE': 'forum/profile/profile_privacy.html'
                }
            elif section == 'display':
                form = build_form(DisplayProfileForm,
                                  request,
                                  instance=user.forum_profile)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                return {
                    'active_menu': 'display',
                    'profile': user,
                    'form': form,
                    'TEMPLATE': 'forum/profile/profile_display.html'
                }
            elif section == 'personality':
                form = build_form(PersonalityProfileForm,
                                  request,
                                  instance=user.forum_profile)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                return {
                    'active_menu': 'personality',
                    'profile': user,
                    'form': form,
                    'TEMPLATE': 'forum/profile/profile_personality.html'
                }
            elif section == 'messaging':
                form = build_form(MessagingProfileForm,
                                  request,
                                  instance=user.forum_profile)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                return {
                    'active_menu': 'messaging',
                    'profile': user,
                    'form': form,
                    'TEMPLATE': 'forum/profile/profile_messaging.html'
                }
            elif section == 'personal':
                form = build_form(PersonalProfileForm,
                                  request,
                                  instance=user.forum_profile,
                                  user=user)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                return {
                    'active_menu': 'personal',
                    'profile': user,
                    'form': form,
                    'TEMPLATE': 'forum/profile/profile_personal.html'
                }
            elif section == 'essentials':
                form = build_form(EssentialsProfileForm,
                                  request,
                                  instance=user.forum_profile,
                                  user_view=user,
                                  user_request=request.user)
                if request.method == 'POST' and form.is_valid():
                    profile = form.save()
                    set_language(request, profile.language)
                    return HttpResponseRedirect(
                        reverse('jsjtbb:forum_profile', args=[user.username]))

                return {
                    'active_menu': 'essentials',
                    'profile': user,
                    'form': form,
                    'TEMPLATE': 'forum/profile/profile_essentials.html'
                }

        elif 'action' in request.GET:
            action = request.GET['action']
            if action == 'upload_avatar':
                form = build_form(UploadAvatarForm,
                                  request,
                                  instance=user.forum_profile)
                if request.method == 'POST' and form.is_valid():
                    form.save()
                    return HttpResponseRedirect(
                        reverse('jsjtbb:forum_profile', args=[user.username]))
                return {
                    'form': form,
                    'avatar_width': forum_settings.AVATAR_WIDTH,
                    'avatar_height': forum_settings.AVATAR_HEIGHT,
                    'TEMPLATE': 'forum/upload_avatar.html'
                }
            elif action == 'delete_avatar':
                profile = get_object_or_404(Profile, user=request.user)
                profile.avatar = None
                profile.save()
                return HttpResponseRedirect(
                    reverse('jsjtbb:forum_profile', args=[user.username]))

        else:
            form = build_form(EssentialsProfileForm,
                              request,
                              instance=user.forum_profile,
                              user_view=user,
                              user_request=request.user)
            if request.method == 'POST' and form.is_valid():
                profile = form.save()
                set_language(request, profile.language)
                return HttpResponseRedirect(
                    reverse('jsjtbb:forum_profile', args=[user.username]))
            return {
                'active_menu': 'essentials',
                'profile': user,
                'form': form,
                'TEMPLATE': 'forum/profile/profile_essentials.html'
            }

    else:
        topic_count = Topic.objects.filter(user=user).count()
        if user.forum_profile.post_count < forum_settings.POST_USER_SEARCH and not request.user.is_authenticated(
        ):
            #FIXME: problem with redirect to unicoded url; blocker - django ticket #11522
            return HttpResponseRedirect(
                reverse('user_signin') + '?next=%s' % request.path)
        return {
            'profile': user,
            'topic_count': topic_count,
        }