예제 #1
0
def delete(request):
    e = Expense(pk=request.REQUEST['id'])
    try:
        e.delete()
        data = '{"success":true}'
    except Exception, e1:
        data = '{"success":false, "msg": "%s"}' % (e1.args)   
예제 #2
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
예제 #3
0
    except SubCategory.DoesNotExist:
        raise ValidationError(_('Select a valid category.'))
    try:
        p = PaymentType.objects.get(pk=req['paymentType.id'])
    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))
예제 #4
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