Modules

Admin

Django admin module.

class pawapp.admin.ConnectionRateAdmin(model, admin_site)[source]

Admin class for model ConnectionRate.

Api

class pawapp.api.BaseResource(*args, **kwargs)[source]

A Base class for the API resources.

is_authenticated()[source]

A simple hook method for controlling whether a request is authenticated to continue.

By default, we only allow the safe GET methods. All others are denied.

Returns:Whether the request is authenticated or not.
Return type:boolean
class pawapp.api.BillResource(*args, **kwargs)[source]

Resource to listening Bill requests.

detail(phone_number, month=None, year=None)[source]

Returns the data for a GET on a detail-style endpoint.

MUST BE OVERRIDDEN BY THE USER - By default, this returns MethodNotImplemented.

Returns:An item
Return type:object or dict
class pawapp.api.CallEventResource(*args, **kwargs)[source]

Resource to listening CallEvent requests.

create()[source]

Allows for creating data via a POST on a list-style endpoint.

MUST BE OVERRIDDEN BY THE USER - By default, this returns MethodNotImplemented.

Returns:May return the created item or None

Cache

Module to access and save data through the Django cache system.

pawapp.cache.clean_value(key)[source]

Clean cached values.

Parameters:key (str) – Key to identify the cache value.
pawapp.cache.get_value(key)[source]

Get value from cache using pickle.

Parameters:key (str) – Cache key.
Returns:Cached object.
Return type:obj
pawapp.cache.set_value(key, data)[source]

Set value in the cache using pickle.

Parameters:
  • key (str) – Cache key.
  • data (obj) – Object to be saved.

Forms

Django forms module.

class pawapp.forms.CallEventForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)[source]

Form to validate values of CallEvent object.

clean()[source]

Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.

validate_unique()[source]

Call the instance’s validate_unique() method and update the form’s validation errors if any were raised.

Handlers

Handler module for incoming data through the API

class pawapp.handlers.BaseDataHandler(data)[source]

Base data handler

add_error(field, message)[source]

Add message error for a field.

Parameters:
  • field (str) – Field name.
  • message (str) – Message error.
handle()[source]

Process the current data.

MUST BE OVERRIDDEN BY THE USER - By default, this returns NotImplementedError.

Returns:Result for the data processed.
Return type:dict
validate()[source]

Run the validation for the current data.

MUST BE OVERRIDDEN BY THE USER - By default, this returns NotImplementedError.

class pawapp.handlers.BillHandler(data)[source]

Handler class for Bill data.

handle()[source]

Process Bill current data.

Raises:InvalidDataException – Raises if data is not valid.
validate()[source]

Validate fields for current data.

class pawapp.handlers.CallEventHandler(data)[source]

Handler class for CallEvent data.

handle()[source]

Process CallEvent current data.

Raises:InvalidDataException – Raises if data is not valid.
save()[source]

Save current data for CallEvent.

This function calls an async job to save the current data.

validate()[source]

Validate fields for current data.

pawapp.handlers.bill_handler(data)[source]

Convenient function to return Bill handler instance.

pawapp.handlers.callevent_handler(data)[source]

Convenient function to return CallEvent handler instance.

Helpers

Helper functions module

pawapp.helpers.add_list_value(source, key, item)[source]

Add item to a list inside the source dict.

Parameters:
  • source (dict) – Source dict.
  • key (str) – Field where the item will be added.
  • item – Value to be added in the list.
pawapp.helpers.last_period()[source]

Get the last month and year based on current date.

Returns:Year and month of the date.
Return type:tuple
pawapp.helpers.map_dict_fields(source, from_fields, to_fields)[source]

Change the source keys in from_fields to to_fields.

Parameters:
  • source (dict) – Source dict.
  • from_fields (list) – List of fields in the Source.
  • to_fields (list) – List of new fields in the Source.

Jobs

RQ job module

pawapp.jobs.save_callevent(data)[source]

Save the data using CallEvent model.

Models

Django models module.

class pawapp.models.Bill(*args, **kwargs)[source]

Model representing the phone bill.

exception DoesNotExist
exception MultipleObjectsReturned
classmethod data_by_number_period(phone_number, month, year)[source]

Return bill data by phone_number, month and year.

Parameters:
  • phone_number (str) – Phone number
  • month (str) – Month
  • year (str) – Year
classmethod save_by_calls(start_call, end_call, duration, amount)[source]

Save Bill and Item based on the start and end calls.

Parameters:
  • start_call (CallEvent) – CallEvent object representing the start call.
  • end_call (CallEvent) – CallEvent object representing the end call.
  • duration (int) – Call duration.
  • amount (float) – Call value.
class pawapp.models.BillItem(*args, **kwargs)[source]

Model representing the item of a Bill.

exception DoesNotExist
exception MultipleObjectsReturned
from_date_and_time

From_timestamp field splited as date and time values.

repr_duration

Represent duration value.

class pawapp.models.CallEvent(*args, **kwargs)[source]

Model representing the call events ocurred.

exception DoesNotExist
exception MultipleObjectsReturned
classmethod calculate_call(call_id)[source]

Calculated the call value and duration charged.

Parameters:

call_id (int) – Call event Id.

Returns:

Two values representing the total value and

duration calculated.

Return type:

tuple

Raises:
  • InvalidCallPairException – Raises if start or end calls are missing.
  • InvalidCallIntervalException – Raises if end datetime is less than start datetime.
call_timestamp_datetime

Datetime call_timestamp value.

Returns:Call_timestamp value.
Return type:datetime
classmethod interval_by_call_id(call_id)[source]

Return call timestamp interval.

Parameters:call_id (int) – Call event Id
Returns:Start and end datetime
Return type:dict
classmethod save_call(save_bill=False, **data)[source]

Save or update CallEvent.

Parameters:
  • save_bill (bool, optional) – Should save the bill for this call event.
  • **data – Arbitrary keyword arguments.
Returns:

Instance created or updated.

Return type:

CallEvent

class pawapp.models.ConnectionRate(*args, **kwargs)[source]

Model representing the connection rate calls.

exception DoesNotExist
exception MultipleObjectsReturned
classmethod current_rates(use_cache=True)[source]

Current rates available for calculation.

Parameters:use_cache (bool) – Should use the cache.
Returns:
List with dict object with the fields:
from_time, to_time, stangind and minute rates
Return type:list
classmethod mapped_rates_interval(start_datetime, end_datetime)[source]

List of mapped datetime and values intervals.

This method is responsible to calculate the range of intervals between the start and end datetime with respective values.

Parameters:
  • start_datetime (datetime) – Start datetime object.
  • end_datetime (datetime) – End datetime object.
Returns:

List of intervals.

Return type:

list

pawapp.models.postsave_connectionrate_handler(sender, **kwargs)[source]

Clean cache for ConnectionRate