Beispiel #1
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)
    )
Beispiel #2
0
def remove_app_preparation(app, remove_domains=True):
    if app.pay:
        pay(app.owner, app.type, "Last payment for this site - %s" % app.main_domain.domain_name, app.pay)

    #Signal
    restart_master(config.mode, app.owner)

    if app.type == "uwsgi":
        ur = UWSGIRequest(app.owner,  app.owner.parms.web_machine)
        ur.stop(app, instant=True)
        ur.mod_config()

    if remove_domains:
        for sitedomain in app.sitedomain_set.all():
            sitedomain.delete()
Beispiel #3
0
def remove_site(request):
    u = request.session.get('switched_user', request.user)

    try:
        object_id = request.POST['object_id']
        s = get_object_or_404(UserSite, id=object_id)
        if s.owner != u:
            raise Exception("Forbidden operation")

        s.removed = True
        s.end_date = date.today()
        s.save()

        #Signal
        restart_master(config.mode, u)

        ur = UWSGIRequest(u, u.parms.web_machine)
        ur.stop(s)
        ur.mod_config()

        # calculate!
        u.parms.pay_for_sites(use_cache=False)
        return JsonResponse("OK", {1: ugettext("Site was successfuly removed")})
    except Exception, e:
        return JsonResponse("KO", {1: ugettext("Error deleting site")})
Beispiel #4
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)
    )
Beispiel #5
0
def restart(request, sid):
    u = request.session.get('switched_user', request.user)

    sid = int(sid)
    s = get_object_or_404(UserSite, id=sid)

    #Signal
    if s.type in ("uwsgi", "modwsgi"):
        ur = UWSGIRequest(u, u.parms.web_machine)
        ur.mod_config()
        ur.restart(s)
    else:
        restart_master(config.mode, u)

    messages.add_message(request, messages.SUCCESS, _('Request for restarting has been sent'))
    messages.add_message(request, messages.INFO, _('It will be performed in few minutes'))
    return HttpResponseRedirect(reverse("app_list"))
Beispiel #6
0
def remove_app_preparation(app, remove_domains=True):
    if app.pay:
        pay(app.owner, app.type,
            "Last payment for this site - %s" % app.main_domain.domain_name,
            app.pay)

    #Signal
    restart_master(config.mode, app.owner)

    if app.type == "uwsgi":
        ur = UWSGIRequest(app.owner, app.owner.parms.web_machine)
        ur.stop(app, instant=True)
        ur.mod_config()

    if remove_domains:
        for sitedomain in app.sitedomain_set.all():
            sitedomain.delete()
Beispiel #7
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))