Esempio n. 1
0
def login_view(request):
    # username = request.POST['username']
    # password = request.POST['password']
    # user = authenticate(username=username, password=password)
    if request.method == "POST":
        request.session.set_test_cookie()
        form = forms.AuthenticationForm(request, data=request.POST)
        if form.is_valid():
            user = form.get_user()
            UserSession.objects.get(session_key=request.session.session_key).delete()
            login(request, user)
            referer = request.META.get("HTTP_REFERER")
            ## create empty profile if missing
            try:
                profile = UserProfile.objects.get(user=request.user)
            except:
                if user.is_staff:
                    user.groups.add(Group.objects.get(name="Administrator"))
                    profile = UserProfile()
                    profile.user = request.user
                    profile.posts = 0
                    profile.threads = 0
                    profile.activate = "T"
                    profile.banned = False
                    profile.theme = Theme.objects.filter(default=True)[0]
                    profile.save()
                    user.save()
            messages.add_message(request, messages.INFO, "Login successfull!")
            # return redirect(urlresolvers.reverse('board.views.index'))
            return redirect(referer)
            # return render_to_response('user/login_successful.html',{'referer':referer},context_instance=RequestContext(request))
        return render_to_response("user/login_error.html", {"form": form}, context_instance=RequestContext(request))
    else:
        form = forms.AuthenticationForm(request)
        return render_to_response("user/login.html", {"form": form}, context_instance=RequestContext(request))
Esempio n. 2
0
def create_post(request,thread_id):
    can_post = False
    #try:
    thread = Thread.objects.get(pk=thread_id)
    groups = []
    if (request.user.id is not None):
        groups =  request.user.groups.all()
    else:
        group = auth.models.Group.objects.get(name='Gast')
        groups.append(group)
    for right in thread.board.boardrights_set.all():
        if right.group in groups and right.can_post:
            can_post = True
    if not can_post:
        return HttpResponseForbidden()
    #except:
    #    raise Http404
    quote_id = request.GET.get('quote')
    if (request.method == "GET"):
        name = "Re: "+thread.name
        options = {'name':name,}
        if (quote_id):
            quote = Post.objects.get(pk = quote_id)

            options['text'] ="[quote]%s[/quote]"%( quote.text)
        if (request.user.id is None):
            f_post = PostGuestForm(initial=options)
        else:
            f_post = PostForm(initial=options)
    else:
        if 'preview' in request.POST:
            # show a preview
            f_post = PostForm(data=request.POST)
            post = f_post.save(commit=False)
            if(f_post.is_valid()):          
                return render_to_response('create_post.html',{'f_post':f_post,'thread_id':thread_id,'preview':True,'preview_post':post},context_instance=RequestContext(request))
        else:
            if (request.user.id is None):
                f_post = PostGuestForm(request.POST)
            else:
                f_post = PostForm(request.POST)
            if(f_post.is_valid()):
                thread = Thread.objects.get(pk=thread_id)
                post = f_post.save(commit=False)
                post.thread = thread
                if (request.user.id is not None):
                    post.user = request.user
                post.save()
                thread.posts = thread.posts+1
                thread.save()
                #board=Board.objects.get()
                thread.board.posts = thread.board.posts + 1
                thread.board.save()
                if (request.user.id is not None):
                    profile = request.user.profile
                    profile.posts=profile.posts+1
                    profile.save()
                messages.add_message(request, messages.INFO, _('This post was successfully created.'))
                return redirect(reverse('board.views.show_thread',args=[post.thread.id,post.thread.get_url_name()]))
    return render_to_response('create_post.html',{'f_post':f_post,'thread_id':thread_id},context_instance=RequestContext(request))
Esempio n. 3
0
def downloads(request,cat_id=None):
    try:
        if (cat_id is None):
            categories = DownloadCategory.objects.filter(visible=True,parent=None).order_by('name')
            return render_to_response('cms/dl_cats.html',{'cats':categories,},context_instance=RequestContext(request))
        else:
            category = DownloadCategory.objects.get(pk=cat_id)
            return render_to_response('cms/show_cat.html',{'category':category,},context_instance=RequestContext(request))
    except:
        raise Http404
Esempio n. 4
0
def gallery(request,gall_id=None,gall_name=None):
    try:
        if gall_id is None:
            gallery = Gallery.objects.filter(show=True,parent=None).order_by('name')
            return render_to_response('cms/show_gallery.html',{'gallery':gallery},context_instance=RequestContext(request))
        else:
            gallery = Gallery.objects.get(pk = gall_id)
            return render_to_response('cms/gallery.html',{'gallery':gallery},context_instance=RequestContext(request))
    except Exception as e:
        print(e)
        raise Http404
Esempio n. 5
0
def create(request):
    if(request.method == "GET"):
        form = MessageForm()
        return render_to_response('msg/create.html',{'form':form},context_instance=RequestContext(request))
    else:
        form = MessageForm(request.POST)
        if(form.is_valid()):
            message= form.save(commit=False)
            message.sender = request.user
            message.time = datetime.now()
            message.save()
            messages.add_message(request, messages.INFO, 'Private message was sent to the user.')
            return redirect(urlresolvers.reverse('msg.views.index'))
        else:
            render_to_response('msg/create.html',{'form':form},context_instance=RequestContext(request))
Esempio n. 6
0
def base_profile(request):
    f_password = forms.PasswordChangeForm(request.POST)
    f_profile = ProfileForm(instance=request.user.profile)
    f_user = UserEditForm(instance=request.user)
    commit = False
    if request.method == "POST":
        f_profile = ProfileForm(request.POST, request.FILES, instance=request.user.profile)
        f_user = UserEditForm(request.POST, request.FILES, instance=request.user)
        if f_password.is_valid():
            f_password.save(commit=True)
            # handle_uploaded_file(request.FILES['avatar'])
            f_profile.save(commit=True)
            commit = True
        if f_profile.is_valid():
            f_profile.save(commit=True)
            # handle_uploaded_file(request.FILES['avatar'])
            commit = True
        if f_user.is_valid():
            user = f_user.save(commit=True)
            commit = True
    return render_to_response(
        "user/profile.html",
        {"profile": f_profile, "f_pw": f_password, "f_user": f_user, "commit": commit},
        context_instance=RequestContext(request),
    )
Esempio n. 7
0
def archive(request,year,month,page=1):
    entries = Entry.objects.filter(created_at__year=year,
                                   created_at__month=month).order_by('-created_at')
    if (page < 1):
        page = 1
    pages = Paginator(entries,10)                                   
    return render_to_response('blog/archive.html',{'entries':pages.page(page),'month':month,'year':year},context_instance=RequestContext(request))
Esempio n. 8
0
def tag_search(request,tag_name,page=1):
    tag = Tag.objects.get(name=tag_name)
    entries = Entry.objects.filter(tags__name=tag_name).order_by('-created_at')
    if (page < 1):
        page = 1
    pages = Paginator(entries,10)
    return render_to_response('blog/tag.html',{'entries':pages.page(page),'tag':tag},context_instance=RequestContext(request))
Esempio n. 9
0
def index(request,page=1):
    if (page < 1):
        page = 1
    entries = Entry.objects.order_by('-created_at')
    pages = Paginator(entries,10)
    
    return render_to_response('blog/index.html',{'entries':pages.page(page)},context_instance=RequestContext(request))
Esempio n. 10
0
def show_board(request,board_id,board_name=""):

    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
    try:
        group = request.user.groups.all()[0]
    except:
        group = auth.models.Group.objects.get(name='Gast')    
    board = Board.objects.get(pk=board_id)
    boards = Board.objects.filter(parent=None,boardrights__group=group,boardrights__can_view=True)
    rights = BoardRights.objects.get(board= board_id,group=get_group(request.user))
    
    if rights.can_view:
        threads = Thread.objects.raw('''SELECT t.`id`,`closed`,`moved_from_id`,`board_id`,`author_id`,`posts`,t.`name`, max(p.time_created) time
            FROM  `board_thread` t,  `board_post` p
            WHERE t.id = p.thread_id
            AND  (`board_id` =%s
            OR `moved_from_id` =%s)
            GROUP BY t.`id`,`closed`,`moved_from_id`,`board_id`,`author_id`,`posts`,t.`name`
            ORDER BY max(p.time_created) DESC
        ''',[board_id,board_id])
        pages = Paginator(list(threads), 10)
        return render_to_response('board.html',{'board':board,'threads':pages.page(page),'rights':rights,'boards':boards},context_instance=RequestContext(request))
    else:
        return HttpResponseForbidden
