コード例 #1
0
 def prepare_content_count(self, obj):
     """ Upcoming events for this project/group """
     try:
         event_model = resolve_class('cosinnus_event.models.Event')
     except ImportError:
         return -1
     return event_model.get_current(obj, AnonymousUser()).count()
コード例 #2
0
 def extra_forms(self):
     if not hasattr(self, '_extra_forms'):
         self._extra_forms = []
         initial = hasattr(self, 'instance') and getattr(self.instance, self.extra_forms_field) or None
         for form in getattr(settings, self.extra_forms_setting, []):
             form_class = resolve_class(form)
             if self.request.POST:
                 self._extra_forms.append(form_class(data=self.request.POST))
             else:
                 self._extra_forms.append(form_class(initial=initial))
     return self._extra_forms
コード例 #3
0
    def get_context_data(self, **kwargs):
        context = super(GroupObjectCountMixin, self).get_context_data(**kwargs)

        object_counts = {}
        for app in app_registry:
            app_name = app_registry.get_name(app)
            if self.group.is_app_deactivated(app):
                continue
            if app in self.app_object_count_mappings:
                model = resolve_class(self.app_object_count_mappings[app])
                # only for counting the objects, we use a fake superuser, so we get the actual
                # counts of the contents, and not the visible ones for current user
                fake_admin = AnonymousUser()
                fake_admin.is_superuser = True
                object_counts[app_name] = model.get_current(
                    self.group, fake_admin).count()
        context.update({
            'object_counts': object_counts,
        })
        return context
コード例 #4
0
    def _import_second_round_relations(self,
                                       item_data_list,
                                       user_import_item,
                                       dry_run=True):
        """ Stub to support an additional, second import round for CSV items,
            run after the main import has been processed and all items have been created.
            Mainly enables things like group membership or tag assignments, which
            wouldn't work on a single pass of the imported data because they may
            reference data that follows further on in the CSV. """
        pass

    def get_user_report_title(self, item_data):
        return 'Row: #' + str(item_data['ROW_NUM'] +
                              1) + ' <b>' + item_data.get(
                                  self.field_name_map['first_name'],
                                  '(no name)') + '</b> <i>' + item_data.get(
                                      self.field_name_map['email'],
                                      '(no email)') + '</i>'


class DryRunFinishedException(Exception):
    """ An exception that rolls back an atomic block for a dry run when it has finished successfully. """
    pass


# allow dropin of labels class
CosinnusUserImportProcessor = CosinnusUserImportProcessorBase
if getattr(settings, 'COSINNUS_USER_IMPORT_PROCESSOR_CLASS_DROPIN', None):
    CosinnusUserImportProcessor = resolve_class(
        settings.COSINNUS_USER_IMPORT_PROCESSOR_CLASS_DROPIN)
コード例 #5
0
    MESSAGE_ONLY_ADMINS_MAY_CREATE = _(
        'Sorry, only portal administrators can create Conferences! You can write a message to one of the administrators to create a Conference for you. Below you can find a listing of all administrators.'
    )
    MESSAGE_ONLY_ADMINS_MAY_DEACTIVATE = _(
        'Sorry, only portal administrators can deactivate Conferences! You can write a message to one of the administrators to deactivate it for you. Below you can find a listing of all administrators.'
    )
    MESSAGE_MEMBERS_ONLY = _(
        'Only conference members can see the content you requested. Apply to become a member now!'
    )


# allow dropin of trans classes
CosinnusProjectTrans = CosinnusProjectTransBase
if getattr(settings, 'COSINNUS_GROUP_TRANS_TYPED_CLASSES_DROPINS',
           {}).get(0, None):
    CosinnusProjectTrans = resolve_class(
        settings.COSINNUS_GROUP_TRANS_TYPED_CLASSES_DROPINS[0])

CosinnusSocietyTrans = CosinnusSocietyTransBase
if getattr(settings, 'COSINNUS_GROUP_TRANS_TYPED_CLASSES_DROPINS',
           {}).get(1, None):
    CosinnusSocietyTrans = resolve_class(
        settings.COSINNUS_GROUP_TRANS_TYPED_CLASSES_DROPINS[1])

CosinnusConferenceTrans = CosinnusConferenceTransBase
if getattr(settings, 'COSINNUS_GROUP_TRANS_TYPED_CLASSES_DROPINS',
           {}).get(2, None):
    CosinnusConferenceTrans = resolve_class(
        settings.COSINNUS_GROUP_TRANS_TYPED_CLASSES_DROPINS[2])

