Exemplo n.º 1
0
def app_static(request, app_type="static", app_id=0):
    if app_type not in ("static", "php"):
        return HttpResponseForbidden(ugettext("Invalid type of application"))

    u = request.session.get('switched_user', request.user)
    superuser = request.user

    try:
        site = u.usersite_set.get(id=app_id)
    except UserSite.DoesNotExist:
        site = None

    domains = domains_list(u, used=used_domains(u, site))
    if request.method == 'POST':
        form = FormStatic(request.POST, user=u, instance=site)
        form.fields["main_domain"].choices = [(x.id, x.domain_name) for x in domains]
        form.fields["misc_domains"].choices = [(x.id, x.domain_name) for x in domains]

        if form.is_valid():
            isite = form.save(commit=False)
            isite.type = app_type
            isite.owner = u
            isite.save()

            for sd in SiteDomain.objects.filter(user_site=isite):
                sd.delete()
            for domain in form.cleaned_data['misc_domains']:
                SiteDomain.objects.create(domain=domain, user_site=isite)

            # Requests
            restart_master(config.mode, u)

            # calculate!
            u.parms.pay_for_sites(use_cache=False)

            messages.add_message(request, messages.SUCCESS, _('Site has been %s') % (_('changed') if site else _('added')))
            messages.add_message(request, messages.INFO, _('Changes will be performed in few minutes'))
            return HttpResponseRedirect(reverse("app_list"))
    else:
        form = FormStatic(user=u, instance=site)
        form.fields["main_domain"].choices = [(x.id, x.domain_name) for x in domains]
        form.fields["misc_domains"].choices = [(x.id, x.domain_name) for x in domains]

    form.helper.form_action = reverse("app_static", kwargs={'app_type': app_type, 'app_id': app_id})

    return render_to_response('add_site.html',
            {
            "form": form,
            "title": {'static': _("Static website"), 'php': _("PHP website")}[app_type],
            "u": u,
            "superuser": superuser,
            "menu_active": "webapps",
            },
        context_instance=RequestContext(request)
    )
Exemplo n.º 2
0
def app_static(request, app_type="static", app_id=0):
    if app_type not in ("static", "php"):
        return HttpResponseForbidden(ugettext("Invalid type of application"))

    u = request.session.get('switched_user', request.user)
    superuser = request.user
    choices = [(d, d) for d in user_directories(u, use_cache=True)]

    try:
        site = UserSite.objects.get(id=app_id, owner=u)
    except UserSite.DoesNotExist:
        site = None

    if request.method == 'POST':
        form = FormStatic(request.POST, user=u, instance=site)

        site_errors = domain_check(request, form, this_site=site)
        if not site_errors and form.is_valid():
            isite = form.save(commit=False)
            isite.type = app_type
            isite.owner = u
            isite.save()

            # Requests
            restart_master(config.mode, u)

            # calculate!
            u.parms.pay_for_sites(use_cache=False)

            messages.add_message(request, messages.SUCCESS, _('Site has been %s') % (_('changed') if site else _('added')))
            messages.add_message(request, messages.INFO, _('Changes will be performed in few minutes'))
            return HttpResponseRedirect(reverse("app_list"))
    else:
        form = FormStatic(user=u, instance=site)
        site_errors = ()

    dynamic_refreshs = (
        (reverse("refresh_userdirs"), 'id_document_root'),
    )

    return render_to_response('add_site.html',
            {
            "dynamic_refreshs": dynamic_refreshs,
            "siteErrors": site_errors,
            "form": form,
            "title": {'static': _("Static website"), 'php': _("PHP website")}[app_type],
            "submit": _("Add website") if not site else _("Modify website"),
            "action": reverse("app_static", kwargs={'app_type': app_type, 'app_id': app_id}),
            "u": u,
            "superuser": superuser,
            "menu_active": "webapps",
            },
        context_instance=RequestContext(request)
    )
Exemplo n.º 3
0
def app_static(request, app_type="static", app_id=0):
    if app_type not in ("static", "php"):
        return HttpResponseForbidden(ugettext("Invalid type of application"))

    u = request.session.get('switched_user', request.user)
    superuser = request.user

    try:
        site = u.usersite_set.get(id=app_id)
    except UserSite.DoesNotExist:
        site = None

    domains = domains_list(u, used=used_domains(u, site))
    if request.method == 'POST':
        form = FormStatic(request.POST, user=u, instance=site)
        form.fields["main_domain"].choices = [(x.id, x.domain_name)
                                              for x in domains]
        form.fields["misc_domains"].choices = [(x.id, x.domain_name)
                                               for x in domains]

        if form.is_valid():
            isite = form.save(commit=False)
            isite.type = app_type
            isite.owner = u
            isite.save()

            for sd in SiteDomain.objects.filter(user_site=isite):
                sd.delete()
            for domain in form.cleaned_data['misc_domains']:
                SiteDomain.objects.create(domain=domain, user_site=isite)

            # Requests
            restart_master(config.mode, u)

            # calculate!
            u.parms.pay_for_sites(use_cache=False)

            messages.add_message(
                request, messages.SUCCESS,
                _('Site has been %s') % (_('changed') if site else _('added')))
            messages.add_message(request, messages.INFO,
                                 _('Changes will be performed in few minutes'))
            return HttpResponseRedirect(reverse("app_list"))
    else:
        form = FormStatic(user=u, instance=site)
        form.fields["main_domain"].choices = [(x.id, x.domain_name)
                                              for x in domains]
        form.fields["misc_domains"].choices = [(x.id, x.domain_name)
                                               for x in domains]

    form.helper.form_action = reverse("app_static",
                                      kwargs={
                                          'app_type': app_type,
                                          'app_id': app_id
                                      })

    return render_to_response('add_site.html', {
        "form": form,
        "title": {
            'static': _("Static website"),
            'php': _("PHP website")
        }[app_type],
        "u": u,
        "superuser": superuser,
        "menu_active": "webapps",
    },
                              context_instance=RequestContext(request))