コード例 #1
0
def create_forum_topic(article, forum_name):
    if article.id == None:
        # forum topic not created, lets create
        user = get_object_or_404(User,
                                 username=threadlocals.get_current_user())
        forum = Forum.objects.filter(name=forum_name).order_by("id")[0]
        topic = Topic(
            forum=forum,
            title=article.title,
        )
        topic.save()

        post = Post(
            topic=topic,
            author=user,
            text=article.text,
            ip=threadlocals.get_current_ip(),
            hidden=not article.status,
        )
        post.save()

        topic.topic_latest_post = post
        topic.posts = 1
        topic.hidden = not article.status
        topic.topic_latest_post = post
        topic.forum.posts += 1
        topic.forum.topics += 1
        if article.status:
            topic.forum.forum_latest_post = post
        topic.forum.save()
        topic.save()
        article.topic = topic
    else:
        # this is modified, let's update the forum topic
        topic = article.topic
        topic.tags.clear()
        for tag in article.tags.all():
            topic.tags.add(tag)

        topic.hidden = not article.status
        topic.locked = not article.status
        topic.title = article.title
        topic.save()

        post = topic.post_set.order_by("created")[0]
        post.text = article.text
        post.hidden = not article.status
        post.edited = article.update
        post.save()
    if article.status:
        try:
            ping_google()
        # we're catching SitemapNotFound exception
        # no need to import this exception class since there is only 1 exception in the function.
        except:
            pass
コード例 #2
0
ファイル: tools.py プロジェクト: ozgurlukicin/ozgurlukicin
def create_forum_topic(article, forum_name):
    if article.id == None:
        # forum topic not created, lets create
        user = get_object_or_404(User, username=threadlocals.get_current_user())
        forum = Forum.objects.filter(name=forum_name).order_by("id")[0]
        topic = Topic(
                forum = forum,
                title = article.title,
                )
        topic.save()

        post = Post(
                topic=topic,
                author=user,
                text=article.text,
                ip=threadlocals.get_current_ip(),
                hidden=not article.status,
                )
        post.save()

        topic.topic_latest_post = post
        topic.posts = 1
        topic.hidden = not article.status
        topic.topic_latest_post = post
        topic.forum.posts += 1
        topic.forum.topics += 1
        if article.status:
            topic.forum.forum_latest_post = post
        topic.forum.save()
        topic.save()
        article.topic = topic
    else:
        # this is modified, let's update the forum topic
        topic = article.topic
        topic.tags.clear()
        for tag in article.tags.all():
            topic.tags.add(tag)

        topic.hidden = not article.status
        topic.locked = not article.status
        topic.title = article.title
        topic.save()

        post = topic.post_set.order_by("created")[0]
        post.text = article.text
        post.hidden = not article.status
        post.edited = article.update
        post.save()
    if article.status:
        try:
            ping_google()
        # we're catching SitemapNotFound exception
        # no need to import this exception class since there is only 1 exception in the function.
        except:
            pass
コード例 #3
0
def add(request):
    if request.method == 'POST':
        form = NewIdeaForm(request.POST, request.FILES)
        if form.is_valid():
            forum = Forum.objects.get(name="Yeni Fikirler")
            topic = Topic(forum=forum,
                          title=form.cleaned_data['title'],
                          )
            topic.save()

            newidea = Idea(title = form.cleaned_data['title'],
                           description = form.cleaned_data['description'],
                           submitter = request.user,
                           category = form.cleaned_data['category'],
                           related_to = form.cleaned_data['related_to'],
                           forum_url = form.cleaned_data['forum_url'],
                           bug_numbers = form.cleaned_data['bug_numbers'],
                           status = Status.objects.get(name="Yeni Fikir"),
                           topic = topic)
            newidea.save()

            for tag in form.cleaned_data['tags']:
                tag = Tag.objects.get(name=tag)
                newidea.tags.add(tag)
                topic.tags.add(tag)

            post_text = "<p>#" + str(newidea.id) + " "
            post_text += "<a href=" + newidea.get_absolute_url() + ">" + newidea.title + "</a></p>"
            post_text += "<p>" + newidea.description + "</p>"
            if form.cleaned_data['forum_url']:
                post_text += "<p>İlgili Forum Linki<br /><a href='" + newidea.forum_url + "'>" + newidea.forum_url + "</a></p>"
            if newidea.bug_numbers:
                post_text += "<p>İlgili hatalar<br />"
                for bug in newidea.bug_numbers.replace(" ", "").split(","):
                    post_text += "<a href='http://bugs.pardus.org.tr/show_bug.cgi?id=" + bug + "'>" + bug + "</a> "

            post = Post(topic=topic,
                        author=request.user,
                        text=post_text)
            post.save()
            topic.topic_latest_post = post
            topic.posts = 1
            topic.save()
            topic.forum.forum_latest_post = post
            topic.forum.topics += 1
            topic.forum.posts += 1
            topic.forum.save()
            return HttpResponseRedirect(newidea.get_absolute_url())
    else:
        form = NewIdeaForm(auto_id=True)

    page_title = "Yeni Fikir Ekle"
    categories = Category.objects.all()
    return render_response(request, "idea_add_form.html", locals())
コード例 #4
0
def new_topic(request, forum_slug):
    forum = get_object_or_404(Forum, slug=forum_slug)

    if forum.locked and not request.user.has_perm("forum.add_topic"):
        return render_response(
            request, "forum/forum_error.html", {
                "message":
                "Bu forumda yeni başlık açamazsınız. Lütfen kilitli olmayan bir forumda başlık açınız."
            })

    if request.method == 'POST':
        form = TopicForm(request.POST.copy())
        flood, timeout = flood_control(request)

        if form.is_valid() and not flood:
            topic = Topic(forum=forum, title=form.cleaned_data['title'])
            topic.save()

            # add tags
            for tag in form.cleaned_data['tags']:
                t = Tag.objects.get(name=tag)
                topic.tags.add(t)

            post = Post(topic=topic,
                        author=request.user,
                        text=form.cleaned_data['text'])

            post.save()

            # generate post url
            post_url = WEB_URL + topic.get_absolute_url()

            # send e-mail to mailing list. We really rock, yeah!
            # send_mail_with_header('%s' % topic.title,
            #                       '%s<br /><br /><a href="%s">%s</a>' % (post.text, post_url, post_url),
            #                       '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL),
            #                       [FORUM_MESSAGE_LIST],
            #                       headers = {'Message-ID': topic.get_email_id()},
            #                       fail_silently = True
            #                       )

            return HttpResponseRedirect(post.get_absolute_url())
    else:
        form = TopicForm(auto_id=True)

    if request.user.has_perm("forum.can_change_abusereport"):
        abuse_count = AbuseReport.objects.count()

    return render_response(request, 'forum/new_topic.html', locals())
