Esempio n. 1
0
def view_visual_sheet(request, sheet_id):
    """
    View the sheet with sheet_id.
    """
    sheet = get_sheet(sheet_id)
    if "error" in sheet:
        return HttpResponse(sheet["error"])

    sheet["sources"] = annotate_user_links(sheet["sources"])

    # Count this as a view
    db.sheets.update({"id": int(sheet_id)}, {"$inc": {"views": 1}})

    try:
        owner = User.objects.get(id=sheet["owner"])
        author = owner.first_name + " " + owner.last_name
    except User.DoesNotExist:
        author = "Someone Mysterious"

    sheet_class     = make_sheet_class_string(sheet)
    can_edit_flag   = can_edit(request.user, sheet)
    can_add_flag    = can_add(request.user, sheet)

    return render_template(request,'sheets_visual.html', None, {
        "sheetJSON": json.dumps(sheet),
        "sheet": sheet,
        "sheet_class": sheet_class,
        "can_edit": can_edit_flag,
        "can_add": can_add_flag,
        "title": sheet["title"],
        "author": author,
        "is_owner": request.user.id == sheet["owner"],
        "is_public": sheet["status"] == "public",
        "current_url": request.get_full_path,
    })
Esempio n. 2
0
def view_sheet(request, sheet_id, editorMode = False):
    """
    View the sheet with sheet_id.
    """
    editor = request.GET.get('editor', '0')
    embed = request.GET.get('embed', '0')

    if editor != '1' and embed !='1' and editorMode is False:
        return catchall(request, sheet_id, True)

    sheet_id = int(sheet_id)
    sheet = get_sheet(sheet_id)
    if "error" in sheet and sheet["error"] != "Sheet updated.":
            return HttpResponse(sheet["error"])

    sheet["sources"] = annotate_user_links(sheet["sources"])

    # Count this as a view
    db.sheets.update({"id": sheet_id}, {"$inc": {"views": 1}})

    try:
        owner = User.objects.get(id=sheet["owner"])
        author = owner.first_name + " " + owner.last_name
    except User.DoesNotExist:
        author = "Someone Mysterious"

    sheet_class          = make_sheet_class_string(sheet)
    sheet_collections    = get_user_collections_for_sheet(request.user.id, sheet_id) if sheet["owner"] == request.user.id else None
    displayed_collection = Collection().load({"slug": sheet["displayedCollection"]}) if sheet.get("displayedCollection", None) else None
    embed_flag           = "embed" in request.GET
    likes                = sheet.get("likes", [])
    like_count           = len(likes)
    if request.user.is_authenticated:
        can_edit_flag    = can_edit(request.user, sheet)
        can_add_flag     = can_add(request.user, sheet)
        viewer_is_liker  = request.user.id in likes
    else:
        can_edit_flag    = False
        can_add_flag     = False
        viewer_is_liker  = False

    canonical_url = request.get_full_path().replace("?embed=1", "").replace("&embed=1", "")

    return render_template(request,'sheets.html', None, {
        "sheetJSON": json.dumps(sheet),
        "sheet": sheet,
        "sheet_class": sheet_class,
        "can_edit": can_edit_flag,
        "can_add": can_add_flag,
        "title": sheet["title"],
        "author": author,
        "is_owner": request.user.id == sheet["owner"],
        "sheet_collections": sheet_collections,
        "displayed_collection":  displayed_collection,
        "like_count": like_count,
        "viewer_is_liker": viewer_is_liker,
        "current_url": request.get_full_path,
        "canonical_url": canonical_url,
        "assignments_from_sheet":assignments_from_sheet(sheet_id),
    })
Esempio n. 3
0
def view_visual_sheet(request, sheet_id):
    """
    View the sheet with sheet_id.
    """
    sheet = get_sheet(sheet_id)
    if "error" in sheet:
        return HttpResponse(sheet["error"])

    sheet["sources"] = annotate_user_links(sheet["sources"])

    # Count this as a view
    db.sheets.update({"id": int(sheet_id)}, {"$inc": {"views": 1}})

    try:
        owner = User.objects.get(id=sheet["owner"])
        author = owner.first_name + " " + owner.last_name
        owner_groups = get_user_groups(
            request.user.id) if sheet["owner"] == request.user.id else None
    except User.DoesNotExist:
        author = "Someone Mysterious"
        owner_groups = None

    sheet_class = make_sheet_class_string(sheet)
    can_edit_flag = can_edit(request.user, sheet)
    can_add_flag = can_add(request.user, sheet)
    sheet_group = Group().load({
        "name": sheet["group"]
    }) if "group" in sheet and sheet["group"] != "None" else None
    embed_flag = "embed" in request.GET
    likes = sheet.get("likes", [])
    like_count = len(likes)
    viewer_is_liker = request.user.id in likes

    return render(
        request, 'sheets_visual.html', {
            "sheetJSON": json.dumps(sheet),
            "sheet": sheet,
            "sheet_class": sheet_class,
            "can_edit": can_edit_flag,
            "can_add": can_add_flag,
            "title": sheet["title"],
            "author": author,
            "is_owner": request.user.id == sheet["owner"],
            "is_public": sheet["status"] == "public",
            "owner_groups": owner_groups,
            "sheet_group": sheet_group,
            "like_count": like_count,
            "viewer_is_liker": viewer_is_liker,
            "current_url": request.get_full_path,
        })
Esempio n. 4
0
def assigned_sheet(request, assignment_id):
    """
    A new sheet prefilled with an assignment.
    """
    sheet = get_sheet(assignment_id)
    if "error" in sheet:
        return HttpResponse(sheet["error"])

    sheet["sources"] = annotate_user_links(sheet["sources"])

    # Remove keys from we don't want transferred
    for key in ("id", "like", "views"):
        if key in sheet:
            del sheet[key]

    assigner = UserProfile(id=sheet["owner"])
    assigner_id = assigner.id
    owner_groups = get_user_groups(request.user.id)

    sheet_class = make_sheet_class_string(sheet)
    can_edit_flag = True
    can_add_flag = can_add(request.user, sheet)
    sheet_group = Group().load({
        "name": sheet["group"]
    }) if "group" in sheet and sheet["group"] != "None" else None
    embed_flag = "embed" in request.GET
    likes = sheet.get("likes", [])
    like_count = len(likes)
    viewer_is_liker = request.user.id in likes

    return render(
        request, 'sheets.html', {
            "sheetJSON": json.dumps(sheet),
            "sheet": sheet,
            "assignment_id": assignment_id,
            "assigner_id": assigner_id,
            "new_sheet": True,
            "sheet_class": sheet_class,
            "can_edit": can_edit_flag,
            "can_add": can_add_flag,
            "title": sheet["title"],
            "is_owner": True,
            "is_public": sheet["status"] == "public",
            "owner_groups": owner_groups,
            "sheet_group": sheet_group,
            "like_count": like_count,
            "viewer_is_liker": viewer_is_liker,
            "current_url": request.get_full_path,
        })