コード例 #1
0
ファイル: ledger.py プロジェクト: marmida/djaodjin-saas
def parse_line(line, account_first=False, create_organizations=False):
    """
    Parse an (organization, account, amount) triplet.
    """
    if account_first:
        look = re.match(r'\s+(?P<account>(\w+:)+)(?P<organization>\w+)'\
r'(\s+(?P<amount>.+))?', line)
    else:
        look = re.match(r'\s+(?P<organization>\w+)(?P<account>(:(\w+))+)'\
r'(\s+(?P<amount>.+))?', line)
    if look:
        organization_slug = look.group('organization')
        account = look.group('account')
        if account.startswith(':'):
            account = account[1:]
        if account.endswith(':'):
            account = account[:-1]
        amount = look.group('amount')
        if amount and amount.startswith('$'):
            locale.setlocale(locale.LC_ALL, 'en_US')
            amount = long(locale.atof(amount[1:]) * 100)
        try:
            if create_organizations:
                organization, _ = Organization.objects.get_or_create(
                    slug=organization_slug)
            else:
                organization = Organization.objects.get(slug=organization_slug)
            if account_first:
                organization = get_current_provider()
            return (organization, account, amount)
        except Organization.DoesNotExist:
            print "Cannot find Organization '%s'" % organization_slug
    return (None, None, None)
コード例 #2
0
def _read_agreement_file(slug, context=None):
    import markdown
    if not context:
        context = {
            'organization': get_current_provider()}
    source, _ = loader.find_template('saas/agreements/legal_%s.md' % slug)
    return markdown.markdown(source.render(Context(context)))
コード例 #3
0
ファイル: billing.py プロジェクト: altuzar/djaodjin-saas
 def get_initial(self):
     """
     Populates place order forms with the organization address
     whenever possible.
     """
     self.customer = self.get_organization()
     kwargs = super(CardFormMixin, self).get_initial()
     provider = get_current_provider()
     if self.customer.country:
         country = self.customer.country
     else:
         country = provider.country
     if self.customer.region:
         region = self.customer.region
     else:
         region = provider.region
     kwargs.update({
         'card_name': self.customer.full_name,
         'card_city': self.customer.locality,
         'card_address_line1': self.customer.street_address,
         'country': country,
         'region': region,
         'card_address_zip': self.customer.postal_code
     })
     return kwargs
コード例 #4
0
 def get_organization(self):
     if self.organization_url_kwarg in self.kwargs:
         queryset = Organization.objects.filter(
             slug=self.kwargs.get(self.organization_url_kwarg))
         if queryset.exists():
             return queryset.get()
     return get_current_provider()
コード例 #5
0
ファイル: mixins.py プロジェクト: marmida/djaodjin-saas
 def get_organization(self):
     if self.organization_url_kwarg in self.kwargs:
         queryset = Organization.objects.filter(
             slug=self.kwargs.get(self.organization_url_kwarg))
         if queryset.exists():
             return queryset.get()
     return get_current_provider()
コード例 #6
0
ファイル: saas_tags.py プロジェクト: Qbitus/djaodjin-saas
def is_current_provider(organization):
    # We do a string compare here because both ``Organization`` might come
    # from a different db. That is if the organization parameter is not
    # a unicode string itself.
    if isinstance(organization, basestring):
        slug = organization
    else:
        slug = organization.slug
    return slug == get_current_provider().slug
コード例 #7
0
def is_current_provider(organization):
    # We do a string compare here because both ``Organization`` might come
    # from a different db. That is if the organization parameter is not
    # a unicode string itself.
    slug = ''
    if isinstance(organization, basestring):
        slug = organization
    elif organization:
        slug = organization.slug
    return slug == get_current_provider().slug
コード例 #8
0
ファイル: transactions.py プロジェクト: altuzar/djaodjin-saas
 def to_representation(self, obj):
     ret = super(TransactionSerializer, self).to_representation(obj)
     is_debit = self._is_debit(obj)
     if is_debit:
         amount = as_money(obj.orig_amount, '-%s' % obj.orig_unit)
     else:
         amount = as_money(obj.dest_amount, obj.dest_unit)
     ret.update({
         'description': as_html_description(
             obj, provider=get_current_provider()),
         'is_debit': is_debit,
         'amount': amount})
     return ret
コード例 #9
0
ファイル: decorators.py プロジェクト: wshcdr/djaodjin-saas
 def _wrapped_view(request, *args, **kwargs):
     organization = None
     if kwargs.has_key('charge'):
         charge = get_object_or_404(
             Charge, processor_id=kwargs.get('charge'))
         organization = charge.customer
     elif kwargs.has_key('organization'):
         organization = get_object_or_404(Organization,
             slug=kwargs.get('organization'))
     else:
         organization = get_current_provider()
     if organization and _contributor_readonly(request, [organization]):
         return view_func(request, *args, **kwargs)
     raise PermissionDenied
コード例 #10
0
 def to_representation(self, obj):
     ret = super(TransactionSerializer, self).to_representation(obj)
     is_debit = self._is_debit(obj)
     if is_debit:
         amount = as_money(obj.orig_amount, '-%s' % obj.orig_unit)
     else:
         amount = as_money(obj.dest_amount, obj.dest_unit)
     ret.update({
         'description':
         as_html_description(obj, provider=get_current_provider()),
         'is_debit':
         is_debit,
         'amount':
         amount
     })
     return ret
