Exemplo n.º 1
0
 def post(self, id=None):
     data = request.get_json(force=True, silent=False)
     if 'rewards' in data:
         reward_list = []
         for reward in data['rewards']:
             reward_list.append(Reward(**reward))
         data['rewards'] = reward_list
     if 'organization' in data:
         org = Organization.objects.get_or_404(id=data['organization'])
         data['organization'] = org
     if 'name' not in data:
         return helpers.api_error('Please enter an appropriate name for your project!', 400), 400
     user = User.objects.get_or_404(id=data['creator'])
     for key, value in data.iteritems():
         if key in ['start_date', 'end_date', 'fulfilled_date', 'published']:
             data[key] = datetime.strptime(value['date'], "%Y-%m-%d %H:%M:%S")
         else:
             data[key] = value
     data['creator'] = user
     proj = Project(**data)
     proj.updated = datetime.utcnow()
     try:
         proj.save()
     except ValidationError as e:
         return helpers.api_error(e.message, 400), 400
     except NotUniqueError as e:
         return helpers.api_error(e.message, 409), 409
     except Exception:
         return helpers.api_error("Something went wrong! Check your request parameters!", 500), 500
     ml = MarketingList(project=proj.id, contacts=[], pledge_conversion=0, convert_conversion=0, total_donated=0)
     ml.save()
     return helpers.api_return("OK", proj.updated, proj.id, 'Project')
Exemplo n.º 2
0
 def delete(self, id):
     if id is None:
         return helpers.api_error("No Transaction ID Provided!", 404), 404
     else:
         t = Transaction.objects.get_or_404(id=id)
         Project.objects(id=t.project.id).update_one(
             dec__total_raised=t.total_amt,
             dec__total_giga_fee=t.giga_fee,
             dec__total_trans_fee=t.trans_fee,
             dec__total_net_raised=t.net_amt,
             pull__donor_list=t.email,
         )
         t.delete()
         return helpers.api_return("DELETED", datetime.utcnow(), id, "Transaction")
Exemplo n.º 3
0
 def put(self, id):
     data = request.get_json(force=True, silent=False)
     transaction = Transaction.objects.get_or_404(id=id)
     if "total_amt" in data:
         org = transaction.organization
         diff = data["total_amt"] - transaction.total_amt
         if org is not None:
             diff_giga = (
                 (data["total_amt"] * (org.giga_fee_percent / 10000.0)) + org.giga_fee_cents
             ) - transaction.giga_fee
             diff_trans = (
                 (data["total_amt"] * (org.trans_fee_percent / 10000.0)) + org.trans_fee_cents
             ) - transaction.trans_fee
             net_amt = (data["total_amt"] - (diff_giga + diff_trans)) - transaction.net_amt
         else:
             diff_giga = (data["total_amt"] * 0.05) - transaction.giga_fee
             diff_trans = ((data["total_amt"] * 0.029) + 30) - transaction.trans_fee
             net_amt = (data["total_amt"] - (diff_giga + diff_trans)) - transaction.net_amt
         Project.objects(id=transaction.project.id).update_one(
             inc__total_raised=diff,
             inc__total_giga_fee=diff_giga,
             inc__total_trans_fee=diff_trans,
             inc__total_net_raised=net_amt,
         )
     if "comment" in data:
         transaction.comment = data["comment"]
     if "referring_user" in data:
         ref = User.objects.get_or_404(id=data["referring_user"])
         transaction.referring_user = ref
     if "organization" in data:
         org = Organization.objects.get_or_404(id=data["organization"])
         transaction.organization = org
     if "user" in data:
         user = User.objects.get_or_404(id=data["user"])
         transaction.user = user
     transaction = helpers.generic_update(transaction, data)
     return helpers.api_return("OK", transaction.updated, transaction.id, "Transaction")
Exemplo n.º 4
0
 def get(self, id, cid=None, org_perma=None, proj_perma=None):
     if id is None:
         if cid is not None:
             # this is temporary - return list of projects for this cid?
             return helpers.api_error('No Project ID Provided!', 404), 404
         elif (org_perma is not None) and (proj_perma is not None):
             org = Organization.objects.get_or_404(perma_name=org_perma)
             return Project.objects.get_or_404(organization=org, perma_name=proj_perma).select_related(1).to_json()
         elif 'user' in request.args:
             u = User.objects.get_or_404(id=request.args['user'])
             projects = Project.objects(creator=u)
             return jsonify(result=projects.to_json())
         else:
             return helpers.api_error('No Project ID Provided!', 404), 404
     else:
         return Project.objects.get_or_404(id=id).select_related(1).to_json()