コード例 #5
0
ファイル: views.py プロジェクト: ozgurlukicin/ozgurlukicin
def new_topic(request, forum_slug):
    forum = get_object_or_404(Forum, slug=forum_slug)

    if forum.locked and not request.user.has_perm("forum.add_topic"):
        return render_response(request, "forum/forum_error.html", { "message":"Bu forumda yeni başlık açamazsınız. Lütfen kilitli olmayan bir forumda başlık açınız." })

    if request.method == 'POST':
        form = TopicForm(request.POST.copy())
        flood,timeout = flood_control(request)

        if form.is_valid() and not flood:
            topic = Topic(forum=forum,
                          title=form.cleaned_data['title'])
            topic.save()

            # add tags
            for tag in form.cleaned_data['tags']:
                t=Tag.objects.get(name=tag)
                topic.tags.add(t)

            post = Post(topic=topic,
                        author=request.user,
                        text=form.cleaned_data['text'])

            post.save()

            # generate post url
            post_url = WEB_URL + topic.get_absolute_url()

            # send e-mail to mailing list. We really rock, yeah!
            # send_mail_with_header('%s' % topic.title,
            #                       '%s<br /><br /><a href="%s">%s</a>' % (post.text, post_url, post_url),
            #                       '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL),
            #                       [FORUM_MESSAGE_LIST],
            #                       headers = {'Message-ID': topic.get_email_id()},
            #                       fail_silently = True
            #                       )

            return HttpResponseRedirect(post.get_absolute_url())
    else:
        form = TopicForm(auto_id=True)

    if request.user.has_perm("forum.can_change_abusereport"):
        abuse_count = AbuseReport.objects.count()

    return render_response(request, 'forum/new_topic.html', locals())
コード例 #6
0
ファイル: views.py プロジェクト: ozgurlukicin/ozgurlukicin
def mark_duplicate(request, idea_id):
    if request.POST:
        idea = get_object_or_404(Idea, pk = idea_id)
        if request.POST['dupple_number']:
            idea_original = get_object_or_404(Idea, pk= int(request.POST['dupple_number']))
            idea.duplicate = idea_original
        else:
            idea_original = get_object_or_404(Idea, pk = int(request.POST['dupple']))
            idea.duplicate = idea_original
        idea.is_duplicate = True
        idea.save()
        #changes for forum
        #the duplicate
        topic = idea.topic
        post_text = "<h1> Bu fikir başka bir fikrin tekrarı olarak belirlenmiş </h1>"
        post_text += '<a href="'+  reverse('idea_detail', args =( idea_original.id,))
        post_text += '">#' + str(idea_original.id) + ": " + idea_original.title + "</a>"
        post_text += "<p>" + idea_original.description + "</p><br />"
        for image in idea_original.screenshot_set.all():
            if image.is_hidden == False:
                post_text += '<br /><img src="'+image.image.url+'" height="320" width"240" /><br />'
        post_text += "<br /><a href='"+idea_original.topic.get_latest_post_url()+"'>Lütfen buradan devam ediniz...</a>"
        post = Post(topic=topic, author=request.user, text=post_text )
        post.save()
        topic.topic_latest_post = post
        topic.posts += 1
        topic.save()
        topic.forum.forum_latest_post = post
        topic.forum.posts += 1
        topic.forum.save()
        #the original idea
        topic = idea_original.topic
        post_text = "<h1> Başka bir fikir bu fikrin tekrarı olarak belirlenmiş </h1>"
        post_text += "<p>#" + str(idea.id) + ": "
        post_text += idea.title + "</p>"
        post_text += "<p>" + idea.description + "</p><br />"
        for image in idea.screenshot_set.all():
            if image.is_hidden == False:
                post_text += '<br /><img src="'+image.image.url+'" height="320" width"240" /><br />'
        post_text += "<br /><a href='"+idea.topic.get_absolute_url()+"'>Daha önce şu başlık altında tartışılmış...</a>"
        post = Post(topic=topic, author=request.user, text=post_text )
        post.save()
        
        post_text = '#' + str(idea.id) + ": " + idea.title
        post_text += "<p>" + idea.description + "</p><br />"
        for image in idea.screenshot_set.all():
            if image.is_hidden == False:
                post_text += '<br /><img src="'+image.image.url+'" height="320" width"240" /><br />'

        post = idea.topic.post_set.all().order_by('created')[0]

        post.text = post_text
        post.save()
        
        topic.topic_latest_post = post
        topic.posts += 1
        topic.save()
        topic.forum.forum_latest_post = post
        topic.forum.posts += 1
        topic.forum.save()
        votes_list = Vote.objects.filter( idea = idea)
        for vote in votes_list:
            if vote.vote == "U":
                idea_original.vote_value +=10
            elif vote.vote == "D":
                idea_original.vote_value -=10
            elif vote.vote == "N":
                idea_original.vote_value +=1
            vote.idea = idea_original
            vote.save()

        all_votes = Vote.objects.filter( idea=idea_original ).count()
        all_votes = float(all_votes)
        u_votes = Vote.objects.filter( idea=idea_original, vote="U").count()
        n_votes = Vote.objects.filter( idea=idea_original, vote="N").count()
        d_votes = Vote.objects.filter( idea=idea_original, vote="D").count()
        if all_votes != 0:
            u_percent = int((u_votes/all_votes)*100)
            n_percent = int((n_votes/all_votes)*100)
            d_percent = int((d_votes/all_votes)*100)
        else:
            u_percent = n_percent = d_percent = 0
        percent = (u_percent*1000000)+(n_percent*1000)+d_percent
        idea_original.vote_percent=percent
        idea_original.save()
        return HttpResponseRedirect(reverse('oi.beyin2.views.delete_idea', args=(idea.id,)))
    else:
        idea = get_object_or_404(Idea, pk = idea_id)
        idea_list = Idea.objects.exclude(pk=idea.id).filter(is_hidden=False)
        return render_response(request, 'beyin2/idea_duplicate.html', {'idea': idea,'idea_list': idea_list})
コード例 #7
0
ファイル: views.py プロジェクト: ozgurlukicin/ozgurlukicin
def add_new(request,phase ):
    if phase == "1":
        ScreenShotSet = formset_factory(ScreenShotForm, extra=3, max_num=3)
        ScreenShotFormSet = ScreenShotSet(prefix = 'imageform')
        form = TagsForm(request.POST)
        dummy_idea = form.save(commit = False)
        tags = form.cleaned_data['tags']
        title = form.cleaned_data['title']
        form = IdeaForm({'ideaform-title': title, 'ideaform-tags': [tag.id for tag in tags]}, prefix = 'ideaform')
        return render_response(request, 'beyin2/idea_new.html', {'form':form,'ScreenShotFormSet':ScreenShotFormSet})
    if phase == "2":
        form = IdeaForm({'title': '', 'description': '', 'status': DefaultStatus, 'category': DefaultCategory}, prefix = 'ideaform')
        ScreenShotSet = formset_factory(ScreenShotForm, extra=3, max_num=3) 
        if request.POST:
            try:
                form = IdeaForm(request.POST, prefix = 'ideaform')
                ScreenShotFormSet  = ScreenShotSet(request.POST, request.FILES, prefix = 'imageform') 
            except:
                return render_response(request,'beyin2/idea_errorpage.html',{'error':'Form bulunamadı.',})

            
            if form.is_valid():
                forum = Forum.objects.get(name = ForumCategory)
                topic = Topic(forum = forum,title = form.cleaned_data['title'])
                topic.save()

                idea = form.save(commit = False)
                idea.submitter = request.user
                idea.description = form.cleaned_data['description']
                idea.dateSubmitted = datetime.now()
                idea.topic = topic
                if not idea.status:
                    def_stat = get_object_or_404(Status, pk = DefaultStatus )
                    idea.status = def_stat
                if not idea.category:
                    def_cate = get_object_or_404(Category, pk = DefaultCategory )
                    idea.category = def_cate
                idea.save()

                try:
                    for screenshotform in ScreenShotFormSet.forms:
                        image = screenshotform.save(commit = False)
                        if image.image:
                            image.idea = idea
                            image.save()
                except:
                    pass

                for tag in form.cleaned_data['tags']:
                    tag = Tag.objects.get(name=tag)
                    idea.tags.add(tag)
                    topic.tags.add(tag)

                post_text = '<a href="'+  reverse('idea_detail', args =( idea.id,))
                post_text += '">#' + str(idea.id) + ": "
                post_text += idea.title + "</a>"
                post_text += "<p>" + idea.description + "</p>"
                for image in idea.screenshot_set.all():
                    post_text += '<br /><img src="'+image.image.url+'" height="320" width"240" /><br />'
                post = Post(topic=topic, author=request.user, text=post_text )
                post.save()
                topic.topic_latest_post = post
                topic.posts = 1
                topic.save()
                topic.forum.forum_latest_post = post
                topic.forum.topics += 1
                topic.forum.posts += 1
                topic.forum.save()
                return HttpResponseRedirect(reverse('oi.beyin2.views.main'))
            else:
                return render_response(request, 'beyin2/idea_errorpage.html',{'error':form.errors,})

        else:
            ScreenShotFormSet = ScreenShotSet(prefix = 'imageform')
            return render_response(request, 'beyin2/idea_new.html', {'form':form,'ScreenShotFormSet':ScreenShotFormSet})
