Ejemplo n.º 1
0
def app_wsgi(request, app_id=0):
    u = request.session.get('switched_user', request.user)
    superuser = request.user

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

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

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

            if site.type == "uwsgi":
                ur = UWSGIRequest(u, u.parms.web_machine)
                ur.mod_config()
                ur.restart(site)

            #Signal
            restart_master(config.mode, u)

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

            messages.add_message(request, messages.SUCCESS, _('App 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 = FormWsgi(user=u, instance=site)
        site_errors = ()


    dynamic_refreshs = (
        (reverse("refresh_wsgi"), 'id_script'),
        (reverse("refresh_venv"), 'id_virtualenv'),
    )

    return render_to_response('add_site.html',
            {
            "dynamic_refreshs": dynamic_refreshs,
            "siteErrors": site_errors,
            "form": form,
            "title": _("%s WSGI application") % _('Modify') if site else _('Add'),
            "submit": _("Save changes"),
            "action": reverse("app_wsgi", args=[app_id]),
            "u": u,
            "superuser": superuser,
            "menu_active": "webapps",
            },
        context_instance=RequestContext(request)
    )
Ejemplo n.º 2
0
def app_wsgi(request, app_id=0):
    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 = FormWsgi(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():
            site = form.save(commit=False)
            site.owner = u
            site.type = 'uwsgi'
            site.save()

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

            if site.type == "uwsgi":
                ur = UWSGIRequest(u, u.parms.web_machine)
                ur.mod_config()
                ur.restart(site)

            #Signal
            restart_master(config.mode, u)

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

            messages.add_message(request, messages.SUCCESS, _('App 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 = FormWsgi(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_wsgi", args=[app_id])

    return render_to_response('add_site.html',
            {
            "form": form,
            "title": _("%s WSGI application") % _('Modify') if site else _('Add'),
            "u": u,
            "superuser": superuser,
            "menu_active": "webapps",
            },
        context_instance=RequestContext(request)
    )
Ejemplo n.º 3
0
def app_wsgi(request, app_id=0):
    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 = FormWsgi(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():
            site = form.save(commit=False)
            site.owner = u
            site.type = 'uwsgi'
            site.save()

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

            if site.type == "uwsgi":
                ur = UWSGIRequest(u, u.parms.web_machine)
                ur.mod_config()
                ur.restart(site)

            #Signal
            restart_master(config.mode, u)

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

            messages.add_message(
                request, messages.SUCCESS,
                _('App 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 = FormWsgi(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_wsgi", args=[app_id])

    return render_to_response(
        'add_site.html', {
            "form": form,
            "title":
            _("%s WSGI application") % _('Modify') if site else _('Add'),
            "u": u,
            "superuser": superuser,
            "menu_active": "webapps",
        },
        context_instance=RequestContext(request))