Esempio n. 11
0
def index(request):
    try:
        group = request.user.groups.all()[0]
    except:
        group = auth.models.Group.objects.get(name='Gast')
    boards = Board.objects.filter(parent=None,boardrights__group=group,boardrights__can_view=True)
    
    #load statistic data (users online)
    users = UserSession.objects.filter(user__gt=0)
    guest_count = UserSession.objects.filter(Q(user=0)|Q(user__isnull=True)).count()
    #load base stats
    all_user = auth.models.User.objects.count()
    all_threads = Thread.objects.count()
    all_posts = Post.objects.count()
    last_user = auth.models.User.objects.latest('date_joined')
    groups = auth.models.Group.objects.annotate(perm_count=Count('permissions')).filter(perm_count__gt=0)
    return render_to_response('index.html',
        {'boards':boards
         ,'users':users
         ,'groups':groups
         ,'guest_count':guest_count
         ,'all_user':all_user
         ,'all_threads':all_threads
         ,'all_posts':all_posts
         ,'last_user':last_user},context_instance=RequestContext(request))
Esempio n. 12
0
def show_thread(request,thread_id,thread_name=""):
    try:
        thread = Thread.objects.prefetch_related('author').get(pk=thread_id)
    except:
        raise Http404
    rights = BoardRights.objects.get(board= thread.board_id,group=get_group(request.user))
    mod_form = ThreadModForm()
    try:
        group = request.user.groups.all()[0]
    except:
        group = auth.models.Group.objects.get(name='Gast')
    boards = Board.objects.filter(parent=None,boardrights__group=group,boardrights__can_view=True)
    page = 1
    try:
        page = int(request.GET.get('page','1'))
    except Exception as e:
        page = 1
    #mod_form.initial = 
    if rights.can_view:
        thread.views = thread.views+1
        thread.save()
        _posts = Post.objects.select_related().filter(thread=thread_id).order_by('time_created')
        posts = Paginator(_posts,10)
        ppage = posts.page(page)
        
        mark_read(request, thread.board_id, False)
        return render_to_response('thread.html',{'thread':thread,
                                                 't_posts':ppage,
                                                 'rights':rights,
                                                 'moderation':mod_form,
                                                 'boards':boards}
                                  ,context_instance=RequestContext(request))
    else:
        return HttpResponseForbidden()
Esempio n. 13
0
def create_thread(request,board_id):
    """
    Display an new thread form or success page

    **Context**

    ``RequestContext``

    ``thread``
        An instance of :model:`board.Thread`.

    **Template:**

    :template:`create_thread_success.html`
    :template:`create_thread.html`

    """
    if (request.method == "GET"):
        # show template
        Smilie.objects.all()
        BBCode.objects.all()
        f_thread = ThreadForm()
        f_post = PostThreadForm()
    else:
        f_thread = ThreadForm(request.POST)

        f_post = PostThreadForm(request.POST)
        if f_thread.is_valid() and f_post.is_valid():
            thread = f_thread.save(commit=False)
            thread.posts = 0
            thread.author = request.user
            thread.board = Board.objects.get(pk=board_id)
            thread.save()
            post = f_post.save(commit=False)
            post.thread = thread
            post.user = request.user
            post.name = thread.name
            post.save()
            board=thread.board
            board.posts = board.posts + 1
            board.threads = board.threads+1
            board.save()
            profile = request.user.get_profile() 
            profile.posts=profile.posts+1
            profile.save()
            return render_to_response('create_thread_success.html',{'thread':thread,},context_instance=RequestContext(request))
    return render_to_response('create_thread.html',{'f_thread':f_thread,'f_post':f_post,'board_id':board_id},context_instance=RequestContext(request))
Esempio n. 14
0
def topic(request,topic_id):
    try:
        topic_id = int(topic_id)
    except ValueError:
        topic_id=1
    
    topic = Topic.objects.get(pk=topic_id)
    return render_to_response('faq/topic.html',{'topic':topic},context_instance=RequestContext(request))
Esempio n. 15
0
def team(request,team_name=None):
    if (request.method == 'POST'):
        team_name = request.POST['team_name']
    if (team_name is None):
        groups=Group.objects.filter(user__is_staff=True)
    else:
        groups=Group.objects.filter(user__is_staff=True,name=team_name)
    return render_to_response('user/team.html',{'groups':groups},context_instance=RequestContext(request))
Esempio n. 16
0
def team(request, team_name=None):
    if request.method == "POST":
        team_name = request.POST["team_name"]
    if team_name is None:
        groups = Group.objects.filter(user__is_staff=True)
    else:
        groups = Group.objects.filter(user__is_staff=True, name=team_name)
    return render_to_response("user/team.html", {"groups": groups}, context_instance=RequestContext(request))