コード例 #8
0
ファイル: views.py プロジェクト: ozgurlukicin/ozgurlukicin
def main(request, idea_id = -1, page_number = 1, order = "date", filter_by = "none", filter = "none" ):
    order_dict = {
        'date': '-dateSubmitted',
        'vote_value': '-vote_value',
        'title': 'title',
        'vote_count': 'vote_count',
        'neg_date': 'dateSubmitted',
        'neg_vote_value': 'vote_value',
        'neg_title': '-title',
        'neg_vote_count': '-vote_count'}

    if request.POST:
        idea = get_object_or_404(Idea, pk = idea_id)
        is_change_status = 0
        try:
            if idea.status != get_object_or_404(Status, name = request.POST['status']):
                is_change_status = 1
                idea.status = get_object_or_404(Status, name = request.POST['status'])
                #and send forum that status changed
                topic = idea.topic
                post_text = "<b> Bu fikrin durumu "+ idea.status.name+" olarak değiştirildi </b>"
                post = Post(topic=topic, author=request.user, text=post_text )
                post.save()
                topic.topic_latest_post = post
                topic.posts += 1
                topic.save()
                topic.forum.forum_latest_post = post
                topic.forum.posts += 1
                topic.forum.save()
        except:
            idea.status = Status()
        try:
            if is_change_status:
                is_change_status = 0
            else:
                idea.category = get_object_or_404(Category, name = request.POST['category'])
                #and send forum that category changed
                topic = idea.topic
                post_text = "<b> Bu fikrin kategorisi "+ idea.category.name+" olarak değiştirildi </b>"
                post = Post(topic=topic, author=request.user, text=post_text )
                post.save()
                topic.topic_latest_post = post
                topic.posts += 1
                topic.save()
                topic.forum.forum_latest_post = post
                topic.forum.posts += 1
                topic.forum.save()
        except:
            idea.category = Category()

        idea.save()
        return HttpResponseRedirect(reverse('oi.beyin2.views.main'))
    else:
        #idea list order changes
        all_idea_list = Idea.objects.filter(is_hidden=False).order_by(order_dict[order])
        #idea list filter changes
        if filter_by == "user":
            all_idea_list = Idea.objects.filter(is_hidden = False, submitter = filter ).order_by(order_dict[order])
        if filter_by == "tag":
            tag = Tag.objects.get(name=filter)
            all_idea_list = tag.idea_set.filter(is_hidden=False).order_by(order_dict[order])
        if filter_by == "favorite":
            favorites = Favorite.objects.filter( user = request.user )
            try: 
                favorites[0]
                all_idea_list = []
                for favorite in favorites:
                    all_idea_list.append(favorite.idea)
            except:
                return render_response(request,'beyin2/idea_errorpage.html',{'error':'İsteğe uygun fikir bulunamadı.',})
        if filter_by == "today":
            all_idea_list = Idea.objects.filter( is_hidden = False, dateSubmitted__gt = datetime.now() - timedelta(1)).order_by(order_dict[order])
        if filter_by == "this_week":
            all_idea_list = Idea.objects.filter( is_hidden = False, dateSubmitted__gt = datetime.now() - timedelta(7)).order_by(order_dict[order])
        if filter_by == "this_month":
            all_idea_list = Idea.objects.filter( is_hidden = False, dateSubmitted__gt = datetime.now() - timedelta(10)).order_by(order_dict[order])
        if filter_by == "category":
            all_idea_list = Idea.objects.filter( is_hidden = False, category = filter ).order_by(order_dict[order])
        if filter_by == "status":
            all_idea_list = Idea.objects.filter( is_hidden = False, status = filter ).order_by(order_dict[order])
        if filter_by == "deleted":
            all_idea_list = Idea.objects.filter( is_hidden = True, is_duplicate = False ).order_by(order_dict[order])
        if filter_by == "duplicate":
            all_idea_list = Idea.objects.filter( is_duplicate = True ).order_by(order_dict[order])
        # add vote_counts for every vote, intended to use in preview on votebar
        '''
        # using this causes Django to fetch all object from database
        # refer to this : http://docs.djangoproject.com/en/dev/topics/db/queries/#querysets-are-lazy
        # set vote_text when user votes or just calculate this for listed objects
        for idea in all_idea_list:
            pos_votes = Vote.objects.filter( vote = 'U', idea = idea).count()
            notr_votes = Vote.objects.filter( vote = 'N', idea = idea ).count()
            neg_votes = Vote.objects.filter( vote = 'D', idea = idea ).count()
            idea.vote_text =  "Olumlu: %s Kararsız: %s Olumsuz: %s" %(pos_votes, notr_votes, neg_votes )
        '''

        status_list = Status.objects.all().order_by("name")
        category_list = Category.objects.all().order_by("name")
        if not all_idea_list:
            return render_response(request,'beyin2/idea_errorpage.html',{'error':'İsteğe uygun fikir bulunamadı.',})
        paginator = Paginator(all_idea_list, idea_per_page)
        idea_list=paginator.page(page_number)
        last_page = len(paginator.page_range)
        if int(page_number) < last_page - 4:
            show_go_to_last = True
        else:
            show_go_to_last = False
        if int(page_number) > 5:
            show_go_to_first = True
        else:
            show_go_to_first = False
        if int(page_number) > 4:
            page_range = paginator.page_range[int(page_number)-5:(int(page_number)+4)]
        else:
            page_range = paginator.page_range[0:(int(page_number)+4)]
        #we dont want to show default category, so we sould send the name to check if it is
        def_cate = get_object_or_404(Status, pk = DefaultCategory )
        '''
        for idea in idea_list.object_list:
            idea.duplicate_list = Idea.objects.filter( duplicate = idea )
        '''
        return render_response(request,'beyin2/idea_list.html',{'idea_list': idea_list, 'status_list':status_list, 'category_list': category_list,'order':order,'come_from':'main', 'page_range': page_range, 'show_go_to_last': show_go_to_last, 'show_go_to_first': show_go_to_first, 'last_page': last_page, 'default_category' : def_cate,'filter':filter,'filter_by':filter_by})
