Exemplo n.º 1
0
def request_community_creation(request):
    if request.user.is_authenticated:
        if request.method == 'POST':
            name = request.POST['name']
            desc = request.POST['desc']
            category = request.POST['category']
            tag_line = request.POST['tag_line']
            purpose = request.POST['purpose']
            status = request.POST['status']
            requestcommunitycreation = RequestCommunityCreation.objects.create(
                name=name,
                desc=desc,
                category=category,
                tag_line=tag_line,
                purpose=purpose,
                requestedby=request.user,
                email=request.user.email,
                status=status)
            return redirect('user_dashboard')
        else:
            sysrep = SystemRep.objects.get(user=request.user)
            defaultval = get_reputation_values()
            srep = sysrep.sysrep
            if (
                    srep > defaultval.min_srep_for_comm
            ):  #checking if the user system reputation is greater than the minimum reputation required to create a community
                return render(request, 'request_community_creation.html')
            return render(request, 'lowrepcom.html')
    else:
        return redirect('login')
Exemplo n.º 2
0
def article_report(request, pk):
    community = Community.objects.get(pk=pk)
    if request.method == 'POST':
        pk1 = int(request.POST.get('pk1'))
        article_reported = ArticleReport.objects.get(pk=pk1)
        status = request.POST.get('status')
        defaultval = get_reputation_values()
        article = article_reported.article
        article_vote = ArticleVotes.objects.get(article=article)
        publisher = article_vote.published_by
        if (status == 'approve'):
            approve_report(pk, article, publisher, community, defaultval)
        else:
            reject_report(article, defaultval)

        voteflags = VotingFlag.objects.filter(article=article, reportflag=True)
        for voteflag in voteflags:
            voteflag.reportflag = False
            voteflag.report_reason = ''
            voteflag.save()
        articlevotes = ArticleVotes.objects.get(
            article=article_reported.article)
        articlevotes.report = 0
        articlevotes.save()
        ArticleReport.objects.filter(pk=pk1).delete()
    articles_reported = ArticleReport.objects.filter(community=community)
    membership = CommunityMembership.objects.get(user=request.user,
                                                 community=community)
    return render(
        request, 'article_report.html', {
            'articles_reported': articles_reported,
            'community': community,
            'membership': membership
        })
Exemplo n.º 3
0
def remove_report(user, resource_id, community, reason):
    voteflag = VotingFlag.objects.get(user=user, article_id=resource_id)
    voteflag.reportflag = False
    voteflag.report_reason = reason
    voteflag.save()
    article_votes = ArticleVotes.objects.get(article_id=resource_id)
    article_votes.report -= 1
    article_votes.save()
    defaultval = get_reputation_values()
    if (article_votes.report < defaultval.threshold_report):
        article = Articles.objects.get(pk=resource_id)
        if ArticleReport.objects.filter(article=article).exists():
            ArticleReport.objects.filter(article=article).delete()
    else:
        article = Articles.objects.get(pk=resource_id)
        ArticleReport.objects.filter(
            community=community,
            article=article).update(no_of_report=article_votes.report)
Exemplo n.º 4
0
def add_report(user, resource_id, community, reason):
    voteflag = VotingFlag.objects.get(user=user, article_id=resource_id)
    voteflag.reportflag = True
    voteflag.report_reason = reason
    voteflag.save()
    article_votes = ArticleVotes.objects.get(article_id=resource_id)
    article_votes.report += 1
    article_votes.save()
    defaultval = get_reputation_values()
    if (article_votes.report >= defaultval.threshold_report):
        article = Articles.objects.get(pk=resource_id)
        if not ArticleReport.objects.filter(article=article).exists():
            ArticleReport.objects.create(community=community,
                                         article=article,
                                         no_of_report=article_votes.report)
        else:
            ArticleReport.objects.filter(
                community=community,
                article=article).update(no_of_report=article_votes.report)
