示例#1
0
def versions(request):
    """
    Show all Versions for an Image according to ADMIN_VERSIONS.
    """

    # QUERY / PATH CHECK
    query = request.GET
    path = get_path(query.get("dir", ""))
    filename = get_file(query.get("dir", ""), query.get("filename", ""))
    if path is None or filename is None:
        if path is None:
            msg = _("The requested Folder does not exist.")
        else:
            msg = _("The requested File does not exist.")
        request.user.message_set.create(message=msg)
        return HttpResponseRedirect(reverse("fb_browse"))
    # abs_path = u'%s' % os.path.join(MEDIA_ROOT, DIRECTORY, path)
    path = os.path.join(DIRECTORY, path, filename)
    settings_var = get_settings_var()

    if request.POST:
        formset = ImageCropDataFormSet(request.POST, queryset=ImageCropData.objects.filter(path=path))
        if formset.is_valid():
            formset.save()
            for version in settings_var.get("ADMIN_VERSIONS", {}):  # TODO: or at least, only do if needed
                version_generator(path, version)
        else:
            raise Exception("Somehow formset became invalid: %s" % formset.errors)
        return HttpResponseRedirect("")

    # We have to create all the versions first, so the crop data form has something to fill with #TODO: this could work better somehow
    for version in VERSIONS:
        version_for_image(path, version)

    formset = ImageCropDataFormSet(queryset=ImageCropData.objects.filter(path=path))

    return render_to_response(
        "filebrowser/versions.html",
        {
            "original": path_to_url(path),
            "query": query,
            "title": _(u'Versions for "%s"') % filename,
            "settings_var": settings_var,
            "breadcrumbs": get_breadcrumbs(query, path),
            "breadcrumbs_title": _(u'Versions for "%s"') % filename,
            "formset": formset,
        },
        context_instance=Context(request),
    )
示例#2
0
 def render(self, context):
     try:
         source = self.src.resolve(context)
     except VariableDoesNotExist:
         return None
     if self.version_prefix:
         version_prefix = self.version_prefix
     else:
         try:
             version_prefix = self.version_prefix_var.resolve(context)
         except VariableDoesNotExist:
             return None
     return version_for_image(source, version_prefix)