コード例 #9
0
def mark_duplicate(request, idea_id):
    if request.POST:
        idea = get_object_or_404(Idea, pk=idea_id)
        if request.POST['dupple_number']:
            idea_original = get_object_or_404(
                Idea, pk=int(request.POST['dupple_number']))
            idea.duplicate = idea_original
        else:
            idea_original = get_object_or_404(Idea,
                                              pk=int(request.POST['dupple']))
            idea.duplicate = idea_original
        idea.is_duplicate = True
        idea.save()
        #changes for forum
        #the duplicate
        topic = idea.topic
        post_text = "<h1> Bu fikir başka bir fikrin tekrarı olarak belirlenmiş </h1>"
        post_text += '<a href="' + reverse('idea_detail',
                                           args=(idea_original.id, ))
        post_text += '">#' + str(
            idea_original.id) + ": " + idea_original.title + "</a>"
        post_text += "<p>" + idea_original.description + "</p><br />"
        for image in idea_original.screenshot_set.all():
            if image.is_hidden == False:
                post_text += '<br /><img src="' + image.image.url + '" height="320" width"240" /><br />'
        post_text += "<br /><a href='" + idea_original.topic.get_latest_post_url(
        ) + "'>Lütfen buradan devam ediniz...</a>"
        post = Post(topic=topic, author=request.user, text=post_text)
        post.save()
        topic.topic_latest_post = post
        topic.posts += 1
        topic.save()
        topic.forum.forum_latest_post = post
        topic.forum.posts += 1
        topic.forum.save()
        #the original idea
        topic = idea_original.topic
        post_text = "<h1> Başka bir fikir bu fikrin tekrarı olarak belirlenmiş </h1>"
        post_text += "<p>#" + str(idea.id) + ": "
        post_text += idea.title + "</p>"
        post_text += "<p>" + idea.description + "</p><br />"
        for image in idea.screenshot_set.all():
            if image.is_hidden == False:
                post_text += '<br /><img src="' + image.image.url + '" height="320" width"240" /><br />'
        post_text += "<br /><a href='" + idea.topic.get_absolute_url(
        ) + "'>Daha önce şu başlık altında tartışılmış...</a>"
        post = Post(topic=topic, author=request.user, text=post_text)
        post.save()

        post_text = '#' + str(idea.id) + ": " + idea.title
        post_text += "<p>" + idea.description + "</p><br />"
        for image in idea.screenshot_set.all():
            if image.is_hidden == False:
                post_text += '<br /><img src="' + image.image.url + '" height="320" width"240" /><br />'

        post = idea.topic.post_set.all().order_by('created')[0]

        post.text = post_text
        post.save()

        topic.topic_latest_post = post
        topic.posts += 1
        topic.save()
        topic.forum.forum_latest_post = post
        topic.forum.posts += 1
        topic.forum.save()
        votes_list = Vote.objects.filter(idea=idea)
        for vote in votes_list:
            if vote.vote == "U":
                idea_original.vote_value += 10
            elif vote.vote == "D":
                idea_original.vote_value -= 10
            elif vote.vote == "N":
                idea_original.vote_value += 1
            vote.idea = idea_original
            vote.save()

        all_votes = Vote.objects.filter(idea=idea_original).count()
        all_votes = float(all_votes)
        u_votes = Vote.objects.filter(idea=idea_original, vote="U").count()
        n_votes = Vote.objects.filter(idea=idea_original, vote="N").count()
        d_votes = Vote.objects.filter(idea=idea_original, vote="D").count()
        if all_votes != 0:
            u_percent = int((u_votes / all_votes) * 100)
            n_percent = int((n_votes / all_votes) * 100)
            d_percent = int((d_votes / all_votes) * 100)
        else:
            u_percent = n_percent = d_percent = 0
        percent = (u_percent * 1000000) + (n_percent * 1000) + d_percent
        idea_original.vote_percent = percent
        idea_original.save()
        return HttpResponseRedirect(
            reverse('oi.beyin2.views.delete_idea', args=(idea.id, )))
    else:
        idea = get_object_or_404(Idea, pk=idea_id)
        idea_list = Idea.objects.exclude(pk=idea.id).filter(is_hidden=False)
        return render_response(request, 'beyin2/idea_duplicate.html', {
            'idea': idea,
            'idea_list': idea_list
        })
コード例 #10
0
def add_new(request, phase):
    if phase == "1":
        ScreenShotSet = formset_factory(ScreenShotForm, extra=3, max_num=3)
        ScreenShotFormSet = ScreenShotSet(prefix='imageform')
        form = TagsForm(request.POST)
        dummy_idea = form.save(commit=False)
        tags = form.cleaned_data['tags']
        title = form.cleaned_data['title']
        form = IdeaForm(
            {
                'ideaform-title': title,
                'ideaform-tags': [tag.id for tag in tags]
            },
            prefix='ideaform')
        return render_response(request, 'beyin2/idea_new.html', {
            'form': form,
            'ScreenShotFormSet': ScreenShotFormSet
        })
    if phase == "2":
        form = IdeaForm(
            {
                'title': '',
                'description': '',
                'status': DefaultStatus,
                'category': DefaultCategory
            },
            prefix='ideaform')
        ScreenShotSet = formset_factory(ScreenShotForm, extra=3, max_num=3)
        if request.POST:
            try:
                form = IdeaForm(request.POST, prefix='ideaform')
                ScreenShotFormSet = ScreenShotSet(request.POST,
                                                  request.FILES,
                                                  prefix='imageform')
            except:
                return render_response(request, 'beyin2/idea_errorpage.html', {
                    'error': 'Form bulunamadı.',
                })

            if form.is_valid():
                forum = Forum.objects.get(name=ForumCategory)
                topic = Topic(forum=forum, title=form.cleaned_data['title'])
                topic.save()

                idea = form.save(commit=False)
                idea.submitter = request.user
                idea.description = form.cleaned_data['description']
                idea.dateSubmitted = datetime.now()
                idea.topic = topic
                if not idea.status:
                    def_stat = get_object_or_404(Status, pk=DefaultStatus)
                    idea.status = def_stat
                if not idea.category:
                    def_cate = get_object_or_404(Category, pk=DefaultCategory)
                    idea.category = def_cate
                idea.save()

                try:
                    for screenshotform in ScreenShotFormSet.forms:
                        image = screenshotform.save(commit=False)
                        if image.image:
                            image.idea = idea
                            image.save()
                except:
                    pass

                for tag in form.cleaned_data['tags']:
                    tag = Tag.objects.get(name=tag)
                    idea.tags.add(tag)
                    topic.tags.add(tag)

                post_text = '<a href="' + reverse('idea_detail',
                                                  args=(idea.id, ))
                post_text += '">#' + str(idea.id) + ": "
                post_text += idea.title + "</a>"
                post_text += "<p>" + idea.description + "</p>"
                for image in idea.screenshot_set.all():
                    post_text += '<br /><img src="' + image.image.url + '" height="320" width"240" /><br />'
                post = Post(topic=topic, author=request.user, text=post_text)
                post.save()
                topic.topic_latest_post = post
                topic.posts = 1
                topic.save()
                topic.forum.forum_latest_post = post
                topic.forum.topics += 1
                topic.forum.posts += 1
                topic.forum.save()
                return HttpResponseRedirect(reverse('oi.beyin2.views.main'))
            else:
                return render_response(request, 'beyin2/idea_errorpage.html', {
                    'error': form.errors,
                })

        else:
            ScreenShotFormSet = ScreenShotSet(prefix='imageform')
            return render_response(request, 'beyin2/idea_new.html', {
                'form': form,
                'ScreenShotFormSet': ScreenShotFormSet
            })
コード例 #11
0
def themeitem_change_font(request, item_id):
    object = get_object_or_404(Font, pk=item_id)
    if request.user == object.author or request.user.has_perm(
            "can_change_themeitem"):
        if request.method == "POST":
            form = FontForm(request.POST.copy(), request.FILES)
            flood, timeout = flood_control(request)
            if flood:
                render_response(
                    request, "tema/message.html", {
                        "type":
                        "error",
                        "message":
                        "Lütfen %s saniye sonra tekrar deneyiniz." % timeout
                    })

            if form.is_valid():
                object.title = form.cleaned_data["title"]
                object.license = form.cleaned_data["license"]
                object.text = form.cleaned_data["text"]
                old_version = object.version
                object.version = form.cleaned_data["version"]
                object.font = form.cleaned_data["font"]
                object.is_turkish = form.cleaned_data["is_turkish"]
                object.update = datetime.datetime.now()

                #change slug
                slug = slugify(replace_turkish(object.title))
                object.slug = str(object.id) + "-" + slug

                object.save()

                #create thumbnail
                twidth = 150
                theight = 100
                thumbnail = Image.new("RGBA", (twidth, theight))
                draw = ImageDraw.Draw(thumbnail)
                bigfont = ImageFont.truetype(object.font.path, 22)
                smallfont = ImageFont.truetype(object.font.path, 14)
                fill = (112, 112, 112)
                draw.text((5, 5), "Aa Ee Rr", font=bigfont, fill=fill)
                text_list = (
                    (30, "Dag basini", u"Dağ başını"),
                    (45, "duman almis,", u"duman almış,"),
                    (60, "Gumus dere", u"Gümüş dere"),
                    (75, "durmaz akar.", u"durmaz akar."),
                )
                for text in text_list:
                    s = draw.textsize(text[1], font=smallfont)
                    x = twidth - s[0] - 5
                    if object.is_turkish:
                        draw.text((x, text[0]),
                                  text[2],
                                  font=smallfont,
                                  fill=fill)
                    else:
                        draw.text((x, text[0]),
                                  text[1],
                                  font=smallfont,
                                  fill=fill)
                file = ContentFile("")
                object.thumbnail.save(
                    object.font.path[:object.font.path.rfind(".")] + ".png",
                    file,
                    save=True)
                thumbnail.save(object.thumbnail.path)

                #post changes
                if object.version != old_version:
                    text = "%s %s sürümlü %s yazitipini %s sürümüne güncelledi." % (
                        request.user, old_version, object.title,
                        object.version)
                    post = Post(
                        topic=object.topic,
                        author=request.user,
                        text=text,
                    )
                    post.save()

                return HttpResponseRedirect(object.get_absolute_url())

            else:
                return render_response(request, "tema/themeitem_change.html",
                                       locals())
        else:
            default_data = {
                "title": object.title,
                "license": object.license,
                "text": object.text,
                "version": object.version,
                "changelog": object.changelog,
                "tags": object.tags.all(),
                "origin_url": object.origin_url,
                "font": object.font,
                "is_turkish": object.is_turkish,
            }

            form = FontForm(initial=default_data)

        return render_response(request, "tema/themeitem_change.html", locals())

    else:
        return render_response(request, "tema/message.html", {
            "type": "error",
            "message": "Bu işlemi yapmak için yetkiniz yok."
        })
コード例 #12
0
ファイル: views.py プロジェクト: ozgurlukicin/ozgurlukicin
def themeitem_change_font(request, item_id):
    object = get_object_or_404(Font, pk=item_id)
    if request.user == object.author or request.user.has_perm("can_change_themeitem"):
        if request.method == "POST":
            form = FontForm(request.POST.copy(), request.FILES)
            flood, timeout = flood_control(request)
            if flood:
                render_response(request, "tema/message.html", {"type": "error", "message": "Lütfen %s saniye sonra tekrar deneyiniz." % timeout })

            if form.is_valid():
                object.title = form.cleaned_data["title"]
                object.license = form.cleaned_data["license"]
                object.text = form.cleaned_data["text"]
                old_version = object.version
                object.version = form.cleaned_data["version"]
                object.font = form.cleaned_data["font"]
                object.is_turkish = form.cleaned_data["is_turkish"]
                object.update = datetime.datetime.now()

                #change slug
                slug = slugify(replace_turkish(object.title))
                object.slug = str(object.id) + "-" + slug

                object.save()

                #create thumbnail
                twidth = 150
                theight = 100
                thumbnail = Image.new("RGBA", (twidth, theight))
                draw = ImageDraw.Draw(thumbnail)
                bigfont = ImageFont.truetype(object.font.path, 22)
                smallfont = ImageFont.truetype(object.font.path, 14)
                fill = (112,112,112)
                draw.text((5, 5), "Aa Ee Rr", font=bigfont, fill=fill)
                text_list = (
                    (30, "Dag basini", u"Dağ başını"),
                    (45, "duman almis,", u"duman almış,"),
                    (60, "Gumus dere", u"Gümüş dere"),
                    (75, "durmaz akar.", u"durmaz akar."),
                )
                for text in text_list:
                    s = draw.textsize(text[1], font=smallfont)
                    x = twidth - s[0] - 5
                    if object.is_turkish:
                        draw.text((x, text[0]), text[2], font=smallfont, fill=fill)
                    else:
                        draw.text((x, text[0]), text[1], font=smallfont, fill=fill)
                file = ContentFile("")
                object.thumbnail.save(object.font.path[:object.font.path.rfind(".")]+".png", file, save=True)
                thumbnail.save(object.thumbnail.path)

                #post changes
                if object.version != old_version:
                    text = "%s %s sürümlü %s yazitipini %s sürümüne güncelledi." % (request.user, old_version, object.title, object.version)
                    post = Post(topic=object.topic,
                                author=request.user,
                                text=text,
                                )
                    post.save()

                return HttpResponseRedirect(object.get_absolute_url())

            else:
                return render_response(request, "tema/themeitem_change.html", locals())
        else:
            default_data = {"title": object.title,
                            "license": object.license,
                            "text": object.text,
                            "version": object.version,
                            "changelog": object.changelog,
                            "tags": object.tags.all(),
                            "origin_url": object.origin_url,
                            "font": object.font,
                            "is_turkish": object.is_turkish,
                            }

            form = FontForm(initial=default_data)

        return render_response(request, "tema/themeitem_change.html", locals())

    else:
        return render_response(request, "tema/message.html", {"type": "error", "message": "Bu işlemi yapmak için yetkiniz yok."})