GROUP_TRANS_MAP = {
    0: CosinnusProjectTrans,
コード例 #6
0
    # in the select list, this is the "none chosen" choice string
    MANAGED_TAG_FIELD_EMPTY_CHOICE = _('No Tag selected')

    @classmethod
    def get_labels_dict(cls):
        """ Returns a dict of all labels.
            Note: lazy translation objects will be resolved here! """
        return dict([(key, force_text(val))
                     for (key, val) in cls.__dict__.items()
                     if not key.startswith('_')])


# allow dropin of labels class
MANAGED_TAG_LABELS = CosinnusManagedTagLabels
if getattr(settings, 'COSINNUS_MANAGED_TAGS_LABEL_CLASS_DROPIN', None):
    MANAGED_TAG_LABELS = resolve_class(
        settings.COSINNUS_MANAGED_TAGS_LABEL_CLASS_DROPIN)


class CosinnusManagedTagManager(models.Manager):

    # a list of all CosinnusManagedTags
    _MANAGED_TAG_ALL_LIST_CACHE_KEY = 'cosinnus/core/portal/%d/managed_tags/all'  # portal_id
    # a dict of *both* mappings from int and slug to CosinnusManagedTags. contains duplicate tags!
    _MANAGED_TAG_DICT_CACHE_KEY = 'cosinnus/core/portal/%d/managed_tags/dict'  # portal_id

    def all_in_portal(self):
        """ Returns all managed tags within the current portal only """
        return self.get_queryset().filter(
            portal=CosinnusPortal().get_current())

    def all_in_portal_cached(self):
コード例 #7
0
def send_payment_event_payment_email(payment, event):
    """ Sends an email to a user for an event such ass success/errors in payments, or updates to subscriptions.
        Mail type depends on the given event.
        @param payment: Always supply a payment for this function, the subscription will be taken from its
            `subscription` relation. If all you have is a subscription, supply the `subscription.last_payment`.
        @param event: one of the values of `PAYMENT_EVENTS`. 
        @return: True if the mail was successfully relayed, False or raises otherwise. 
    """
    cur_language = translation.get_language()
    try:
        if not payment.user:
            logger.warning(
                'Sending payment status message was ignored because no user was attached to the payment',
                extra={'payment': payment.id})
            return
        if not event in PAYMENT_EVENTS:
            logger.error(
                'Could not send out a payment event email because the event type was unknown.',
                extra={'payment': payment.id})
            return
        user = payment.user
        email = user.email
        template = 'wechange_payments/mail/mail_base.html'
        subject_template = 'wechange_payments/mail/subject_base.txt'
        portal = CosinnusPortal.get_current()

        # switch language to user's preference language
        translation.activate(
            getattr(user.cosinnus_profile, 'language',
                    settings.LANGUAGES[0][0]))

        link_html = '[' + str(pgettext_lazy(
            '(URL-LABEL)', 'Link')) + '](' + portal.get_domain() + '%s)'
        mail_html = '[%s](mailto:%s)'

        # prepare all possible variables
        sepa_mandate = None
        iban = None
        if payment.type == PAYMENT_TYPE_DIRECT_DEBIT:
            reference_payment = payment.subscription.reference_payment
            sepa_mandate = reference_payment.extra_data.get(
                'sepa_mandate_token', None)
            iban = reference_payment.extra_data.get('iban', None)

        variables = {
            'payment':
            payment,
            'link_payment_info':
            link_html % reverse('wechange_payments:payment-infos'),
            'link_invoices':
            link_html % reverse('wechange_payments:invoices'),
            'link_new_payment':
            link_html % reverse('wechange_payments:payment'),
            'link_payment_issues':
            link_html % reverse('wechange_payments:suspended-subscription'),
            'portal_name':
            portal.name,
            'username':
            full_name(payment.user),
            'payment_amount':
            str(int(payment.amount)),
            'vat_amount':
            str(int(settings.PAYMENTS_INVOICE_PROVIDER_TAX_RATE_PERCENT)),
            'subscription_amount':
            str(int(payment.subscription.amount)),
            'next_debit_date':
            localize(payment.subscription.get_next_payment_date()),
            'payment_method':
            payment.get_type_string(),
            'support_email':
            mail_html % (portal.support_email, portal.support_email),
            'sepa_mandate':
            sepa_mandate,
            'iban':
            iban,
            'sepa_creditor':
            settings.PAYMENTS_SEPA_CREDITOR_ID,
        }
        # compose email parts
        data = {
            'mail_pre': MAIL_PRE % variables,
            'mail_links': MAIL_LINKS % variables,
            'mail_post': MAIL_POST % variables,
            'mail_body': MAIL_BODY.get(event) % variables,
            'mail_subject': MAIL_SUBJECT.get(event) % variables,
        }
        # add SEPA mandate info to mail body for successful SEPA payment email
        if payment.type == PAYMENT_TYPE_DIRECT_DEBIT and event == PAYMENT_EVENT_SUCCESSFUL_PAYMENT:
            sepa_variables = {
                'payment': payment.subscription.reference_payment,
                'SETTINGS': settings,
            }
            data['mail_body'] += '\n\n-\n\n' + render_to_string(
                'wechange_payments/mail/sepa_mandate_partial.html',
                sepa_variables)

        # send mail
        if settings.PAYMENTS_USE_HOOK_INSTEAD_OF_SEND_MAIL == True:
            signals.success_email_sender.send(
                sender=payment,
                to_user=user,
                template=template,
                subject_template=subject_template,
                data=data)
        else:
            subject = render_to_string(subject_template, data)
            message = render_to_string(template, data)
            mail_func = resolve_class(settings.PAYMENTS_SEND_MAIL_FUNCTION)
            mail_func(subject, message, settings.DEFAULT_FROM_EMAIL, [email])
        return True
    except Exception as e:
        logger.warning(
            'Payments: Sending a payment status email to the user failed!',
            extra={
                'internal_transaction_id': payment.internal_transaction_id,
                'vendor_transaction_id': payment.vendor_transaction_id,
                'exception': e
            })
        if settings.DEBUG:
            raise
        return False

    # switch language back to previous
    translation.activate(cur_language)