Revision c7b82fdc

b/snf-astakos-app/astakos/im/models.py
66 66

  
67 67
from astakos.im.settings import (
68 68
    DEFAULT_USER_LEVEL, INVITATIONS_PER_LEVEL,
69
    AUTH_TOKEN_DURATION, BILLING_FIELDS,
70
    EMAILCHANGE_ACTIVATION_DAYS, LOGGING_LEVEL,
69
    AUTH_TOKEN_DURATION, EMAILCHANGE_ACTIVATION_DAYS, LOGGING_LEVEL,
71 70
    SITENAME, SERVICES, MODERATION_ENABLED)
72 71
from astakos.im import settings as astakos_settings
73 72
from astakos.im.endpoints.qh import (
74 73
    register_users, register_resources, qh_add_quota, QuotaLimits,
75 74
    qh_query_serials, qh_ack_serials)
76 75
from astakos.im import auth_providers
77
#from astakos.im.endpoints.aquarium.producer import report_user_event
78
#from astakos.im.tasks import propagate_groupmembers_quota
79 76

  
80 77
import astakos.im.messages as astakos_messages
81 78
from .managers import ForUpdateManager
......
1713 1710
    create_astakos_user(instance)
1714 1711
post_save.connect(user_post_save, sender=User)
1715 1712

  
1716
def astakosuser_pre_save(sender, instance, **kwargs):
1717
    instance.aquarium_report = False
1718
    instance.new = False
1719
    try:
1720
        db_instance = AstakosUser.objects.get(id=instance.id)
1721
    except AstakosUser.DoesNotExist:
1722
        # create event
1723
        instance.aquarium_report = True
1724
        instance.new = True
1725
    else:
1726
        get = AstakosUser.__getattribute__
1727
        l = filter(lambda f: get(db_instance, f) != get(instance, f),
1728
                   BILLING_FIELDS)
1729
        instance.aquarium_report = True if l else False
1730
pre_save.connect(astakosuser_pre_save, sender=AstakosUser)
1731

  
1732 1713
def astakosuser_post_save(sender, instance, created, **kwargs):
1733
    if instance.aquarium_report:
1734
        report_user_event(instance, create=instance.new)
1735 1714
    if not created:
1736 1715
        return
1737 1716
    # TODO handle socket.error & IOError
/dev/null
1
# Copyright 2011 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

  
34
from celery.task import task, periodic_task
35
from celery.schedules import crontab
36

  
37
from functools import wraps
38

  
39
from astakos.im.endpoints.qh import send_quota
40
from astakos.im.endpoints.aquarium.producer import (
41
    report_credits_event,
42
    report_user_event)
43
from astakos.im.endpoints.aquarium.client import AquariumClient
44

  
45
import logging
46

  
47
logger = logging.getLogger(__name__)
48

  
49

  
50
def log(func):
51
    @wraps(func)
52
    def wrapper(*args, **kwargs):
53
        logger.info('Starting the %s with args=%s kwargs=%s' % (
54
                    func, args, kwargs
55
                    )
56
                    )
57
        return func(*args, **kwargs)
58
    return wrapper
59

  
60

  
61
@periodic_task(run_every=crontab(day_of_month='1'))
62
@log
63
def propagate_credits_update():
64
    report_credits_event()
65

  
66

  
67
@task
68
@log
69
def propagate_groupmembers_quota(group):
70
    if group.is_disabled:
71
        return
72
    send_quota(group.approved_members)
73

  
74

  
75
@task
76
@log
77
def request_billing(user, start, end):
78
    return AquariumClient().get_billing(user, start, end)
b/snf-astakos-app/astakos/im/views.py
91 91
    SendNotificationError,
92 92
    accept_membership, reject_membership, remove_membership,
93 93
    leave_project, join_project, enroll_member)
94
# from astakos.im.endpoints.qh import timeline_charge
95 94
from astakos.im.settings import (
96 95
    COOKIE_DOMAIN, LOGOUT_NEXT,
97 96
    LOGGING_LEVEL, PAGINATE_BY,
98 97
    RESOURCES_PRESENTATION_DATA, PAGINATE_BY_ALL,
99 98
    MODERATION_ENABLED)
