Beispiel #1
0
def swap_post_save(sender, instance, created, *args, **kwargs):
    if created:
        return

    # last comment
    comment = ''
    last_comment = ''
    c = instance.comments.all().order_by("-id")
    if c.count():
        last_comment = c[0].comment

    if instance.status == 'CON':
        p1 = instance.user_to.get_profile()
        p1.credits += instance.credits_from
        p1.credits -= instance.credits_to
        p1.save()

        p2 = instance.user_from.get_profile()
        p2.credits += instance.credits_to
        p2.credits -= instance.credits_from
        p2.save()

        instance.status = 'DON'
        items = {'from': [i.name for i in instance.items_from()], 'to': [i.name for i in instance.items_to()]}
        instance.done_msg = simplejson.dumps(items)

        instance.premiate_users()
        instance.premiate_groups()

        instance.save()

        # removing items from sender
        for item in instance.items.filter(item__type='IT').exclude(item__quantity=0):
            item = item.item
            item.quantity = item.quantity - 1

            if item.quantity <= 0:
                # zero items, removing
                item.delete()
            else:
                item.save()
        return

    elif instance.status == 'DON':
        comment = _("Conglatulations, swap has been accepted")
        title = _("A swap has been accepted")
    elif instance.status in ['US1', 'US2']:
        title = _("A swap has been modified")
    elif instance.status == 'CAN':
        title = _("A swap has been canceled")

    url = reverse('swap_view', args=(instance.id,))

    context = {'swap': instance, 'url': url, 'comment': comment,
               'last_comment': last_comment,
               'credit_name': settings.ETK_CREDIT,
               'status': instance.get_status_msg()}
    template_email('truekko/swap_modified_mail.txt',
                   title,
                   [instance.user_to.email, instance.user_from.email], context)
Beispiel #2
0
def membership_pre_delete(sender, instance, *args, **kwargs):
    url = reverse('view_group', args=(instance.group.id,))

    context = {'membership': instance, 'url': url}
    template_email('truekko/membership_delete_mail.txt',
                   'Community "%(group)s" membership' % {'group': instance.group.name},
                   [instance.user.email], context)
Beispiel #3
0
def membership_pre_delete(sender, instance, *args, **kwargs):
    url = reverse('view_group', args=(instance.group.id, ))

    context = {'membership': instance, 'url': url}
    template_email(
        'truekko/membership_delete_mail.txt',
        'Community "%(group)s" membership' % {'group': instance.group.name},
        [instance.user.email], context)
Beispiel #4
0
def denounce_post_save(sender, instance, created, *args, **kwargs):
    if created:
        # Sending email notification to admin, denouncer and denounced
        email_list = instance.group.admins_emails() + [instance.user_from.email, instance.user_to.email]
        url = reverse('group_denounce_view', args=[instance.id])

        context = {'denounce': instance, 'url': url}
        template_email('truekko/denounce_mail.txt',
                       _("%(user)s user has been denounced in community %(group)s") % dict(user=instance.user_to.username, group=instance.group.name),
                       email_list, context)
Beispiel #5
0
def denounce_post_save(sender, instance, created, *args, **kwargs):
    if created:
        # Sending email notification to admin, denouncer and denounced
        email_list = instance.group.admins_emails() + [
            instance.user_from.email, instance.user_to.email
        ]
        url = reverse('group_denounce_view', args=[instance.id])

        context = {'denounce': instance, 'url': url}
        template_email(
            'truekko/denounce_mail.txt',
            _("%(user)s user has been denounced in community %(group)s") %
            dict(user=instance.user_to.username, group=instance.group.name),
            email_list, context)
Beispiel #6
0
def membership_post_save(sender, instance, created, *args, **kwargs):
    if created:
        url = reverse('view_group', args=(instance.group.id, ))

        context = {'membership': instance, 'url': url}
        template_email(
            'truekko/membership_mail.txt', 'Community "%(group)s" membership' %
            {'group': instance.group.name}, [instance.user.email], context)

        # if not admin in this group and this memberhip is admin
        # giving 30 truekkos
        credits = 30
        adms = instance.group.admins()
        if len(adms) == 1 and instance.user in adms and instance.role == "ADM":
            p = instance.user.get_profile()
            if p.valid_credits(credits):
                p.credits += credits
                p.premiated_date = datetime.datetime.now()
                p.save()
Beispiel #7
0
def membership_post_save(sender, instance, created, *args, **kwargs):
    if created:
        url = reverse('view_group', args=(instance.group.id,))

        context = {'membership': instance, 'url': url}
        template_email('truekko/membership_mail.txt',
                       'Community "%(group)s" membership' % {'group': instance.group.name},
                       [instance.user.email], context)

        # if not admin in this group and this memberhip is admin
        # giving 30 truekkos
        credits = 30
        adms = instance.group.admins()
        if len(adms) == 1 and instance.user in adms and instance.role == "ADM":
                p = instance.user.get_profile()
                if p.valid_credits(credits):
                    p.credits += credits
                    p.premiated_date = datetime.datetime.now()
                    p.save()
Beispiel #8
0
def wall_message_post_save(sender, instance, created, *args, **kwargs):
    if created:
        name = instance.wall.name
        email_list = []
        # Sending email notification to receiver
        if instance.wall.user:
            if instance.wall.user.get_profile().receive_notification:
                email_list.append(instance.wall.user.email)
            url = reverse('view_profile', args=[instance.wall.user.username])
            name = instance.wall.user.username
        elif instance.wall.group:
            email_list = [
                i.email for i in instance.wall.group.members()
                if i.get_profile().receive_notification
            ]
            url = reverse('view_group', args=[instance.wall.group.id])
            name = instance.wall.group.name
        else:
            email_list = [
                i.email for i in User.objects.filter(is_superuser=True)
                if i.get_profile().receive_notification
            ]
            url = '/'

        if email_list:
            surl = reverse('edit_profile')
            context = {
                'message': instance,
                'name': name,
                'url': url,
                'surl': surl
            }
            template_email(
                'truekko/message_mail.txt',
                _("New message by %(user)s in %(wall)s") %
                dict(user=instance.user, wall=instance.wall.name), email_list,
                context)
Beispiel #9
0
def wall_message_post_save(sender, instance, created, *args, **kwargs):
    if created:
        name = instance.wall.name
        email_list = []
        # Sending email notification to receiver
        if instance.wall.user:
            if instance.wall.user.get_profile().receive_notification:
                email_list.append(instance.wall.user.email)
            url = reverse('view_profile', args=[instance.wall.user.username])
            name = instance.wall.user.username
        elif instance.wall.group:
            email_list = [i.email for i in instance.wall.group.members() if i.get_profile().receive_notification]
            url = reverse('view_group', args=[instance.wall.group.id])
            name = instance.wall.group.name
        else:
            email_list = [i.email for i in User.objects.filter(is_superuser=True) if i.get_profile().receive_notification]
            url = '/'

        if email_list:
            surl = reverse('edit_profile')
            context = {'message': instance, 'name': name, 'url': url, 'surl': surl}
            template_email('truekko/message_mail.txt',
                           _("New message by %(user)s in %(wall)s") % dict(user=instance.user, wall=instance.wall.name),
                           email_list, context)
Beispiel #10
0
def swap_post_save(sender, instance, created, *args, **kwargs):
    if created:
        return

    # last comment
    comment = ''
    last_comment = ''
    c = instance.comments.all().order_by("-id")
    if c.count():
        last_comment = c[0].comment

    if instance.status == 'CON':
        p1 = instance.user_to.get_profile()
        p1.credits += instance.credits_from
        p1.credits -= instance.credits_to
        p1.save()

        p2 = instance.user_from.get_profile()
        p2.credits += instance.credits_to
        p2.credits -= instance.credits_from
        p2.save()

        instance.status = 'DON'
        items = {
            'from': [i.name for i in instance.items_from()],
            'to': [i.name for i in instance.items_to()]
        }
        instance.done_msg = simplejson.dumps(items)

        instance.premiate_users()
        instance.premiate_groups()

        instance.save()

        # removing items from sender
        for item in instance.items.filter(item__type='IT').exclude(
                item__quantity=0):
            item = item.item
            item.quantity = item.quantity - 1

            if item.quantity <= 0:
                # zero items, removing
                item.delete()
            else:
                item.save()
        return

    elif instance.status == 'DON':
        comment = _("Conglatulations, swap has been accepted")
        title = _("A swap has been accepted")
    elif instance.status in ['US1', 'US2']:
        title = _("A swap has been modified")
    elif instance.status == 'CAN':
        title = _("A swap has been canceled")

    url = reverse('swap_view', args=(instance.id, ))

    context = {
        'swap': instance,
        'url': url,
        'comment': comment,
        'last_comment': last_comment,
        'credit_name': settings.ETK_CREDIT,
        'status': instance.get_status_msg()
    }
    template_email('truekko/swap_modified_mail.txt', title,
                   [instance.user_to.email, instance.user_from.email], context)