Exemplo n.º 5
0
def create_community(request):
    errormessage = ''
    if request.user.is_superuser:
        if request.method == 'POST':
            username = request.POST['username']
            try:
                usr = User.objects.get(username=username)
                name = request.POST['name']
                desc = request.POST['desc']
                category = request.POST['category']
                tag_line = request.POST['tag_line']
                role = Roles.objects.get(name='community_admin')

                # Create Forum for this community
                from django.db import connection
                cursor = connection.cursor()
                cursor.execute(
                    ''' select tree_id from forum_forum order by tree_id DESC limit 1'''
                )
                tree_id = cursor.fetchone()[0] + 1
                slug = "-".join(name.lower().split())
                #return HttpResponse(str(tree_id))
                insert_stmt = (
                    "INSERT INTO forum_forum (created,updated,name,slug,description,link_redirects,type,link_redirects_count,display_sub_forum_list,lft,rght,tree_id,level,direct_posts_count,direct_topics_count) "
                    "VALUES (NOW(), NOW(), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
                )
                data = (name, slug, desc, 0, 0, 0, 1, 1, 2, tree_id, 0, 0, 0)
                try:
                    cursor.execute(insert_stmt, data)
                    cursor.execute(
                        ''' select id from forum_forum order by id desc limit 1'''
                    )
                    forum_link = slug + '-' + str(cursor.fetchone()[0])
                except:
                    errormessage = 'Can not create default forum for this community'
                    return render(request, 'new_community.html',
                                  {'errormessage': errormessage})

                community = Community.objects.create(
                    name=name,
                    desc=desc,
                    category=category,
                    image=request.FILES['community_image'],
                    tag_line=tag_line,
                    created_by=usr,
                    forum_link=forum_link)
                communitymembership = CommunityMembership.objects.create(
                    user=usr, community=community, role=role)
                commrep = CommunityRep(
                )  #createing a new CommunityRep row has the community creation has been approved
                commrep.user = usr
                commrep.community = community
                commrep.rep = 3001  #he will be the community admin so his community reputation should be above 3000
                sysrep = SystemRep.objects.get(user=usr)
                defaultval = get_reputation_values()
                sysrep.sysrep += defaultval.srep_for_comm_creation  #increasing the user system reputation has he has created a new community
                sysrep.save()
                commrep.save()

                return redirect('community_view', community.pk)
            except User.DoesNotExist:
                errormessage = 'user does not exist'
                return render(request, 'new_community.html',
                              {'errormessage': errormessage})
        else:
            return render(request, 'new_community.html')
    else:
        return redirect('home')
Exemplo n.º 6
0
def handle_community_creation_requests(request):

    if request.user.is_superuser:
        if request.method == 'POST':
            pk = request.POST['pk']
            rcommunity = RequestCommunityCreation.objects.get(pk=pk)
            user = rcommunity.requestedby
            status = request.POST['status']
            if status == 'approve' and rcommunity.status != 'approved':

                # Create Forum for this community
                from django.db import connection
                cursor = connection.cursor()
                cursor.execute(
                    ''' select tree_id from forum_forum order by tree_id DESC limit 1'''
                )
                tree_id = cursor.fetchone()[0] + 1
                slug = "-".join(rcommunity.name.lower().split())
                #return HttpResponse(str(tree_id))
                insert_stmt = (
                    "INSERT INTO forum_forum (created,updated,name,slug,description,link_redirects,type,link_redirects_count,display_sub_forum_list,lft,rght,tree_id,level,direct_posts_count,direct_topics_count) "
                    "VALUES (NOW(), NOW(), %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
                )
                data = (rcommunity.name, slug, rcommunity.desc, 0, 0, 0, 1, 1,
                        2, tree_id, 0, 0, 0)
                try:
                    cursor.execute(insert_stmt, data)
                    cursor.execute(
                        ''' select id from forum_forum order by id desc limit 1'''
                    )
                    forum_link = slug + '-' + str(cursor.fetchone()[0])
                except:
                    errormessage = 'Can not create default forum for this community'
                    return render(request, 'new_community.html',
                                  {'errormessage': errormessage})

                communitycreation = Community.objects.create(
                    name=rcommunity.name,
                    desc=rcommunity.desc,
                    tag_line=rcommunity.tag_line,
                    category=rcommunity.category,
                    created_by=rcommunity.requestedby,
                    forum_link=forum_link)
                communityadmin = Roles.objects.get(name='community_admin')
                communitymembership = CommunityMembership.objects.create(
                    user=rcommunity.requestedby,
                    community=communitycreation,
                    role=communityadmin)
                rcommunity.status = 'approved'
                rcommunity.save()

                commrep = CommunityRep(
                )  #createing a new CommunityRep row has the community creation has been approved
                commrep.user = rcommunity.requestedby
                commrep.community = communitycreation
                commrep.rep = 3001  #he will be the community admin so his community reputation should be above 3000
                sysrep = SystemRep.objects.get(user=rcommunity.requestedby)
                defaultval = get_reputation_values()
                sysrep.sysrep += defaultval.srep_for_comm_creation  #increasing the user system reputation has he has created a new community
                sysrep.save()
                commrep.save()
                rolechange(commrep, rcommunity.requestedby, communitycreation)
            if status == 'reject' and rcommunity.status != 'rejected':
                rcommunity.status = 'rejected'
                rcommunity.save()

        requestcommunitycreation = RequestCommunityCreation.objects.filter(
            status='Request')
        return render(request, 'community_creation_requests.html',
                      {'requestcommunitycreation': requestcommunitycreation})
    else:
        return redirect('login')