Beispiel #1
0
def metadata(request):
    """
    This view serves the metadata window.
    """
    w = int(request.GET["id"])
    ent = get_by_ismi_id(w)
    title = get_name(ent)

    def adder(clss, l):
        for a in clss.objects.all():
            if a.show != clss.NEVER_SHOW:
                k, vals = get_keyvals(a, w)
                if a.show == clss.ALWAYS_SHOW:
                    for val in vals:
                        l.append((k, val))
                else:  # show if set
                    if len(vals) == 1:
                        val, = vals
                        if val == NO_DATA_MSG:
                            continue
                    for val in vals:
                        l.append((k, val))

    md = []
    adder(AttDisplaySetting, md)
    adder(RelDisplaySetting, md)

    data = {"title": title, "md": md}
    return render(request, "templates/metadata.html", data)
Beispiel #2
0
 def format_output(self, rendered_widgets):
     labels = [get_by_ismi_id(w).get("ov") for w in self.witnesses]
     header = u"""<tr>
         <th>Witness</th>
         <th>First Page</th>
         <th>Last Page</th>
     </tr>"""
     zipped = zip(labels, rendered_widgets)
     prerenders = [u"<tr><td>" + l + u"</td>" + w + u"</tr>" for l, w in zipped]
     rows = u"\n".join(prerenders)
     return u"<table>" + header + rows + u"</table>"
Beispiel #3
0
def manuscript(request, ms_id):
    """The view for displaying a specific manuscript."""
    if request.user.is_anonymous():
        u = User.objects.get(pk=-1)  # select the "AnonymousUser" object
    else:
        u = request.user

    # We break the response down into a couple steps here.
    # First, check the number of manuscripts groups they have permissions to. This is just to
    # be able to exit with a 404 if they're trying to access a manuscript in a group that doesn't exist.

    # Then, we check against the manuscripts themselves. This allows us to catch the user and redirect them
    # to a log in page if they need to log in to see the MSS.
    manuscript_groups = get_objects_for_user(u, "imageserve.view_manuscript_group")
    manuscripts = Manuscript.objects.filter(manuscriptgroup__in=manuscript_groups).distinct()
    if not manuscripts.exists():
        raise Http404

    has_permission = manuscripts.filter(id=ms_id)

    if manuscripts and not has_permission.exists():
        return redirect("/login/?next={0}".format(request.path))

    m = has_permission[0]
    curr_wit = request.GET.get("curr_wit")
    try:
        curr_wit = int(curr_wit)
    except (ValueError, TypeError):
        curr_wit = -1

    # witnesses = None
    titles = None
    ismi_data = False
    wits = PageNotAnInteger

    if m.ismi_id is not None:
        codex_title = get_name(get_by_ismi_id(m.ismi_id))
        ismi_data = True
        wits = m.witnesses
        if wits:
            if not curr_wit in wits:
                curr_wit = -1
            titles = [(w, get_rel(w, "is_exemplar_of")[0], get_att(w, "folios")) for w in wits]
    else:
        codex_title = m.directory

    data = {
        "ms_title": codex_title,
        "witnesses": bool(wits),
        "divaserve_url": DIVASERVE_URL,
        "iipserver_url": IIPSERVER_URL,
        "image_root": conf.IMG_DIR,
        "curr_wit": curr_wit,
        "ms_name": m.directory,
        "titles": titles,
        "ismi_data": ismi_data,
        "ms_id": ms_id,
        "ismi_id": m.ismi_id,
        "path": quote_plus(request.get_full_path()),
        "num_files": m.num_files,
    }
    return render(request, "templates/diva.html", data)