Commit 6f86a76b authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

remove astakos obsolete code for billing & timeline

parent eb16ce84
...@@ -66,16 +66,13 @@ from django.core.exceptions import PermissionDenied, ObjectDoesNotExist ...@@ -66,16 +66,13 @@ from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from astakos.im.settings import ( from astakos.im.settings import (
DEFAULT_USER_LEVEL, INVITATIONS_PER_LEVEL, DEFAULT_USER_LEVEL, INVITATIONS_PER_LEVEL,
AUTH_TOKEN_DURATION, BILLING_FIELDS, AUTH_TOKEN_DURATION, EMAILCHANGE_ACTIVATION_DAYS, LOGGING_LEVEL,
EMAILCHANGE_ACTIVATION_DAYS, LOGGING_LEVEL,
SITENAME, SERVICES, MODERATION_ENABLED) SITENAME, SERVICES, MODERATION_ENABLED)
from astakos.im import settings as astakos_settings from astakos.im import settings as astakos_settings
from astakos.im.endpoints.qh import ( from astakos.im.endpoints.qh import (
register_users, register_resources, qh_add_quota, QuotaLimits, register_users, register_resources, qh_add_quota, QuotaLimits,
qh_query_serials, qh_ack_serials) qh_query_serials, qh_ack_serials)
from astakos.im import auth_providers from astakos.im import auth_providers
#from astakos.im.endpoints.aquarium.producer import report_user_event
#from astakos.im.tasks import propagate_groupmembers_quota
import astakos.im.messages as astakos_messages import astakos.im.messages as astakos_messages
from .managers import ForUpdateManager from .managers import ForUpdateManager
...@@ -1713,25 +1710,7 @@ def user_post_save(sender, instance, created, **kwargs): ...@@ -1713,25 +1710,7 @@ def user_post_save(sender, instance, created, **kwargs):
create_astakos_user(instance) create_astakos_user(instance)
post_save.connect(user_post_save, sender=User) post_save.connect(user_post_save, sender=User)
def astakosuser_pre_save(sender, instance, **kwargs):
instance.aquarium_report = False
instance.new = False
try:
db_instance = AstakosUser.objects.get(id=instance.id)
except AstakosUser.DoesNotExist:
# create event
instance.aquarium_report = True
instance.new = True
else:
get = AstakosUser.__getattribute__
l = filter(lambda f: get(db_instance, f) != get(instance, f),
BILLING_FIELDS)
instance.aquarium_report = True if l else False
pre_save.connect(astakosuser_pre_save, sender=AstakosUser)
def astakosuser_post_save(sender, instance, created, **kwargs): def astakosuser_post_save(sender, instance, created, **kwargs):
if instance.aquarium_report:
report_user_event(instance, create=instance.new)
if not created: if not created:
return return
# TODO handle socket.error & IOError # TODO handle socket.error & IOError
......
# Copyright 2011 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from celery.task import task, periodic_task
from celery.schedules import crontab
from functools import wraps
from astakos.im.endpoints.qh import send_quota
from astakos.im.endpoints.aquarium.producer import (
report_credits_event,
report_user_event)
from astakos.im.endpoints.aquarium.client import AquariumClient
import logging
logger = logging.getLogger(__name__)
def log(func):
@wraps(func)
def wrapper(*args, **kwargs):
logger.info('Starting the %s with args=%s kwargs=%s' % (
func, args, kwargs
)
)
return func(*args, **kwargs)
return wrapper
@periodic_task(run_every=crontab(day_of_month='1'))
@log
def propagate_credits_update():
report_credits_event()
@task
@log
def propagate_groupmembers_quota(group):
if group.is_disabled:
return
send_quota(group.approved_members)
@task
@log
def request_billing(user, start, end):
return AquariumClient().get_billing(user, start, end)
...@@ -91,14 +91,12 @@ from astakos.im.functions import ( ...@@ -91,14 +91,12 @@ from astakos.im.functions import (
SendNotificationError, SendNotificationError,
accept_membership, reject_membership, remove_membership, accept_membership, reject_membership, remove_membership,
leave_project, join_project, enroll_member) leave_project, join_project, enroll_member)
# from astakos.im.endpoints.qh import timeline_charge
from astakos.im.settings import ( from astakos.im.settings import (
COOKIE_DOMAIN, LOGOUT_NEXT, COOKIE_DOMAIN, LOGOUT_NEXT,
LOGGING_LEVEL, PAGINATE_BY, LOGGING_LEVEL, PAGINATE_BY,
RESOURCES_PRESENTATION_DATA, PAGINATE_BY_ALL, RESOURCES_PRESENTATION_DATA, PAGINATE_BY_ALL,
MODERATION_ENABLED) MODERATION_ENABLED)
from astakos.im import settings as astakos_settings from astakos.im import settings as astakos_settings
#from astakos.im.tasks import request_billing
from astakos.im.api.callpoint import AstakosCallpoint from astakos.im.api.callpoint import AstakosCallpoint
from astakos.im import auth_providers from astakos.im import auth_providers
from astakos.im.templatetags.filters import ResourcePresentation from astakos.im.templatetags.filters import ResourcePresentation
...@@ -843,98 +841,6 @@ def resource_usage(request): ...@@ -843,98 +841,6 @@ def resource_usage(request):
resource_usage=backenddata, resource_usage=backenddata,
result=result) result=result)
##@require_http_methods(["GET"])
#@require_http_methods(["POST", "GET"])
#@signed_terms_required
#@login_required
#def billing(request):
#
# today = datetime.today()
# month_last_day = calendar.monthrange(today.year, today.month)[1]
# start = request.POST.get('datefrom', None)
# if start:
# today = datetime.fromtimestamp(int(start))
# month_last_day = calendar.monthrange(today.year, today.month)[1]
#
# start = datetime(today.year, today.month, 1).strftime("%s")
# end = datetime(today.year, today.month, month_last_day).strftime("%s")
# r = request_billing.apply(args=('pgerakios@grnet.gr',
# int(start) * 1000,
# int(end) * 1000))
# data = {}
#
# try:
# status, data = r.result
# data = _clear_billing_data(data)
# if status != 200:
# messages.error(request, _(astakos_messages.BILLING_ERROR) % status)
# except:
# messages.error(request, r.result)
#
# return render_response(
# template='im/billing.html',
# context_instance=get_context(request),
# data=data,
# zerodate=datetime(month=1, year=1970, day=1),
# today=today,
# start=int(start),
# month_last_day=month_last_day)
#def _clear_billing_data(data):
#
# # remove addcredits entries
# def isnotcredit(e):
# return e['serviceName'] != "addcredits"
#
# # separate services
# def servicefilter(service_name):
# service = service_name
#
# def fltr(e):
# return e['serviceName'] == service
# return fltr
#
# data['bill_nocredits'] = filter(isnotcredit, data['bill'])
# data['bill_vmtime'] = filter(servicefilter('vmtime'), data['bill'])
# data['bill_diskspace'] = filter(servicefilter('diskspace'), data['bill'])
# data['bill_addcredits'] = filter(servicefilter('addcredits'), data['bill'])
#
# return data
# #@require_http_methods(["GET"])
# @require_http_methods(["POST", "GET"])
# @signed_terms_required
# @login_required
# def timeline(request):
# # data = {'entity':request.user.email}
# timeline_body = ()
# timeline_header = ()
# # form = TimelineForm(data)
# form = TimelineForm()
# if request.method == 'POST':
# data = request.POST
# form = TimelineForm(data)
# if form.is_valid():
# data = form.cleaned_data
# timeline_header = ('entity', 'resource',
# 'event name', 'event date',
# 'incremental cost', 'total cost')
# timeline_body = timeline_charge(
# data['entity'], data['resource'],
# data['start_date'], data['end_date'],
# data['details'], data['operation'])
#
# return render_response(template='im/timeline.html',
# context_instance=get_context(request),
# form=form,
# timeline_header=timeline_header,
# timeline_body=timeline_body)
# return data
# TODO: action only on POST and user should confirm the removal # TODO: action only on POST and user should confirm the removal
@require_http_methods(["GET", "POST"]) @require_http_methods(["GET", "POST"])
@login_required @login_required
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment