コード例 #1
0
def issue(request):
    if request.method != "POST":
        raise Http404()

    fields = License.objects.get_cc_issue_fields()
    answers = {}
    for field in fields:
        answers[field["id"]] = request.POST.get("cc-question-%s" % field["id"], u"")

    response = {"status": "error"}
    result = License.objects.issue(answers)
    if result:
        response["status"] = "success"
        response.update(result)
        license_type = CC_LICENSE_URL_RE.search(result["url"]).groupdict()["cc_type"]
        response["license_classes"] = license_type.split("-")
    else:
        response["status"] = "error"
        response["message"] = u"Unable to get license information from CreativeCommons.org. Try again later."

    return response
コード例 #2
0
ファイル: forms.py プロジェクト: colinbdclark/OER-Commons
    def render(self, name, value, attrs=None):
        license_url = value.get("url", u"")
        license_name = value.get("name", u"")
        derivatives = u""
        commercial = u""

        r = CC_LICENSE_URL_RE.search(license_url)
        if r:
            cc_type = r.groupdict()["cc_type"]
            if "nd" in cc_type:
                derivatives = "n"
            elif "sa" in cc_type:
                derivatives = "sa"
            else:
                derivatives = "y"
            commercial = "n" if "nc" in cc_type else "y"
        else:
            cc_type = ""
            license_url = u""
            license_name = u""

        return mark_safe(render_to_string(
            "authoring/forms/license-widget.html",
            dict(
                name=name,
                cc_type=cc_type,
                name_widget=forms.HiddenInput().render("%s_name" % name, license_name),
                url_widget=forms.HiddenInput().render("%s_url" % name, license_url),
                derivatives_widget=forms.RadioSelect(attrs={"disabled": "disabled"} if self.readonly else None).render(
                    "%s_derivatives" % name,
                    derivatives,
                    choices=self.DERIVATIVES_CHOICES,
                ),
                commercial_widget=forms.RadioSelect(attrs={"disabled": "disabled"} if self.readonly else None).render(
                    "%s_commercial" % name,
                    commercial,
                    choices=self.COMMERCIAL_CHOICES,
                )
            )
        ))