コード例 #11
0
ファイル: decorators.py プロジェクト: Qbitus/djaodjin-saas
def pass_direct(request, charge=None, organization=None, strength=NORMAL):
    """
    Returns True if the request authenticated ``User`` is a direct contributor
    (or manager) for the ``Organization`` associated to the request.

    Managers can issue all types of requests (GET, POST, etc.) while
    contributors are restricted to GET requests.

    .. image:: perms-contrib.*
    """
    if charge:
        charge = get_object_or_404(Charge, processor_id=charge)
        organization = charge.customer
    elif organization and not isinstance(organization, Organization):
        organization = get_object_or_404(Organization, slug=organization)
    else:
        organization = get_current_provider()
    return organization and _has_valid_access(request, [organization], strength)
コード例 #12
0
def pass_direct(request, charge=None, organization=None, strength=NORMAL):
    """
    Returns True if the request authenticated ``User`` is a direct contributor
    (or manager) for the ``Organization`` associated to the request.

    Managers can issue all types of requests (GET, POST, etc.) while
    contributors are restricted to GET requests.

    .. image:: perms-contrib.*
    """
    if charge:
        charge = get_object_or_404(Charge, processor_id=charge)
        organization = charge.customer
    elif organization and not isinstance(organization, Organization):
        organization = get_object_or_404(Organization, slug=organization)
    else:
        organization = get_current_provider()
    return organization and _has_valid_access(request, [organization],
                                              strength)
コード例 #13
0
ファイル: decorators.py プロジェクト: altuzar/djaodjin-saas
def pass_provider_only(request,
                       charge=None, organization=None, strength=NORMAL):
    """
    Returns True if the request authenticated ``User``
    is a contributor (or manager) for a provider to the ``Organization``
    associated to the request.

    When *strength* is NORMAL, managers can issue all types of requests
    (GET, POST, etc.) while contributors are restricted to GET requests.

    .. image:: perms-contrib-provider-only.*
    """
    if charge:
        charge = get_object_or_404(Charge, processor_key=charge)
        organization = charge.customer
    elif organization:
        organization = get_object_or_404(Organization, slug=organization)
    if organization:
        return _has_valid_access(request,
            list(Organization.objects.providers_to(organization)), strength)
    return  _has_valid_access(request, [get_current_provider()])
コード例 #14
0
ファイル: billing.py プロジェクト: altuzar/djaodjin-saas
 def get_initial(self):
     """
     Populates place order forms with the organization address
     whenever possible.
     """
     self.customer = self.get_organization()
     kwargs = super(CardFormMixin, self).get_initial()
     provider = get_current_provider()
     if self.customer.country:
         country = self.customer.country
     else:
         country = provider.country
     if self.customer.region:
         region = self.customer.region
     else:
         region = provider.region
     kwargs.update({'card_name': self.customer.full_name,
                    'card_city': self.customer.locality,
                    'card_address_line1': self.customer.street_address,
                    'country': country,
                    'region': region,
                    'card_address_zip': self.customer.postal_code})
     return kwargs
コード例 #15
0
def pass_provider_only(request,
                       charge=None,
                       organization=None,
                       strength=NORMAL):
    """
    Returns True if the request authenticated ``User``
    is a contributor (or manager) for a provider to the ``Organization``
    associated to the request.

    When *strength* is NORMAL, managers can issue all types of requests
    (GET, POST, etc.) while contributors are restricted to GET requests.

    .. image:: perms-contrib-provider-only.*
    """
    if charge:
        charge = get_object_or_404(Charge, processor_key=charge)
        organization = charge.customer
    elif organization:
        organization = get_object_or_404(Organization, slug=organization)
    if organization:
        return _has_valid_access(
            request, list(Organization.objects.providers_to(organization)),
            strength)
    return _has_valid_access(request, [get_current_provider()])
コード例 #16
0
ファイル: __init__.py プロジェクト: altuzar/djaodjin-saas
 def get(self, request, *args, **kwargs):
     provider = get_current_provider()
     if pass_direct(request, organization=provider):
         kwargs.update({self.slug_url_kwarg: provider})
         return RedirectView.get(self, request, *args, **kwargs)
     return super(ProviderRedirectView, self).get(request, *args, **kwargs)
コード例 #17
0
ファイル: mixins.py プロジェクト: marmida/djaodjin-saas
 def get_provider():
     return get_current_provider()
コード例 #18
0
def describe(transaction):
    return mark_safe(as_html_description(
        transaction, provider=get_current_provider()))
コード例 #19
0
 def get_provider():
     return get_current_provider()
コード例 #20
0
def is_direct(request, organization=None):
    if organization is None:
        organization = get_current_provider()
    return pass_direct(request, organization=organization)
コード例 #21
0
ファイル: saas_tags.py プロジェクト: wshcdr/djaodjin-saas
def is_current_provider(organization):
    # XXX Use slug because both organizations might come from a different db.
    return organization.slug == get_current_provider().slug
コード例 #22
0
def is_current_provider(organization):
    # XXX Use slug because both organizations might come from a different db.
    return organization.slug == get_current_provider().slug
コード例 #23
0
def is_direct(request, organization=None):
    if organization is None:
        organization = get_current_provider()
    return pass_direct(request, organization=organization)
コード例 #24
0
def describe(transaction):
    return mark_safe(as_html_description(
        transaction, provider=get_current_provider()))
コード例 #25
0
ファイル: legal.py プロジェクト: marmida/djaodjin-saas
def _read_agreement_file(slug, context=None):
    import markdown
    if not context:
        context = {'organization': get_current_provider()}
    source, _ = loader.find_template('saas/agreements/legal_%s.md' % slug)
    return markdown.markdown(source.render(Context(context)))
コード例 #26
0
ファイル: __init__.py プロジェクト: altuzar/djaodjin-saas
 def get(self, request, *args, **kwargs):
     provider = get_current_provider()
     if pass_direct(request, organization=provider):
         kwargs.update({self.slug_url_kwarg: provider})
         return RedirectView.get(self, request, *args, **kwargs)
     return super(ProviderRedirectView, self).get(request, *args, **kwargs)