Beispiel #1
0
def add_resource_permissions(*args, **kwargs):
  """
  This syncdb hooks takes care of adding a view permission too all our 
  content types.
  """
  # for each of our content types
  for resource in find_api_classes('v1_api', ModelResource):
    auth = resource._meta.authorization
    content_type = ContentType.objects.get_for_model(resource._meta.queryset.model)
    if isinstance(auth, SpiffAuthorization):
      conditions = auth.conditions()
      operations = auth.operations()
      if len(conditions) == 0:
        conditions = (None,)

      for condition in conditions:
        for operation in operations:
          # build our permission slug
          if condition:
            codename = "%s_%s_%s" % (operation[0], condition[0], content_type.model)
            name = "Can %s %s, when %s" % (operation[1], content_type.name,
                condition[1])
          else:
            codename = "%s_%s" % (operation[1], content_type.model)
            name = "Can %s %s" % (operation[1], content_type.name)

          # if it doesn't exist..
          if not Permission.objects.filter(content_type=content_type, codename=codename):
            # add it
            Permission.objects.create(content_type=content_type,
                                      codename=codename,
                                      name=name[:49])
            funcLog().debug("Created permission %s.%s (%s)", content_type.app_label, codename, name)
Beispiel #2
0
def processSubscriptions():
  with transaction.atomic():
    startOfMonth, endOfMonth = monthRange()
    lineItems = {}
    for planCls in find_api_classes('models', SubscriptionPlan):
      plans = planCls.objects.all()
      for plan in plans:
        for subscription in plan.subscriptions.filter(active=True):
          if subscription.identity not in lineItems:
            lineItems[subscription.identity] = {'subscriptions': [], 'lineItems': []}

          items = plan.process(subscription)
          funcLog().info("Processed subscription %s", subscription)

          if len(items) > 0 and subscription not in lineItems[subscription.identity]['subscriptions']:
            lineItems[subscription.identity]['subscriptions'].append(subscription)
            lineItems[subscription.identity]['lineItems'] += items
    invoices = []
    for identity, data in lineItems.iteritems():
      invoice = Invoice.bundleLineItems(identity, endOfMonth, data['lineItems'])
      if invoice:
        funcLog().info("Created invoice %s", invoice)
        invoices.append(invoice)
      for subscription in data['subscriptions']:
        subscription.save()
    for invoice in invoices:
      invoice.draft = False
      invoice.save()
Beispiel #3
0
 def periodCost(self):
   from spiff.api.plugins import find_api_classes
   for planCls in find_api_classes('models', SubscriptionPlan):
     try:
       plan = planCls.objects.get(pk=self.pk)
     except planCls.DoesNotExist:
       pass
   return plan.calculatePeriodCost()
Beispiel #4
0
 def save(self, *args, **kwargs):
     if not self.id and not self.created:
         self.created = datetime.datetime.utcnow().replace(tzinfo=utc)
         if notification:
           notification.send(
             [self.user],
             "payment_received",
             {'user': self.user, 'payment': self})
     super(Payment, self).save(*args, **kwargs)
     if self.invoice.unpaidBalance == 0:
         self.invoice.open = False
         self.invoice.save()
         for lineItemType in find_api_classes('models', LineItem):
           for item in lineItemType.objects.filter(invoice=self.invoice):
             item.process()
Beispiel #5
0
from tastypie.api import Api
from spiff.api.plugins import find_api_classes
from tastypie.resources import Resource

v1_api = Api(api_name='v1')
for api in find_api_classes('v1_api', Resource, lambda x:hasattr(x, 'Meta')):
  v1_api.register(api())