Esempio n. 17
0
def archive(request, year, month, page=1):
    entries = NewsItem.objects.filter(time__year=year,
                                      time__month=month).order_by('-time')
    if (page < 1):
        page = 1
    pages = Paginator(entries, 10)
    return render_to_response('cms/archive.html', {'entries': pages.page(page), 'month': month, 'year': year},
                              context_instance=RequestContext(request))
Esempio n. 18
0
def msg(request,msg_id):
    message = Message.objects.get(pk=msg_id)
    if(not message.readed and message.reciver == request.user):
        message.readed = True
        message.save()
    if (message.reciver == request.user):
        return render_to_response('msg/show.html',{'msg':message},context_instance=RequestContext(request))
    else:
        return HttpResponseNotAllowed()
Esempio n. 19
0
def inbox(request):
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
        
    messages = Message.objects.filter(reciver=request.user).order_by('-time')
    pages = Paginator(messages, 10)
    
    return render_to_response('msg/index.html',{'user_msg':pages.page(page)},context_instance=RequestContext(request))
Esempio n. 20
0
def show404(request):
    """
    404 error handler.

    Templates: `404.html`
    Context: None
    """
    return render_to_response('404.html',
        context_instance = RequestContext(request)
    )
Esempio n. 21
0
def show(request,userid,username=""):
    try:
        showuser = User.objects.get(pk=userid)
        profile = showuser.profile
        posts = float(Post.objects.count())
        posts_from_total = 0
        if(posts > 0):
            posts_from_total = float(profile.posts)/posts*100.0
        return render_to_response('user/show.html',{'showuser':showuser,'profile':profile,'posts_from_total':posts_from_total},context_instance=RequestContext(request))
    except ObjectDoesNotExist as e:
        raise Http404(_("User does not exist"))
Esempio n. 22
0
def index(request,page=1):
    news = NewsItem.objects.order_by('-time')
    news_list = Paginator(news,10)

    with connection.cursor() as cursor:
        cursor.execute(
            "SELECT DISTINCT YEAR(time) 'year',MONTHNAME(time) 'month',MONTH(time) 'month_num' FROM `cms_newsitem` ORDER BY 1 DESC,2 DESC")
        dates = namedtuplefetchall(cursor)

    return render_to_response('cms/index.html', {'news': news_list.page(page), "dates": dates},
                              context_instance=RequestContext(request))
Esempio n. 23
0
def blog_post(request,entry_id):
    entry = Entry.objects.get(pk=entry_id)
    if request.method == 'POST':
        comment_form = CommentForm(data=request.POST)
        if comment_form.is_valid():
            post = comment_form.save(False)
            post.entry = entry
            post.save()
            messages.add_message(request, messages.INFO, _('comment successfully added.'))
    else:        
        comment_form = CommentForm()
    return render_to_response('blog/show.html',{'entry':entry,'form':comment_form,'comments':entry.get_comments(request.user)},context_instance=RequestContext(request))
Esempio n. 24
0
def show(request, userid, username=""):
    user = User.objects.get(pk=userid)
    profile = user.profile
    posts = float(Post.objects.count())
    posts_from_total = 0
    if posts > 0:
        posts_from_total = float(profile.posts) / posts * 100.0
    return render_to_response(
        "user/show.html",
        {"user": user, "profile": profile, "posts_from_total": posts_from_total},
        context_instance=RequestContext(request),
    )
Esempio n. 25
0
def index(request):
    try:
        page = int(request.GET.get("page"))
    except:
        page = 1
    if request.is_ajax():
        column = ""
        if not request.GET.get("column"):
            column = "-profile__posts"
        else:
            column = request.GET.get("column")
        print column
        users = User.objects.all().order_by(column)
        user_list = Paginator(users, 10)
        user_page = user_list.page(page)
        return render_to_response("user/all_ajax.html", {"users": user_page}, context_instance=RequestContext(request))
    else:
        users = User.objects.all().order_by("-profile__posts")
        user_list = Paginator(users, 10)
        user_page = user_list.page(page)
        return render_to_response("user/all.html", {"users": user_page}, context_instance=RequestContext(request))