コード例 #13
0
ファイル: views.py プロジェクト: ozgurlukicin/ozgurlukicin
def themeitem_change_packagescreenshot(request, item_id):
    object = get_object_or_404(PackageScreenshot, pk=item_id)
    if request.user == object.author or request.user.has_perm("can_change_themeitem"):
        if request.method == "POST":
            form = PackageScreenshotForm(request.POST.copy(), request.FILES)
            flood, timeout = flood_control(request)
            if flood:
                render_response(request, "tema/message.html", {"type": "error", "message": "Lütfen %s saniye sonra tekrar deneyiniz." % timeout })

            if form.is_valid():
                object.title = form.cleaned_data["title"]
                object.license = form.cleaned_data["license"]
                object.text = form.cleaned_data["text"]
                old_version = object.version
                object.version = form.cleaned_data["version"]
                object.update = datetime.datetime.now()
                object.image = form.cleaned_data["image"]

                #change slug
                slug = slugify(replace_turkish(object.title))
                object.slug = str(object.id) + "-" + slug

                #change image file name
                path, extension = '/'.join(object.image.name.split('/')[:-1]), object.image.name.split('.')[-1]
                object.image.name = "%s/%s.%s" % (path, object.title, extension)

                object.save()

                #create thumbnail
                thumbnail = Image.open(object.image.path)
                thumbnail.thumbnail((150,200), Image.ANTIALIAS)
                file = ContentFile("")
                object.thumbnail.save(object.image.path, file, save=True)
                thumbnail.save(object.thumbnail.path)

                #create thumbnail for package manager
                s_image = Image.open(object.image.path)
                s_image.thumbnail((270,190), Image.ANTIALIAS)
                file = ContentFile("")
                object.s_image.save(object.image.path, file, save=True)
                s_image.save(object.s_image.path)

                #post changes
                if object.version != old_version:
                    text="%s %s uygulamasının %s sürümüne ait paket görüntüsünü %s sürümüne güncelledi." % (request.user, object.title, old_version, object.version)
                    post = Post(topic=object.topic,
                                author=request.user,
                                text=text,
                            )
                    post.save()

                return HttpResponseRedirect(object.get_absolute_url())

            else:
                return render_response(request, "tema/themeitem_change.html", locals())
        else:
            default_data = {"title": object.title,
                            "license": object.license,
                            "text": object.text,
                            "version": object.version,
                            "tags": object.tags.all(),
                            "origin_url": object.origin_url,
                            "image": object.image,
                            }

            form = PackageScreenshotForm(initial=default_data)

        return render_response(request, "tema/themeitem_change.html", locals())

    else:
        return render_response(request, "tema/message.html", {"type": "error", "message": "Bu işlemi yapmak için yetkiniz yok."})
コード例 #14
0
def reply(request, forum_slug, topic_id, quote_id=False):
    topic = get_object_or_404(Topic, pk=topic_id)

    posts = topic.post_set.order_by('-created')[:POSTS_PER_PAGE]

    if topic.locked:
        return render_response(request, "forum/forum_error.html",
                               {"message": "Başlık kilitli."})

    if request.method == 'POST':
        form = PostForm(request.POST.copy())

        flood, timeout = flood_control(request)

        if form.is_valid() and not flood:
            post = Post(topic=topic,
                        author=request.user,
                        text=form.cleaned_data['text'])
            post.save()

            # generate post url
            post_url = WEB_URL + post.get_absolute_url()
            # generate In-Reply-To header. If we get quote that should be quote's message id
            if request.POST.has_key('quote_id'):
                quote = get_object_or_404(Post, id=request.POST['quote_id'])
                in_reply_to = quote.get_email_id()
            else:
                in_reply_to = topic.get_email_id()

            # sorry, we have to send <style> to be able to display quotation correctly. Hardcode for now and I know, It's really UGLY!
            # FIXME: Give postmarkup.py's QuoteTag e-mail rendering support

            css = """<style type="text/css">
.quote {
    border: 1px solid #CCCCCC;
    padding: 10px;
    margin-bottom: 8px;
    background-color: #E1E3FF;
    color: #51615D;
}

.quote p {
    padding-left: 12px;
    font-style: italic;
}
</style>"""

            # send email to everyone who follows this topic.
            watchlists = WatchList.objects.filter(topic__id=topic_id)
            for watchlist in watchlists:
                send_mail_with_header(
                    '[Ozgurlukicin-forum] Re: %s' % topic.title,
                    '%s\n%s<br /><br /><a href="%s">%s</a>' %
                    (css, render_bbcode(
                        form.cleaned_data['text']), post_url, post_url),
                    '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL),
                    [watchlist.user.email],
                    headers={
                        'Message-ID': post.get_email_id(),
                        'In-Reply-To': in_reply_to
                    },
                    fail_silently=True)

            # send mailing list also.
            # send_mail_with_header('Re: %s' % topic.title,
            #                       '%s\n%s<br /><br /><a href="%s">%s</a>' % (css, render_bbcode(form.cleaned_data['text']), post_url, post_url),
            #                       '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL),
            #                       [FORUM_MESSAGE_LIST],
            #                       headers = {'Message-ID': post.get_email_id(),
            #                                  'In-Reply-To': in_reply_to},
            #                       fail_silently = True
            #                       )

            return HttpResponseRedirect(post.get_absolute_url())
    else:
        if quote_id:
            post = get_object_or_404(Post, pk=quote_id)

            if post in topic.post_set.all():
                form = PostForm(
                    auto_id=True,
                    initial={
                        'text':
                        '[quote <b>%s</b>, %s tarihinde:]%s[/quote]' %
                        (post.author, post.edited.strftime("%d/%m/%Y %H:%M"),
                         post.text)
                    })
            # if quote doesn't belong to this topic, just redirect to what user gets :)
            else:
                return HttpResponseRedirect(post.get_absolute_url())
        else:
            form = PostForm(auto_id=True)

    if request.user.has_perm("forum.can_change_abusereport"):
        abuse_count = AbuseReport.objects.count()

    return render_response(request, 'forum/reply.html', locals())
コード例 #15
0
ファイル: views.py プロジェクト: ozgurlukicin/ozgurlukicin
def reply(request, forum_slug, topic_id, quote_id=False):
    topic = get_object_or_404(Topic, pk=topic_id)

    posts = topic.post_set.order_by('-created')[:POSTS_PER_PAGE]

    if topic.locked:
        return render_response(request, "forum/forum_error.html", {"message": "Başlık kilitli."})

    if request.method == 'POST':
        form = PostForm(request.POST.copy())

        flood,timeout = flood_control(request)

        if form.is_valid() and not flood:
            post = Post(topic=topic,
                        author=request.user,
                        text=form.cleaned_data['text']
                       )
            post.save()

            # generate post url
            post_url = WEB_URL + post.get_absolute_url()
            # generate In-Reply-To header. If we get quote that should be quote's message id
            if request.POST.has_key('quote_id'):
                quote = get_object_or_404(Post, id=request.POST['quote_id'])
                in_reply_to = quote.get_email_id()
            else:
                in_reply_to = topic.get_email_id()

            # sorry, we have to send <style> to be able to display quotation correctly. Hardcode for now and I know, It's really UGLY!
            # FIXME: Give postmarkup.py's QuoteTag e-mail rendering support

            css = """<style type="text/css">
.quote {
    border: 1px solid #CCCCCC;
    padding: 10px;
    margin-bottom: 8px;
    background-color: #E1E3FF;
    color: #51615D;
}

.quote p {
    padding-left: 12px;
    font-style: italic;
}
</style>"""

            # send email to everyone who follows this topic.
            watchlists = WatchList.objects.filter(topic__id=topic_id)
            for watchlist in watchlists:
                send_mail_with_header('[Ozgurlukicin-forum] Re: %s' % topic.title,
                                      '%s\n%s<br /><br /><a href="%s">%s</a>' % (css, render_bbcode(form.cleaned_data['text']), post_url, post_url),
                                      '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL),
                                      [watchlist.user.email],
                                      headers = {'Message-ID': post.get_email_id(),
                                                 'In-Reply-To': in_reply_to},
                                      fail_silently = True
                                      )

            # send mailing list also.
            # send_mail_with_header('Re: %s' % topic.title,
            #                       '%s\n%s<br /><br /><a href="%s">%s</a>' % (css, render_bbcode(form.cleaned_data['text']), post_url, post_url),
            #                       '%s <%s>' % (request.user.username, FORUM_FROM_EMAIL),
            #                       [FORUM_MESSAGE_LIST],
            #                       headers = {'Message-ID': post.get_email_id(),
            #                                  'In-Reply-To': in_reply_to},
            #                       fail_silently = True
            #                       )

            return HttpResponseRedirect(post.get_absolute_url())
    else:
        if quote_id:
            post = get_object_or_404(Post, pk=quote_id)

            if post in topic.post_set.all():
                form = PostForm(auto_id=True, initial={'text': '[quote <b>%s</b>, %s tarihinde:]%s[/quote]' % (post.author, post.edited.strftime("%d/%m/%Y %H:%M"), post.text)})
            # if quote doesn't belong to this topic, just redirect to what user gets :)
            else:
                return HttpResponseRedirect(post.get_absolute_url())
        else:
            form = PostForm(auto_id=True)

    if request.user.has_perm("forum.can_change_abusereport"):
        abuse_count = AbuseReport.objects.count()

    return render_response(request, 'forum/reply.html', locals())
