Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 4 commits
  • 14 files changed
  • 0 commit comments
  • 1 contributor
View
7 README.rst
@@ -50,7 +50,12 @@ Developers
* Adam Štrauch - cx@initd.cz (e-mail/jabber)
* Jiří Suchan - @yedpodtrzitko
-* Pavel Buben
+
+Sponzoring
+==========
+
+* Roští.cz (Python/PHP hosting) - http://rosti.cz/
+* Virtualmaster, s.r.o. (VPS) - http://www.virtualmaster.cz/
You are welcome to join us, just click on the fork button up there.
View
4 wsgiadmin/clients/forms.py
@@ -6,10 +6,10 @@
class ParmsForm(ModelForm):
class Meta:
model = Parms
- exclude = ("address", "user", "home", "uid", "gid")
+ fields = ("home", "note", "discount", "fee", "enable")
class UserForm(ModelForm):
class Meta:
model = User
- exclude = ("password", "is_staff", "is_superuser", "last_login", "date_joined", "groups", "user_permissions")
+ fields = ("username", )
View
28 wsgiadmin/clients/models.py
@@ -8,6 +8,7 @@
from django.db.models import Sum
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
+from jsonrpc.proxy import ServiceProxy
from wsgiadmin.emails.models import Email, Message
from wsgiadmin.keystore.tools import kget
from wsgiadmin.requests.tools import RawRequest
@@ -101,10 +102,16 @@ def pay_for_sites(self, use_cache=True):
return pay
def pay_total_day(self):
- return self.pay_for_sites()
+ if self.fee:
+ return self.fee / 30
+ else:
+ return self.pay_for_sites()
def pay_total_month(self):
- return self.pay_for_sites() * 30.0
+ if self.fee:
+ return self.fee
+ else:
+ return self.pay_for_sites() * 30.0
@property
def credit(self):
@@ -124,6 +131,23 @@ def credit_until(self):
return False
def add_credit(self, value, free=False):
+ if settings.JSONRPC_URL:
+ items = [{
+ "description": config.invoice_desc,
+ "count": float(value),
+ "price": 1 / float(config.credit_currency.split(",")[0]), #TODO:change it to multicurrency
+ "tax": config.tax,
+ }]
+
+ proxy = ServiceProxy(settings.JSONRPC_URL)
+ #TODO:what to do with exception?
+ print proxy.add_invoice(
+ settings.JSONRPC_USERNAME,
+ settings.JSONRPC_PASSWORD,
+ self.address_id,
+ items
+ )
+
bonus = 1.0
if value >= 1000:
View
1  wsgiadmin/emails/models.py
@@ -9,6 +9,7 @@
("reg", _("Registration")),
("approved_reg", _("Approved registration")),
("low_credit", _("Low credit notification")),
+ ("autobuy_credit", _("Autobuy credit")),
("add_credit", _("Credit notification - admin")),
)
View
2  wsgiadmin/settings/base.py
@@ -208,6 +208,8 @@
"credit_750_bonus": (1.1, "750 credits bonus (credits * this number)"),
"credit_1000_bonus": (1.2, "500 credits bonus (credits * this number)"),
"credit_currency": ("0.5,12.5,9.5", "CZK, EUR, USD"),
+ "tax": (0, "%"),
+ "invoice_desc": ("Credit for services", "Some text"),
"terms_url": ("", "Terms URL"),
View
4 wsgiadmin/stats/admin.py
@@ -0,0 +1,4 @@
+from django.contrib import admin
+from wsgiadmin.stats.models import Credit
+
+admin.site.register(Credit)
View
49 wsgiadmin/stats/management/commands/auto_buying.py
@@ -0,0 +1,49 @@
+import datetime
+from django.core.management.base import BaseCommand
+from django.contrib.auth.models import User
+from wsgiadmin.emails.models import Message
+
+class Command(BaseCommand):
+ help = "Autobying of credit - work's fine with cron"
+
+ def handle(self, *args, **options):
+ users = User.objects.all()
+ for user in users:
+ last_notification = user.parms.last_notification if user.parms.last_notification else datetime.date(1970, 1 ,1)
+ if user.parms.credit < 15 and user.parms.pay_total_day() > 0 and (datetime.date.today() - last_notification).days > 14:
+ if user.parms.low_level_credits == "send_email":
+ if not user.email: continue
+ message = Message.objects.filter(purpose="low_credit")
+ if message:
+ message[0].send(user.email)
+ elif user.parms.low_level_credits == "buy_month":
+ total = user.parms.pay_total_day() * 30
+ user.parms.add_credit(total)
+ if not user.email: continue
+ message = Message.objects.filter(purpose="autobuy_credit")
+ if message:
+ message[0].send(user.email)
+ elif user.parms.low_level_credits == "buy_three_months":
+ total = user.parms.pay_total_day() * 90
+ user.parms.add_credit(total)
+ if not user.email: continue
+ message = Message.objects.filter(purpose="autobuy_credit")
+ if message:
+ message[0].send(user.email)
+ elif user.parms.low_level_credits == "buy_six_months":
+ total = user.parms.pay_total_day() * 180
+ user.parms.add_credit(total)
+ if not user.email: continue
+ message = Message.objects.filter(purpose="autobuy_credit")
+ if message:
+ message[0].send(user.email)
+ elif user.parms.low_level_credits == "buy_year":
+ total = user.parms.pay_total_day() * 360
+ user.parms.add_credit(total)
+ if not user.email: continue
+ message = Message.objects.filter(purpose="autobuy_credit")
+ if message:
+ message[0].send(user.email)
+
+ user.parms.last_notification = datetime.date.today()
+ user.parms.save()
View
64 wsgiadmin/stats/management/commands/credit_data.py
@@ -1,64 +0,0 @@
-from django.core.management.base import BaseCommand
-from django.contrib.auth.models import User
-import json
-
-
-class Command(BaseCommand):
- help = "Create records"
-
- def get_address(self, user):
- if user.parms.address.invoice_name:
- if len(user.parms.address.invoice_name.split(" ")) >= 2:
- first_name = user.parms.address.invoice_name.split(" ")[0]
- last_name = user.parms.address.invoice_name.split(" ")[1]
- else:
- first_name = user.parms.address.invoice_name.split(" ")[0]
- last_name = ""
- address = {
- "company": user.parms.address.company,
- "first_name": first_name,
- "last_name": last_name,
- "street": user.parms.address.invoice_street,
- "city": user.parms.address.invoice_city,
- "zip": user.parms.address.invoice_city_num,
- "phone": user.parms.address.invoice_phone,
- "email": user.parms.address.invoice_email,
- "company_number": user.parms.address.residency_ic,
- "vat_number": user.parms.address.residency_dic,
- }
- else:
- if len(user.parms.address.residency_name.split(" ")) >= 2:
- first_name = user.parms.address.residency_name.split(" ")[0]
- last_name = user.parms.address.residency_name.split(" ")[1]
- else:
- first_name = user.parms.address.residency_name.split(" ")[0]
- last_name = ""
- address = {
- "company": user.parms.address.company,
- "first_name": first_name,
- "last_name": last_name,
- "street": user.parms.address.residency_city,
- "city": user.parms.address.residency_city,
- "zip": user.parms.address.residency_city_num,
- "phone": user.parms.address.residency_phone,
- "email": user.parms.address.residency_email,
- "company_number": user.parms.address.residency_ic,
- "vat_number": user.parms.address.residency_dic,
- }
- return address
-
- def handle(self, *args, **options):
- invoices = []
- users = User.objects.all()
- for user in users:
- credits = []
- invoice = {}
- for credit in user.credit_set.filter(invoice=False):
- credits.append((credit.date.strftime("%Y-%m-%d"), credit.value - credit.bonus))
- credit.invoice = True
- credit.save()
- invoice["address"] = self.get_address(user)
- invoice["credits"] = credits
- if credits:
- invoices.append(invoice)
- print json.dumps(invoices, sort_keys=True, indent=4)
View
113 wsgiadmin/stats/management/commands/report.py
@@ -1,113 +0,0 @@
-from datetime import date
-import pickle
-import re
-from django.contrib.auth.models import User
-from django.core.management.base import BaseCommand
-import sys
-import json
-from wsgiadmin.stats.models import Record
-
-class Command(BaseCommand):
- help = "Generate report for invoice system. Optionaly, you can give MM/YYYY format, otherwise get actual month"
-
- def get_records(self, user, month=date.today().month, year=date.today().year):
- records = list(Record.objects.filter(user=user, date__month=month, date__year=year,
- service="modwsgi").order_by("value", "date")) + \
- list(Record.objects.filter(user=user, date__month=month, date__year=year,
- service="uwsgi").order_by("value", "date")) + \
- list(Record.objects.filter(user=user, date__month=month, date__year=year,
- service="php").order_by("value", "date")) + \
- list(Record.objects.filter(user=user, date__month=month, date__year=year,
- service="static").order_by("value", "date"))
- return records
-
- def get_date(self, args):
- month = date.today().month
- year = date.today().year
- if len(args) and re.match("([0-9]{1,2})/([0-9]{4})", args[0]):
- s = re.match("([0-9]{1,2})/([0-9]{4})", args[0])
- month = int(s.groups()[0])
- year = int(s.groups()[1])
- return month, year
-
- def get_address(self, user):
- if user.parms.address.invoice_name:
- if len(user.parms.address.invoice_name.split(" ")) >= 2:
- first_name = user.parms.address.invoice_name.split(" ")[0]
- last_name = user.parms.address.invoice_name.split(" ")[1]
- else:
- first_name = user.parms.address.invoice_name.split(" ")[0]
- last_name = ""
- address = {
- "company": user.parms.address.company,
- "first_name": first_name,
- "last_name": last_name,
- "street": user.parms.address.invoice_street,
- "city": user.parms.address.invoice_city,
- "zip": user.parms.address.invoice_city_num,
- "phone": user.parms.address.invoice_phone,
- "email": user.parms.address.invoice_email,
- "company_number": user.parms.address.residency_ic,
- "vat_number": user.parms.address.residency_dic,
- }
- else:
- if len(user.parms.address.residency_name.split(" ")) >= 2:
- first_name = user.parms.address.residency_name.split(" ")[0]
- last_name = user.parms.address.residency_name.split(" ")[1]
- else:
- first_name = user.parms.address.residency_name.split(" ")[0]
- last_name = ""
- address = {
- "company": user.parms.address.company,
- "first_name": first_name,
- "last_name": last_name,
- "street": user.parms.address.residency_city,
- "city": user.parms.address.residency_city,
- "zip": user.parms.address.residency_city_num,
- "phone": user.parms.address.residency_phone,
- "email": user.parms.address.residency_email,
- "company_number": user.parms.address.residency_ic,
- "vat_number": user.parms.address.residency_dic,
- }
- return address
-
- def handle(self, *args, **options):
- month, year = self.get_date(args)
-
- users = User.objects.all()
- reports = []
- for user in users:
- report = {"webs": []}
- records = self.get_records(user, month, year)
- last = None
- web_record = {}
- record = None
- for record in records:
- if not last or (last and record.value != last.value):
- if web_record:
- web_record["date_end"] = last.date
- report["webs"].append(web_record)
- web_record = {"date_start": record.date, "date_end": record.date, "service": record.service,
- "domain": record.value, "days": 0}
- proc = re.findall("\(([0-9]+) proc.\)", record.value)
- if proc:
- web_record["processes"] = proc[0]
- else:
- web_record["processes"] = "1"
- last = record
- web_record["days"] += 1
- if record and web_record:
- web_record["date_end"] = record.date
- report["webs"].append(web_record)
- report["address"] = self.get_address(user)
- report["fee"] = user.parms.fee
- report["discount"] = user.parms.discount
- report["month"] = month
- report["year"] = year
- if report["webs"]:
- reports.append(report)
-
- #TODO:pipe doesn't work, find why and put it here
- f = open("report-%d-%d.pickle" % (year, month), "w")
- pickle.dump(reports, f)
- f.close()
View
28 wsgiadmin/stats/views.py
@@ -1,5 +1,6 @@
from datetime import date, timedelta
from constance import config
+from django.conf import settings
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.db.models.aggregates import Min, Sum
@@ -7,6 +8,7 @@
from django.views.generic.base import TemplateView
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
+from jsonrpc.proxy import ServiceProxy
from wsgiadmin.stats.models import Credit, Record
from django.utils.translation import ugettext_lazy as _
@@ -35,14 +37,24 @@ def get_context_data(self, **kwargs):
context['superuser'] = self.request.user
context['menu_active'] = "dashboard"
context['config'] = config
- context["for_month"] = self.user.parms.pay_total_day() * 30.0
- context["for_three_months"] = self.user.parms.pay_total_day() * 90
- context["for_six_months"] = self.user.parms.pay_total_day() * 180
- context["for_year"] = self.user.parms.pay_total_day() * 360
- context["for_month_cost"] = (self.user.parms.pay_total_day() * 30.0) / self.user.parms.one_credit_cost
- context["for_three_months_cost"] = (self.user.parms.pay_total_day() * 90) / self.user.parms.one_credit_cost
- context["for_six_months_cost"] = (self.user.parms.pay_total_day() * 180) / self.user.parms.one_credit_cost
- context["for_year_cost"] = (self.user.parms.pay_total_day() * 360) / self.user.parms.one_credit_cost
+ if self.user.parms.fee:
+ context["for_month"] = self.user.parms.fee
+ context["for_three_months"] = self.user.parms.fee * 3
+ context["for_six_months"] = self.user.parms.fee * 6
+ context["for_year"] = self.user.parms.fee * 12
+ context["for_month_cost"] = self.user.parms.fee / self.user.parms.one_credit_cost
+ context["for_three_months_cost"] = (self.user.parms.fee * 3) / self.user.parms.one_credit_cost
+ context["for_six_months_cost"] = (self.user.parms.fee * 6) / self.user.parms.one_credit_cost
+ context["for_year_cost"] = (self.user.parms.fee * 12) / self.user.parms.one_credit_cost
+ else:
+ context["for_month"] = self.user.parms.pay_total_day() * 30.0
+ context["for_three_months"] = self.user.parms.pay_total_day() * 90
+ context["for_six_months"] = self.user.parms.pay_total_day() * 180
+ context["for_year"] = self.user.parms.pay_total_day() * 360
+ context["for_month_cost"] = (self.user.parms.pay_total_day() * 30.0) / self.user.parms.one_credit_cost
+ context["for_three_months_cost"] = (self.user.parms.pay_total_day() * 90) / self.user.parms.one_credit_cost
+ context["for_six_months_cost"] = (self.user.parms.pay_total_day() * 180) / self.user.parms.one_credit_cost
+ context["for_year_cost"] = (self.user.parms.pay_total_day() * 360) / self.user.parms.one_credit_cost
return context
class StatsView(TemplateView):
View
2  wsgiadmin/templates/bill.html
@@ -21,7 +21,7 @@
{% endfor %}
<table class="table table-striped">
<tr>
- <th colspan="3">{% trans "What you pay by months" %}</th>
+ <th colspan="3">{% trans "What you payed by months" %}</th>
</tr>
{% for month in months %}
<tr>
View
6 wsgiadmin/templates/credit.html
@@ -15,8 +15,8 @@
</tr>
{% if u.parms.fee %}
<tr>
- <td>{% trans "Webs/Applications" %}</td>
- <td>{{ u.parms.count_sites }}×</td>
+ <td>{% trans "Regular fee" %}</td>
+ <td></td>
<td>{{ u.parms.fee|floatformat:2 }}</td>
</tr>
{% else %}
@@ -25,7 +25,7 @@
<td>{{ u.parms.count_sites }}×</td>
<td>{{ u.parms.pay_for_sites|floatformat:2 }}</td>
</tr>
- {% endif %}
+ {% endif %}
{% if not u.parms.fee %}
<tr>
View
3  wsgiadmin/useradmin/forms.py
@@ -9,7 +9,8 @@
class formReg(forms.Form):
company = forms.CharField(label=_("Company"), max_length=250, required=False)
- name = forms.CharField(label=_("Name"), max_length=250)
+ first_name = forms.CharField(label=_("First name"), max_length=250)
+ last_name = forms.CharField(label=_("Last name"), max_length=250)
street = forms.CharField(label=_("Street"), max_length=250)
city = forms.CharField(label=_("City"), max_length=250)
city_num = forms.CharField(label=_("ZIP"), max_length=6)
View
22 wsgiadmin/useradmin/views.py
@@ -16,6 +16,7 @@
from django.template.context import RequestContext
from django.core.mail import send_mail
from django.views.generic.edit import FormView
+from jsonrpc.proxy import ServiceProxy
from wsgiadmin.apacheconf.models import UserSite
from wsgiadmin.clients.models import *
@@ -190,6 +191,24 @@ def reg(request):
m_mail = get_object_or_404(Machine, name=config.default_mail_machine)
m_mysql = get_object_or_404(Machine, name=config.default_mysql_machine)
m_pgsql = get_object_or_404(Machine, name=config.default_pgsql_machine)
+
+ address_id = 0
+ if settings.JSONRPC_URL:
+ proxy = ServiceProxy(settings.JSONRPC_URL)
+ address_id = proxy.add_address(
+ settings.JSONRPC_USERNAME, settings.JSONRPC_PASSWORD,
+ form1.cleaned_data["company"],
+ form1.cleaned_data["first_name"],
+ form1.cleaned_data["last_name"],
+ form1.cleaned_data["street"],
+ form1.cleaned_data["city"],
+ form1.cleaned_data["city_num"],
+ form1.cleaned_data["phone"],
+ form1.cleaned_data["email"],
+ form1.cleaned_data["ic"],
+ form1.cleaned_data["dic"]
+ )
+
# parms
p = Parms()
p.home = join("/home", form2.cleaned_data["username"])
@@ -202,6 +221,7 @@ def reg(request):
p.mysql_machine = m_mysql
p.pgsql_machine = m_pgsql
p.user = u
+ p.address_id = int(address_id)
p.save()
if form3.cleaned_data["pay_method"] == "fee":
@@ -231,7 +251,7 @@ def reg(request):
form_helper.form_tag = False
return render_to_response('reg.html',
- {
+ {
"form1": form1,
"form2": form2,
"form3": form3,

No commit comments for this range

Something went wrong with that request. Please try again.