예제 #1
0
파일: views.py 프로젝트: varunarora/OC
def reposition_cover_picture(request, project_id):
    try:
        project = Project.objects.get(pk=project_id)
    except:
        raise Http404

    if request.user not in project.admins.all():
        return APIUtilities._api_unauthorized_failure()

    left = request.GET.get('left', None)
    top = request.GET.get('top', None)

    try:
        project.cover_pic_position.top = int(top)
        project.cover_pic_position.left = int(left)
        project.cover_pic_position.save()

        return APIUtilities._api_success()
    except:
        context = {
            'title': 'Cannot reposition project cover picture.',
            'message': 'We failed to reposition the project cover picture. Please ' +
                'contact us if this problem persists.'
        }
        return APIUtilities._api_failure(context)    
예제 #2
0
파일: views.py 프로젝트: varunarora/OC
def delete_comment(request, comment_id):
    try:
        comment = Comment.objects.get(pk=comment_id)

        # TODO(Varun): Same logic as duplicated from template generation to show
        # delete button
        from interactions.CommentUtilities import CommentUtilities
        (host_type, host, root) = CommentUtilities.get_comment_root(comment)

        if host_type.name == 'project':
            if request.user == comment.user or request.user in host.admins.all():
                # Delete all descendant elements of this comment.
                delete_comment_tree(comment)
                return APIUtilities._api_success()

            else:
                return APIUtilities._api_unauthorized_failure()

        elif host_type.name == 'resource':
            if request.user == comment.user or (
                request.user in host.collaborators.all() or
                request.user == host.creator):
                    delete_comment_tree(comment)
                    return APIUtilities._api_success()            

        return APIUtilities._api_failure()

    except Comment.DoesNotExist:
        return APIUtilities._api_not_found()    
예제 #3
0
파일: views.py 프로젝트: varunarora/OC
def delete_event(request, event_id):
    try:
        event = Event.objects.get(pk=event_id)
    except:
        return APIUtilities._api_not_found()

    if request.user != event.user:
        return APIUtilities._api_unauthorized_failure()

    event.delete()
    return APIUtilities.success()
예제 #4
0
파일: views.py 프로젝트: varunarora/OC
def delete_curriculum(request, curriculum_id):
    try:
        curriculum = Curriculum.objects.get(pk=curriculum_id)
    except:
        return APIUtilities._api_not_found()

    if request.user != curriculum.user:
        return APIUtilities._api_unauthorized_failure()
    
    delete_individual_curriculum(curriculum)
    return APIUtilities.success()
예제 #5
0
파일: views.py 프로젝트: varunarora/OC
def delete_item(request, section_item_id):
    try:
        item = SectionItem.objects.get(pk=section_item_id)
    except:
        return APIUtilities._api_not_found()

    if not request.user:
        return APIUtilities._api_unauthorized_failure()

    delete_individual_item(item)

    return APIUtilities.success()
예제 #6
0
파일: views.py 프로젝트: varunarora/OC
def delete_section(request, section_id):
    try:
        section = Section.objects.get(pk=section_id)
    except:
        return APIUtilities._api_not_found()

    if not request.user:
        return APIUtilities._api_unauthorized_failure()

    for item in section.items.all():
        delete_individual_item(item)

    section.delete()

    return APIUtilities.success()
예제 #7
0
파일: views.py 프로젝트: varunarora/OC
def delete_class(request, class_id):
    try:
        class_to_delete = Class.objects.get(pk=class_id)
    except:
        return APIUtilities._api_not_found()

    if request.user != class_to_delete.user:
        return APIUtilities._api_unauthorized_failure()

    # Deep delete all events with this class link.
    events = Event.objects.filter(class_link=class_to_delete)
    for event in events:
        event.delete()

    class_to_delete.delete()
    return APIUtilities.success()
예제 #8
0
파일: views.py 프로젝트: varunarora/OC
def get_project_visibility(request, project_id):
    try:
        project = Project.objects.get(pk=project_id)

        if not request.user:
            return APIUtilities._api_unauthorized_failure()

        context = {
            'visibility': project.visibility
        }

        return APIUtilities._api_success(context)

    except:
        context = {
            'title': 'Could not get the visibility of this project.',
            'message': 'We failed to retrieve the visibility of '
            + 'this project. Please contact us if the problem persists.'
        }
        return APIUtilities._api_failure(context)
예제 #9
0
파일: views.py 프로젝트: varunarora/OC
def delete_category(request, project_id, category_id):
    try:
        category = GroupCategory.objects.get(pk=category_id)
        project = Project.objects.get(pk=project_id)
    except:
        return APIUtilities._api_not_found()

    if not request.user.is_authenticated() or request.user not in project.admins.all():
        context = {
            'title': 'You are not authorized to delete the category',
            'message': 'You need to be logged in as an administrator of the group ' +
                'to remove a member from the group.'
        }
        return APIUtilities._api_unauthorized_failure(context)

    group_categories = GroupCategory.objects.filter(parent=project).count()
    if group_categories == 1:
        context = {
            'title': 'Could not delete the only category.',
            'message': 'We failed to delete the category you marked for deletion ' +
                'as this is the only category in the group and you need to have atleast ' +
                'one category in a group. Create another category before you delete this one.'
        }
        return APIUtilities._api_failure(context)

    try:
        # Delete all the posts in this category.
        Comment.objects.filter(category=category).delete()

        category.delete()

        return APIUtilities._api_success()
    except:
        context = {
            'title': 'Could not delete the category.',
            'message': 'We failed to delete the category of this group '
            + 'due to an internal problem. Please contact us if this problem persists.'
        }
        return APIUtilities._api_failure(context)