コード例 #16
0
def themeitem_change_packagescreenshot(request, item_id):
    object = get_object_or_404(PackageScreenshot, pk=item_id)
    if request.user == object.author or request.user.has_perm(
            "can_change_themeitem"):
        if request.method == "POST":
            form = PackageScreenshotForm(request.POST.copy(), request.FILES)
            flood, timeout = flood_control(request)
            if flood:
                render_response(
                    request, "tema/message.html", {
                        "type":
                        "error",
                        "message":
                        "Lütfen %s saniye sonra tekrar deneyiniz." % timeout
                    })

            if form.is_valid():
                object.title = form.cleaned_data["title"]
                object.license = form.cleaned_data["license"]
                object.text = form.cleaned_data["text"]
                old_version = object.version
                object.version = form.cleaned_data["version"]
                object.update = datetime.datetime.now()
                object.image = form.cleaned_data["image"]

                #change slug
                slug = slugify(replace_turkish(object.title))
                object.slug = str(object.id) + "-" + slug

                #change image file name
                path, extension = '/'.join(object.image.name.split(
                    '/')[:-1]), object.image.name.split('.')[-1]
                object.image.name = "%s/%s.%s" % (path, object.title,
                                                  extension)

                object.save()

                #create thumbnail
                thumbnail = Image.open(object.image.path)
                thumbnail.thumbnail((150, 200), Image.ANTIALIAS)
                file = ContentFile("")
                object.thumbnail.save(object.image.path, file, save=True)
                thumbnail.save(object.thumbnail.path)

                #create thumbnail for package manager
                s_image = Image.open(object.image.path)
                s_image.thumbnail((270, 190), Image.ANTIALIAS)
                file = ContentFile("")
                object.s_image.save(object.image.path, file, save=True)
                s_image.save(object.s_image.path)

                #post changes
                if object.version != old_version:
                    text = "%s %s uygulamasının %s sürümüne ait paket görüntüsünü %s sürümüne güncelledi." % (
                        request.user, object.title, old_version,
                        object.version)
                    post = Post(
                        topic=object.topic,
                        author=request.user,
                        text=text,
                    )
                    post.save()

                return HttpResponseRedirect(object.get_absolute_url())

            else:
                return render_response(request, "tema/themeitem_change.html",
                                       locals())
        else:
            default_data = {
                "title": object.title,
                "license": object.license,
                "text": object.text,
                "version": object.version,
                "tags": object.tags.all(),
                "origin_url": object.origin_url,
                "image": object.image,
            }

            form = PackageScreenshotForm(initial=default_data)

        return render_response(request, "tema/themeitem_change.html", locals())

    else:
        return render_response(request, "tema/message.html", {
            "type": "error",
            "message": "Bu işlemi yapmak için yetkiniz yok."
        })
コード例 #17
0
ファイル: views.py プロジェクト: ozgurlukicin/ozgurlukicin
def themeitem_change_openofficetheme(request, item_id):
    object = get_object_or_404(OpenOfficeTheme, pk=item_id)
    if request.user == object.author or request.user.has_perm("can_change_themeitem"):
        if request.method == "POST":
            form = OpenOfficeThemeForm(request.POST.copy(), request.FILES)
            flood, timeout = flood_control(request)

            if flood:
                render_response(request, "tema/message.html", {"type": "error", "message": "Lütfen %s saniye sonra tekrar deneyiniz." % timeout })

            if form.is_valid():
                object.title = form.cleaned_data["title"]
                object.category = form.cleaned_data["category"]
                object.license = form.cleaned_data["license"]
                object.text = form.cleaned_data["text"]
                old_version = object.version
                object.version = form.cleaned_data["version"]
                object.file = form.cleaned_data["file"]
                screenshot = form.cleaned_data["screenshot"]
                object.update = datetime.datetime.now()

                if screenshot != None:
                    object.screenshot = screenshot

                #change slug
                slug = slugify(replace_turkish(object.title))
                object.slug = str(object.id) + "-" + slug

                object.save()

                #create thumbnail
                thumbnail = Image.open(object.screenshot.path)
                thumbnail.thumbnail((150,200), Image.ANTIALIAS)
                file = ContentFile("")
                object.thumbnail.save(object.screenshot.path, file, save=True)
                thumbnail.save(object.thumbnail.path)

                #post changes
                if object.version != old_version:
                    text = "%s %s sürümlü %s OpenOffice.org öğesini %s sürümüne güncelledi." % (request.user, old_version, object.title, object.version)
                    post = Post(topic=object.topic,
                                author=request.user,
                                text=text,
                                )
                    post.save()

                return HttpResponseRedirect(object.get_absolute_url())

            else:
                return render_response(request, "tema/themeitem_add_openofficetheme.html", locals())
        else:
            default_data = {"title": object.title,
                            "category": object.category,
                            "license": object.license,
                            "text": object.text,
                            "version": object.version,
                            "tags": object.tags.all(),
                            "origin_url": object.origin_url,
                            "file": object.file,
                            "screenshot": object.screenshot,
                            }
            form = OpenOfficeThemeForm(initial=default_data)

        return render_response(request, "tema/themeitem_change.html", locals())

    else:
        return render_response(request, "tema/message.html", {"type": "error", "message": "Bu işlemi yapmak için yetkiniz yok."})
コード例 #18
0
def themeitem_change_openofficetheme(request, item_id):
    object = get_object_or_404(OpenOfficeTheme, pk=item_id)
    if request.user == object.author or request.user.has_perm(
            "can_change_themeitem"):
        if request.method == "POST":
            form = OpenOfficeThemeForm(request.POST.copy(), request.FILES)
            flood, timeout = flood_control(request)

            if flood:
                render_response(
                    request, "tema/message.html", {
                        "type":
                        "error",
                        "message":
                        "Lütfen %s saniye sonra tekrar deneyiniz." % timeout
                    })

            if form.is_valid():
                object.title = form.cleaned_data["title"]
                object.category = form.cleaned_data["category"]
                object.license = form.cleaned_data["license"]
                object.text = form.cleaned_data["text"]
                old_version = object.version
                object.version = form.cleaned_data["version"]
                object.file = form.cleaned_data["file"]
                screenshot = form.cleaned_data["screenshot"]
                object.update = datetime.datetime.now()

                if screenshot != None:
                    object.screenshot = screenshot

                #change slug
                slug = slugify(replace_turkish(object.title))
                object.slug = str(object.id) + "-" + slug

                object.save()

                #create thumbnail
                thumbnail = Image.open(object.screenshot.path)
                thumbnail.thumbnail((150, 200), Image.ANTIALIAS)
                file = ContentFile("")
                object.thumbnail.save(object.screenshot.path, file, save=True)
                thumbnail.save(object.thumbnail.path)

                #post changes
                if object.version != old_version:
                    text = "%s %s sürümlü %s OpenOffice.org öğesini %s sürümüne güncelledi." % (
                        request.user, old_version, object.title,
                        object.version)
                    post = Post(
                        topic=object.topic,
                        author=request.user,
                        text=text,
                    )
                    post.save()

                return HttpResponseRedirect(object.get_absolute_url())

            else:
                return render_response(
                    request, "tema/themeitem_add_openofficetheme.html",
                    locals())
        else:
            default_data = {
                "title": object.title,
                "category": object.category,
                "license": object.license,
                "text": object.text,
                "version": object.version,
                "tags": object.tags.all(),
                "origin_url": object.origin_url,
                "file": object.file,
                "screenshot": object.screenshot,
            }
            form = OpenOfficeThemeForm(initial=default_data)

        return render_response(request, "tema/themeitem_change.html", locals())

    else:
        return render_response(request, "tema/message.html", {
            "type": "error",
            "message": "Bu işlemi yapmak için yetkiniz yok."
        })
