Exemplo n.º 1
0
def fromParams(req):
    s = SubCategory.objects.get(pk=req['subCategory.id'])
    p = PaymentType(pk=req['paymentType.id'])
    if param_exist("text",req):
        text = req['text']
    else:
        text = s.name 

    if param_exist("id",req):
        e = Expense.objects.get(pk=req['id'])
    else:
        e = Expense()
        
    e.text=text
    e.date=DateService.invert(req['date']) 
    e.amount=req['amount']
    e.subCategory=s
    e.paymentType=p
    return e
Exemplo n.º 2
0
    except (PaymentType.DoesNotExist, KeyError):
        raise ValidationError(_('Select a valid payment type.'))
        
    if param_exist("text",req):
        text = req['text']
    else:
        text = s.name 

    if param_exist("id",req):
        e = Expense.objects.get(pk=req['id'])
    else:
        e = Expense()
        
    e.text=text
    e.date=DateService.parseDate(req['date']) 
    e.amount=amount
    e.subCategory=s
    e.paymentType=p
    return e

@json_response
def save_or_update(request):
    req = request.REQUEST
    try:
        e = fromParams(req)
    except ValidationError, e:
        data = '{"success":false, "msg": "%s"}' % ("".join(e.messages))
        return data
        
    values = {'text':e.text,'date':req['date'], 'amount': float(e.amount)}
    if e.id:
Exemplo n.º 3
0
from django.conf import settings

class SyncServiceClass(object):

    def __init__(self):
        self.server = xmlrpclib.ServerProxy(settings.RPC_HOST).app
            
    def sync_expenses(self):
        try:
            data = self.server.getData()
        except Exception, e:
            raise
        else:
            if data:
                for e in data:
                    expense = Expense()
                    s = SubCategory.objects.get(pk=e['subCategory'])
                    p = PaymentType.objects.get(pk=e['paymentType'])
                    if e['text']:
                        expense.text = e['text']
                    else:
                        expense.text = s.name
                    expense.subCategory=s
                    expense.paymentType=p
                    expense.date=e['date']
                    expense.amount=e['amount']
                    expense.save()
                return len(data)
            else:
                return 0