Skip to content

Commit

Permalink
Merge branch 'release/v2.8.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
areski committed Dec 9, 2013
2 parents 19a9920 + 54dbaa1 commit ec7700c
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 53 deletions.
38 changes: 38 additions & 0 deletions CHANGES.txt
@@ -1,6 +1,44 @@
Changelog
=========

2.8.2 (2013-12-09)
------------------

* Support for Django 1.6


2.8.1 (2013-06-03)
------------------

* Add setting to ceil_strdate - hour_min support hours and minutes


2.8.0 (2013-06-03)
------------------

* Add constant EXPORT_CHOICE - Define list of format to export
* Add class HorizRadioRenderer - This overrides widget method to put
radio buttons horizontally instead of vertically.


2.7.2 (2013-05-13)
------------------

* new function unset_session_var : Unset session variables


2.7.1 (2013-05-13)
------------------

* new function getvar(request, field_name, setsession=False)
Check field in POST/GET request and return field value
if there is value you can also save a session variable


2.7.0 (2013-05-02)
------------------

* add percentage function - Get percentage value


2.6.0 (2013-02-22)
Expand Down
6 changes: 5 additions & 1 deletion README.rst
Expand Up @@ -29,6 +29,10 @@ It contains the following helper mainly related to Django :
* ``get_news`` - Get news from news url
* ``only_one`` - Decorator for distributed task locking in celery
* ``ceil_strdate`` - Convert a string date to either a start or end day date
* ``percentage`` - Get percentage value
* ``unset_session_var`` - Unset settion variable
* ``getvar`` - Check field in POST/GET request and return field value. if there is value you can
also save a session variable

4. Common Template tags :

Expand Down Expand Up @@ -70,7 +74,7 @@ License
-------

MPL V2.0 License
Copyright (C) 2011-2012 Star2Billing S.L.
Copyright (C) 2011-2013 Star2Billing S.L.

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this file,
Expand Down
6 changes: 3 additions & 3 deletions common/__init__.py
Expand Up @@ -8,16 +8,16 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
#

# :copyright: (c) 2011 - 2012 by Arezqui Belaid.
# :copyright: (c) 2011-2013 by Arezqui Belaid.
# :license: MPL 2.0, see COPYING for more details.

VERSION = (2, 6, 0, "")
VERSION = (2, 8, 2, "")
__version__ = ".".join(map(str, VERSION[0:3])) + "".join(VERSION[3:])
__author__ = "Arezqui Belaid"
__contact__ = "info@star2billing.com"
Expand Down
4 changes: 2 additions & 2 deletions common/admin_custom_actions.py
Expand Up @@ -5,7 +5,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
Expand Down Expand Up @@ -47,4 +47,4 @@ def export_as_csv(modeladmin, request, queryset):
writer.writerow([unicode(getattr(obj, field)) for field in field_names])
return response
export_as_csv.short_description = description
return export_as_csv
return export_as_csv
4 changes: 2 additions & 2 deletions common/app_label_renamer.py
Expand Up @@ -5,7 +5,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
Expand Down Expand Up @@ -54,7 +54,7 @@ def wrap(model_or_iterable, admin_class=None, **option):
if model.__module__ != self.module:
continue
if admin_class is None:
admin_class = type(model.__name__+'Admin', (admin.ModelAdmin,), {})
admin_class = type(model.__name__ + 'Admin', (admin.ModelAdmin,), {})
admin_class.add_view = rename_breadcrumbs(admin_class.add_view)
admin_class.change_view = rename_breadcrumbs(admin_class.change_view)
admin_class.changelist_view = rename_breadcrumbs(admin_class.changelist_view)
Expand Down
2 changes: 1 addition & 1 deletion common/big_integer_field.py
Expand Up @@ -5,7 +5,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
Expand Down
20 changes: 20 additions & 0 deletions common/common_constants.py
@@ -0,0 +1,20 @@
#
# Switch2bill-common
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
#
from utils import Choice
from django.utils.translation import ugettext_lazy as _


class EXPORT_CHOICE(Choice):
CSV = 'csv', _('csv').upper()
XLS = 'xls', _('xls').upper()
JSON = 'json', _('json').upper()
34 changes: 34 additions & 0 deletions common/common_forms.py
@@ -0,0 +1,34 @@
#
# Switch2bill-common
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
#
from django import forms
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from common_constants import EXPORT_CHOICE


class HorizRadioRenderer(forms.RadioSelect.renderer):
"""This overrides widget method to put radio buttons horizontally
instead of vertically.
"""
def render(self):
"""Outputs radios"""
return mark_safe(u'\n'.join([u'%s\n' % w for w in self]))


