Exemple #1
0
def software_add_license(request,object_id):
    object = get_object_or_404(models.software, pk=object_id)
    web = webs.software_web()
    breadcrumbs = web.get_view_breadcrumbs(object)
    breadcrumbs.append(webs.breadcrumb(web.get_add_license_url(object),"add software license"))

    l_web = webs.license_web()
    error = l_web.check_add_perms(request, breadcrumbs)
    if error is not None:
        return error

    if request.method == 'POST':
        form = forms.license_add_form(request.POST, request.FILES)

        if form.is_valid():
            valid = True
            # we try to get license_key first, in case something goes wrong.
            # if something goes wrong, no license will be created.
            key = form.cleaned_data['key'].strip()
            lk_web = webs.license_key_web()
            try:
                # try to find existing license for key
                if lk_web.has_edit_perms(request.user):
                    license_key = models.license_key.objects.get(key=key,software=object)
                else:
                    msg = u"License key exists and no permission to modify"
                    form._errors["key"] = util.ErrorList([msg])
                    valid = False
            except models.license_key.DoesNotExist, e:
                # no license found, we have to create one
                if lk_web.has_add_perms(request.user):
                    license_key = models.license_key()
                    license_key.software = object
                    license_key.key = key
                else:
                    msg = u"License key doesn't exist and no permission to add one"
                    form._errors["key"] = util.ErrorList([msg])
                    valid = False

            # Can we continue?
            if valid:
                # we need to create the license license
                license = models.license()
                license.vendor_tag = form.cleaned_data['vendor_tag']
                license.installations_max = form.cleaned_data['installations_max']
                license.version = form.cleaned_data['version']
                license.expires = form.cleaned_data['expires']
                license.owner = form.cleaned_data['owner']
                license.save()

                # Update license_key with license we just got
                license_key.license = license
                license_key.save()

                # we finished
                url = l_web.get_view_url(license)
                url = request.GET.get("next",url)
                return HttpResponseRedirect(url)
Exemple #2
0
                license.installations_max = form.cleaned_data['installations_max']
                license.version = form.cleaned_data['version']
                license.expires = form.cleaned_data['expires']
                license.owner = form.cleaned_data['owner']
                license.save()

                # Update license_key with license we just got
                license_key.license = license
                license_key.save()

                # we finished
                url = l_web.get_view_url(license)
                url = request.GET.get("next",url)
                return HttpResponseRedirect(url)
    else:
        form = forms.license_add_form()

    return render_to_response('django_webs/object_edit.html', {
            'object': None, 'type': 'software license',
            'breadcrumbs': breadcrumbs,
            'form' : form,
            'media' : form.media,
            },context_instance=RequestContext(request))

def license_delete(request,object_id):
    web = webs.license_web()
    object = get_object_or_404(models.license, pk=object_id)
    return web.object_delete(request, object)

###############
# LICENSE KEY #