100 99
from astakos.im import settings as astakos_settings
101
#from astakos.im.tasks import request_billing
102 100
from astakos.im.api.callpoint import AstakosCallpoint
103 101
from astakos.im import auth_providers
104 102
from astakos.im.templatetags.filters import ResourcePresentation
......
843 841
                           resource_usage=backenddata,
844 842
                           result=result)
845 843

  
846

  
847
##@require_http_methods(["GET"])
848
#@require_http_methods(["POST", "GET"])
849
#@signed_terms_required
850
#@login_required
851
#def billing(request):
852
#
853
#    today = datetime.today()
854
#    month_last_day = calendar.monthrange(today.year, today.month)[1]
855
#    start = request.POST.get('datefrom', None)
856
#    if start:
857
#        today = datetime.fromtimestamp(int(start))
858
#        month_last_day = calendar.monthrange(today.year, today.month)[1]
859
#
860
#    start = datetime(today.year, today.month, 1).strftime("%s")
861
#    end = datetime(today.year, today.month, month_last_day).strftime("%s")
862
#    r = request_billing.apply(args=('pgerakios@grnet.gr',
863
#                                    int(start) * 1000,
864
#                                    int(end) * 1000))
865
#    data = {}
866
#
867
#    try:
868
#        status, data = r.result
869
#        data = _clear_billing_data(data)
870
#        if status != 200:
871
#            messages.error(request, _(astakos_messages.BILLING_ERROR) % status)
872
#    except:
873
#        messages.error(request, r.result)
874
#
875
#    return render_response(
876
#        template='im/billing.html',
877
#        context_instance=get_context(request),
878
#        data=data,
879
#        zerodate=datetime(month=1, year=1970, day=1),
880
#        today=today,
881
#        start=int(start),
882
#        month_last_day=month_last_day)
883

  
884

  
885
#def _clear_billing_data(data):
886
#
887
#    # remove addcredits entries
888
#    def isnotcredit(e):
889
#        return e['serviceName'] != "addcredits"
890
#
891
#    # separate services
892
#    def servicefilter(service_name):
893
#        service = service_name
894
#
895
#        def fltr(e):
896
#            return e['serviceName'] == service
897
#        return fltr
898
#
899
#    data['bill_nocredits'] = filter(isnotcredit, data['bill'])
900
#    data['bill_vmtime'] = filter(servicefilter('vmtime'), data['bill'])
901
#    data['bill_diskspace'] = filter(servicefilter('diskspace'), data['bill'])
902
#    data['bill_addcredits'] = filter(servicefilter('addcredits'), data['bill'])
903
#
904
#    return data
905

  
906

  
907
# #@require_http_methods(["GET"])
908
# @require_http_methods(["POST", "GET"])
909
# @signed_terms_required
910
# @login_required
911
# def timeline(request):
912
# #    data = {'entity':request.user.email}
913
#     timeline_body = ()
914
#     timeline_header = ()
915
# #    form = TimelineForm(data)
916
#     form = TimelineForm()
917
#     if request.method == 'POST':
918
#         data = request.POST
919
#         form = TimelineForm(data)
920
#         if form.is_valid():
921
#             data = form.cleaned_data
922
#             timeline_header = ('entity', 'resource',
923
#                                'event name', 'event date',
924
#                                'incremental cost', 'total cost')
925
#             timeline_body = timeline_charge(
926
#                 data['entity'], data['resource'],
927
#                 data['start_date'], data['end_date'],
928
#                 data['details'], data['operation'])
929
#
930
#     return render_response(template='im/timeline.html',
931
#                            context_instance=get_context(request),
932
#                            form=form,
933
#                            timeline_header=timeline_header,
934
#                            timeline_body=timeline_body)
935
#     return data
936

  
937

  
938 844
# TODO: action only on POST and user should confirm the removal
939 845
@require_http_methods(["GET", "POST"])
940 846
@login_required

Also available in: Unified diff