class Exportfile(forms.Form):
"""
Abstract Form : export file in various format e.g. XLS, CSV, JSON
"""
export_to = forms.TypedChoiceField(label=_('export to').capitalize(), required=True,
choices=list(EXPORT_CHOICE),
widget=forms.RadioSelect(renderer=HorizRadioRenderer))
112 changes: 77 additions & 35 deletions common/common_functions.py
Expand Up @@ -5,7 +5,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
Expand Down Expand Up @@ -84,12 +84,7 @@ def unique_list(inlist):
>>> unique_list(inlist)
[1, 2, 4, 5, 6]
"""
# order preserving
uniques = []
for item in inlist:
if item not in uniques:
uniques.append(item)
return uniques
return set(inlist)


def get_unique_id():
Expand Down Expand Up @@ -124,19 +119,19 @@ def comp_month_range():
word_months = _("months")
word_month = _("month")
COMP_MONTH_LIST = (
(12, '- 12 ' + word_months),
(11, '- 11 ' + word_months),
(10, '- 10 ' + word_months),
(9, '- 9 ' + word_months),
(8, '- 8 ' + word_months),
(7, '- 7 ' + word_months),
(6, '- 6 ' + word_months),
(5, '- 5 ' + word_months),
(4, '- 4 ' + word_months),
(3, '- 3 ' + word_months),
(2, '- 2 ' + word_months),
(1, '- 1 ' + word_month),
)
(12, '- 12 ' + word_months),
(11, '- 11 ' + word_months),
(10, '- 10 ' + word_months),
(9, '- 9 ' + word_months),
(8, '- 8 ' + word_months),
(7, '- 7 ' + word_months),
(6, '- 6 ' + word_months),
(5, '- 5 ' + word_months),
(4, '- 4 ' + word_months),
(3, '- 3 ' + word_months),
(2, '- 2 ' + word_months),
(1, '- 1 ' + word_month),
)
return COMP_MONTH_LIST


Expand Down Expand Up @@ -188,10 +183,7 @@ def validate_days(year, month, day):
31
"""
total_days = calendar.monthrange(year, month)
if day > total_days[1]:
return total_days[1]
else:
return day
return ( total_days[1] if (day > total_days[1]) else day )


def month_year_range(enter_date):
Expand Down Expand Up @@ -268,7 +260,10 @@ def get_news(news_url):

#variable check with request
def variable_value(request, field_name):
"""Check field in POST/GET request and return field value"""
"""Check field in POST/GET request and return field value
Depreciated : It will be replaced by getvar
"""
if request.method == 'GET':
if field_name in request.GET:
field_name = request.GET[field_name]
Expand All @@ -284,6 +279,40 @@ def variable_value(request, field_name):
return field_name


def unset_session_var(request, field_list):
"""Unset session variables
field_list = ['destination', 'result']
unset_session_var(request, field_list)
"""
for field in field_list:
request.session['session_' + field] = ''
return True


#Get variable from request
def getvar(request, field_name, setsession=False):
"""Check field in POST/GET request and return field value
if there is value you can also save a session variable
"""
if request.method == 'GET':
if field_name in request.GET:
val = request.GET[field_name]
else:
val = ''

if request.method == 'POST':
if field_name in request.POST:
val = request.POST[field_name]
else:
val = ''

if setsession and val and val != '':
request.session['session_' + field_name] = val

return val


#source_type/destination_type filed check with request
def source_desti_field_chk(base_field, base_field_type, field_name):
"""Prepare filters (kwargs{}) for django queryset
Expand Down Expand Up @@ -411,24 +440,29 @@ def isint(str):
return ok


def ceil_strdate(str_date, start):
def ceil_strdate(str_date, start, hour_min=False):
"""convert a string date to either a start or end day date"""
if start == 'start':
return datetime(int(str_date[0:4]), int(str_date[5:7]),
int(str_date[8:10]), 0, 0, 0, 0)
if hour_min:
return datetime(int(str_date[0:4]), int(str_date[5:7]),
int(str_date[8:10]), int(str_date[11:13]), int(str_date[14:16]), 0, 0)
else:
return datetime(int(str_date[0:4]), int(str_date[5:7]),
int(str_date[8:10]), 0, 0, 0, 0)
else:
return datetime(int(str_date[0:4]), int(str_date[5:7]),
int(str_date[8:10]), 23, 59, 59, 999999)
if hour_min:
return datetime(int(str_date[0:4]), int(str_date[5:7]),
int(str_date[8:10]), int(str_date[11:13]), int(str_date[14:16]), 0, 0)
else:
return datetime(int(str_date[0:4]), int(str_date[5:7]),
int(str_date[8:10]), 23, 59, 59, 999999)


def get_pagination_vars(request, col_field_list, default_sort_field):
"""Return data for django pagination with sort order"""
# Define no of records per page
PAGE_SIZE = settings.PAGE_SIZE
try:
PAGE_NUMBER = int(request.GET['page'])
except:
PAGE_NUMBER = 1
PAGE_NUMBER = int(request.GET.get('page', 1))

# page index
if PAGE_NUMBER > 1:
Expand Down Expand Up @@ -463,4 +497,12 @@ def get_pagination_vars(request, col_field_list, default_sort_field):
'col_name_with_order': col_name_with_order,
'sort_order': sort_order,
}
return data
return data


def percentage(value, total_sum):
"""calculate a percentage"""
if total_sum == 0:
return 0
else:
return round(100 * float(value) / float(total_sum))
2 changes: 1 addition & 1 deletion common/custom_xml_emitter.py
Expand Up @@ -5,7 +5,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
Expand Down
2 changes: 1 addition & 1 deletion common/filter_persist_middleware.py
Expand Up @@ -5,7 +5,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
Expand Down
2 changes: 1 addition & 1 deletion common/intermediate_model_base_class.py
Expand Up @@ -5,7 +5,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
Expand Down
2 changes: 1 addition & 1 deletion common/language_field.py
Expand Up @@ -5,7 +5,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
Expand Down

0 comments on commit ec7700c

Please sign in to comment.