Ejemplo n.º 1
0
def downvote2(request):
    downvotes = 0
    if request.method == 'GET':
        post_id = request.GET['post_id']
        thread_id = request.GET['thread_id']
        post = Post.objects.get(pk=post_id)
        if request.user.is_authenticated():
            if Vote.objects.filter(post=post,
                                   upordown=0,
                                   user=UserProfile.objects.get(
                                       user=request.user)).count() == 0:
                post.downvotes = post.downvotes + 1
                downvotes = post.downvotes
                post.save()
                v = Vote()
                v.user = UserProfile.objects.get(user=request.user)
                v.post = post
                v.upordown = 0
                v.save()
            else:
                downvotes = post.downvotes
        thread = Thread.objects.get(id=thread_id)
        post = Post.objects.get(id=post_id)
        userp = UserProfile.objects.get(user=request.user)
        noti = Notification(member=post.posted_by,
                            msg_type='DW',
                            msg='' + userp.user.first_name +
                            ' has downvoted your comment ',
                            link='/th/' + str(thread.id))
        noti.save()
    return HttpResponse(downvotes)
Ejemplo n.º 2
0
def create_post(request, thread_id):
    if request.method == 'POST':
        print 'in view'
        post_text = request.POST.get('the_post')
        print post_text
        # post_text= request.POST['the_post']
        thread = Thread.objects.get(pk=thread_id)
        response_data = {}
        userp = UserProfile.objects.get(user=request.user)
        post = Post(msg=post_text, posted_by=userp, thread=thread)
        post.save()
        noti = Notification(member=thread.started_by,
                            msg_type='PO',
                            msg='' + userp.user.first_name +
                            ' has posted in your thread ' + thread.heading,
                            link='/th/' + str(thread.id))
        noti.save()
        response_data['result'] = 'Create post successful!'
        response_data['postpk'] = post.pk
        response_data['text'] = post.msg
        response_data['created'] = post.posted_at.strftime(
            '%B %d, %Y %I:%M %p')
        response_data['author'] = post.posted_by.user.first_name
        response_data['pic_path'] = "/media/" + str(
            post.posted_by.user.userprofile.picture)
        response_data['thread_id'] = thread_id

        return HttpResponse(json.dumps(response_data),
                            content_type="application/json")
    else:
        return HttpResponse(json.dumps(
            {"nothing to see": "this isn't happening"}),
                            content_type="application/json")
Ejemplo n.º 3
0
def updatetask(request, task_id, project_id):
    task = Task.objects.get(pk=task_id)
    members = task.member.all()
    flag = 0
    person = UserProfile.objects.get(user=request.user)
    print person.pk
    for m in members:
        if m == person:
            flag = 1
            break
    if flag == 1:
        print "Authenticated member"
        task.progress = request.POST['progress']
        commit = Commit()
        commit.project = project_id
        commit.user = request.user.username
        commit.commit_prog = request.POST['progress']
        commit.commit_msg = request.POST['commit_msg']
        commit.save()
        task.last_commit = commit
        task.save()
        project = Project.objects.get(id=project_id)
        print project.admin
        project_admin = UserProfile.objects.get(user__email=project.admin)
        noti = Notification(member=project_admin,
                            msg_type='UT',
                            msg='' + person.user.first_name +
                            ' has updated a task in ' + project.name,
                            link='/' + str(project.id) + '/viewproject')
        noti.save()
    return HttpResponseRedirect('/' + str(person.pk) + '-' + project_id +
                                '/tasks')
Ejemplo n.º 4
0
def addtask(request, project_id):
    project = Project.objects.get(pk=project_id)
    if request.method == "POST":
        task_form = TaskForm(data=request.POST)
        member_to_add = request.POST['member']
        print 'printing member', member_to_add
        member = UserProfile.objects.get(id=member_to_add)
        task = task_form.save(commit=False)
        task.progress = 0
        task.last_commit = commit
        task.save()
        task.member.add(member_to_add)
        task.project.add(project)
        noti = Notification(member=member,
                            msg_type='AT',
                            msg='You have just been assigned a new task in ' +
                            project.name,
                            link='/' + str(project.id) + '/viewproject')
        noti.save()
        return HttpResponseRedirect('/dashboard')
    else:
        print request.user
        task_form = TaskForm()
        # pic_path= str(request.user.userprofile.picture)
        context = {
            'project': project,
            'task_form': task_form,
        }
        load_defaults(request, context)
        context['page_title'] = 'Add a Task'
        return render(request, 'site/addtask.html', context)
Ejemplo n.º 5
0
def reject(request, user_id, project_id):
    if request.user.username == Project.objects.get(pk=project_id).admin:
        print "Admin"
        project2 = Project.objects.get(pk=project_id)
        user = UserProfile.objects.get(pk=user_id)
        mem = Membership.objects.get(person=user, project=project2)
        mem.delete()
        noti = Notification(member=user,
                            msg_type='AP',
                            msg='' + request.user.first_name +
                            ' has rejected your project request for ' +
                            project2.name,
                            link='/' + str(project2.id) + '/viewproject')
        noti.save()
        return HttpResponseRedirect('/dashboard')
    else:
        return HttpResponseRedirect('/logout')
Ejemplo n.º 6
0
def applytoproject(request, project_id):
    user = UserProfile.objects.get(user=request.user)
    project = Project.objects.get(pk=project_id)
    project_members = Membership.objects.filter(project=project,
                                                confirmed=True)
    no_of_members = len(project_members)
    if no_of_members < project.max_members:
        membership = Membership.objects.create(person=user, project=project)
        membership.save()
        project_admin = UserProfile.objects.get(user__email=project.admin)
        noti = Notification(member=project_admin,
                            msg_type='Applied',
                            msg='' + user.user.first_name +
                            ' has applied for the project ' + project.name,
                            link='/' + str(project.id) + '/viewproject')
        noti.save()
    return HttpResponseRedirect("/" + str(project_id) + "/viewproject")