Esempio n. 26
0
def register(request):
    if request.method == "POST":
        form = RegisterForm(data=request.POST)
        f_profile = ProfileForm(data=request.POST)
        if form.is_valid() and f_profile.is_valid():
            user = form.save()
            user.groups.add(Group.objects.get(name="User"))
            user.is_active = False
            user.set_password(user.password)
            user.save()
            import uuid

            lv_uuid = str(uuid.uuid1())[0:30]
            send_mail(
                "Registration at silver-boards.de",
                "Hello "
                + user.username
                + "\n\nPlease click the following the link to end your registration.\n\n"
                + "http://localhost:8000/user/activate/"
                + lv_uuid
                + "/",
                settings.SYSTEMMAIL,
                [user.email],
                fail_silently=False,
            )
            profile = f_profile.save(commit=False)
            profile.user = user
            profile.posts = 0
            profile.threads = 0
            profile.activate = lv_uuid
            profile.theme = Theme.objects.get(default=True)
            profile.banned = False
            profile.save()
            return render_to_response("user/register_successful.html", {}, context_instance=RequestContext(request))
    else:
        form = RegisterForm()
        f_profile = ProfileForm()
    return render_to_response(
        "user/register.html", {"form": form, "f_profile": f_profile}, context_instance=RequestContext(request)
    )
Esempio n. 27
0
def index(request):
    try:
        page = int(request.GET.get('page'))
    except:
        page = 1
    if (request.is_ajax()):
        users = User.objects.values('pk','username','profile__posts','profile__threads','last_login').all()
        return JsonResponse(list(users),safe=False)
    else:
        users = User.objects.all().order_by('-profile__posts')
        user_list = Paginator(users, 10)
        user_page = user_list.page(page)
        return render_to_response('user/all.html',{'users':user_page,},context_instance=RequestContext(request))
Esempio n. 28
0
def edit_post(request,post_id):
    if request.method =='POST':
        if 'preview' in request.POST:
            # show a preview
            post = Post.objects.get(pk=post_id)
            if (post.user == request.user):
                # show the edit template
                f_post = PostForm(instance=post,data=request.POST)
                post = f_post.save(commit=False)             
                return render_to_response('edit_post.html',{'f_post':f_post,'post_id':post_id,'preview':True,'post':post},context_instance=RequestContext(request))
        else:
            post = Post.objects.get(pk=post_id)
            if (post.user == request.user):
                # show the edit template
                f_post = PostForm(instance=post,data=request.POST)            
                p=f_post.save(commit=False)
                p.time_edited = datetime.now()
                p.save()
                messages.add_message(request, messages.INFO, 'This reply was successfully edited.')
                return redirect(urlresolvers.reverse('board.views.show_thread',args=[p.thread.id,p.thread.get_url_name()]))
    try:
        post = Post.objects.get(pk=post_id)
        if (post.user == request.user or request.user.is_staff):
            # show the edit template
            html_file = "edit_post.html"
            f_post = PostForm(instance=post)
            if (request.is_ajax()):
                html_file = "edit_post_ajax.html"
                
            return render_to_response(html_file,{'f_post':f_post,'post_id':post_id},context_instance=RequestContext(request))
        else:
            messages.add_message(request, messages.ERROR, 'You are not allowed to edit this post.')
            return redirect(urlresolvers.reverse('board.views.show_thread',args=[p.thread.id,p.thread.get_url_name()]))
    except Exception as e:
        #return a 404 page
        #traceback.print_stack(e)
        traceback.print_exc(file=sys.stdout)
        print e
        raise Http404
Esempio n. 29
0
def index(request,page=1):
    if (page < 1):
        page = 1
    entries = Entry.objects.order_by('-created_at')
    pages = Paginator(entries,10)
    
    Entry.objects.values('created_at')
    
    with connection.cursor() as cursor:
        cursor.execute("SELECT DISTINCT YEAR(created_at) 'year',MONTHNAME(created_at) 'month',MONTH(created_at) 'month_num' FROM `blog_entry` ORDER BY 1 DESC,2 DESC")
        dates = namedtuplefetchall(cursor)
    
    return render_to_response('blog/index.html',{'entries':pages.page(page),'dates':dates},context_instance=RequestContext(request))
Esempio n. 30
0
def activate(request,uuid):
    try:
        
        profile = UserProfile.objects.get(activate =uuid)
        user = profile.user
        profile.activate = 'T'
        user.is_active = True
        profile.save()
        user.save()
        return render_to_response('user/activated.html',{},context_instance=RequestContext(request))
    except Exception as e:
        print(e)
        raise Http404