コード例 #19
0
def main(request,
         idea_id=-1,
         page_number=1,
         order="date",
         filter_by="none",
         filter="none"):
    order_dict = {
        'date': '-dateSubmitted',
        'vote_value': '-vote_value',
        'title': 'title',
        'vote_count': 'vote_count',
        'neg_date': 'dateSubmitted',
        'neg_vote_value': 'vote_value',
        'neg_title': '-title',
        'neg_vote_count': '-vote_count'
    }

    if request.POST:
        idea = get_object_or_404(Idea, pk=idea_id)
        is_change_status = 0
        try:
            if idea.status != get_object_or_404(Status,
                                                name=request.POST['status']):
                is_change_status = 1
                idea.status = get_object_or_404(Status,
                                                name=request.POST['status'])
                #and send forum that status changed
                topic = idea.topic
                post_text = "<b> Bu fikrin durumu " + idea.status.name + " olarak değiştirildi </b>"
                post = Post(topic=topic, author=request.user, text=post_text)
                post.save()
                topic.topic_latest_post = post
                topic.posts += 1
                topic.save()
                topic.forum.forum_latest_post = post
                topic.forum.posts += 1
                topic.forum.save()
        except:
            idea.status = Status()
        try:
            if is_change_status:
                is_change_status = 0
            else:
                idea.category = get_object_or_404(
                    Category, name=request.POST['category'])
                #and send forum that category changed
                topic = idea.topic
                post_text = "<b> Bu fikrin kategorisi " + idea.category.name + " olarak değiştirildi </b>"
                post = Post(topic=topic, author=request.user, text=post_text)
                post.save()
                topic.topic_latest_post = post
                topic.posts += 1
                topic.save()
                topic.forum.forum_latest_post = post
                topic.forum.posts += 1
                topic.forum.save()
        except:
            idea.category = Category()

        idea.save()
        return HttpResponseRedirect(reverse('oi.beyin2.views.main'))
    else:
        #idea list order changes
        all_idea_list = Idea.objects.filter(is_hidden=False).order_by(
            order_dict[order])
        #idea list filter changes
        if filter_by == "user":
            all_idea_list = Idea.objects.filter(is_hidden=False,
                                                submitter=filter).order_by(
                                                    order_dict[order])
        if filter_by == "tag":
            tag = Tag.objects.get(name=filter)
            all_idea_list = tag.idea_set.filter(is_hidden=False).order_by(
                order_dict[order])
        if filter_by == "favorite":
            favorites = Favorite.objects.filter(user=request.user)
            try:
                favorites[0]
                all_idea_list = []
                for favorite in favorites:
                    all_idea_list.append(favorite.idea)
            except:
                return render_response(
                    request, 'beyin2/idea_errorpage.html', {
                        'error': 'İsteğe uygun fikir bulunamadı.',
                    })
        if filter_by == "today":
            all_idea_list = Idea.objects.filter(
                is_hidden=False,
                dateSubmitted__gt=datetime.now() - timedelta(1)).order_by(
                    order_dict[order])
        if filter_by == "this_week":
            all_idea_list = Idea.objects.filter(
                is_hidden=False,
                dateSubmitted__gt=datetime.now() - timedelta(7)).order_by(
                    order_dict[order])
        if filter_by == "this_month":
            all_idea_list = Idea.objects.filter(
                is_hidden=False,
                dateSubmitted__gt=datetime.now() - timedelta(10)).order_by(
                    order_dict[order])
        if filter_by == "category":
            all_idea_list = Idea.objects.filter(is_hidden=False,
                                                category=filter).order_by(
                                                    order_dict[order])
        if filter_by == "status":
            all_idea_list = Idea.objects.filter(
                is_hidden=False, status=filter).order_by(order_dict[order])
        if filter_by == "deleted":
            all_idea_list = Idea.objects.filter(is_hidden=True,
                                                is_duplicate=False).order_by(
                                                    order_dict[order])
        if filter_by == "duplicate":
            all_idea_list = Idea.objects.filter(is_duplicate=True).order_by(
                order_dict[order])
        # add vote_counts for every vote, intended to use in preview on votebar
        '''
        # using this causes Django to fetch all object from database
        # refer to this : http://docs.djangoproject.com/en/dev/topics/db/queries/#querysets-are-lazy
        # set vote_text when user votes or just calculate this for listed objects
        for idea in all_idea_list:
            pos_votes = Vote.objects.filter( vote = 'U', idea = idea).count()
            notr_votes = Vote.objects.filter( vote = 'N', idea = idea ).count()
            neg_votes = Vote.objects.filter( vote = 'D', idea = idea ).count()
            idea.vote_text =  "Olumlu: %s Kararsız: %s Olumsuz: %s" %(pos_votes, notr_votes, neg_votes )
        '''

        status_list = Status.objects.all().order_by("name")
        category_list = Category.objects.all().order_by("name")
        if not all_idea_list:
            return render_response(request, 'beyin2/idea_errorpage.html', {
                'error': 'İsteğe uygun fikir bulunamadı.',
            })
        paginator = Paginator(all_idea_list, idea_per_page)
        idea_list = paginator.page(page_number)
        last_page = len(paginator.page_range)
        if int(page_number) < last_page - 4:
            show_go_to_last = True
        else:
            show_go_to_last = False
        if int(page_number) > 5:
            show_go_to_first = True
        else:
            show_go_to_first = False
        if int(page_number) > 4:
            page_range = paginator.page_range[int(page_number) -
                                              5:(int(page_number) + 4)]
        else:
            page_range = paginator.page_range[0:(int(page_number) + 4)]
        #we dont want to show default category, so we sould send the name to check if it is
        def_cate = get_object_or_404(Status, pk=DefaultCategory)
        '''
        for idea in idea_list.object_list:
            idea.duplicate_list = Idea.objects.filter( duplicate = idea )
        '''
        return render_response(
            request, 'beyin2/idea_list.html', {
                'idea_list': idea_list,
                'status_list': status_list,
                'category_list': category_list,
                'order': order,
                'come_from': 'main',
                'page_range': page_range,
                'show_go_to_last': show_go_to_last,
                'show_go_to_first': show_go_to_first,
                'last_page': last_page,
                'default_category': def_cate,
                'filter': filter,
                'filter_by': filter_by
            })