Created
January 24, 2012 01:31
-
-
Save elg0nz/1667173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery.task import task | |
from coreApi import models as caModels | |
from django.db.models import Sum | |
from settings import DEBUG | |
import tablib | |
import datetime | |
import json | |
DEFAULT_ESTABLISHMENT_SETTING_OPTIONS = [ | |
'print_courses', | |
'print_fine_dining', | |
'prompt_for_seat', | |
'open_drawer_cc', | |
'capture_on_swipe', | |
'lock_table', | |
'kiosk_add_via_thumbnail', | |
'prompt_for_seat', | |
'kiosk_cash_option', | |
'group_print', | |
'keyboard_raise', | |
'password_extra_item', | |
'cash_drawer_password', | |
'multi_cc', | |
'kiosk_email_collect', | |
'valuetec', | |
'mandatory_tip', | |
'mandatory_tip_percentage', | |
'prompt_ticket_name', | |
'kitchen_network_key', | |
] | |
DEFAULT_ESTABLISHMENT_SETTING_OPTIONS_WITH_PARAMS = [ | |
{'name':'auto_logout', 'parameter_name':'auto_logout_time'}, | |
{'name':'use_call_number', 'parameter_name':'call_number_reset'}, | |
{'name':'week_start_day', 'parameter_name':'day_of_weekstart'}, | |
] | |
# pylint: disable=E1101 | |
@task | |
def initialize_establishment_settings(establishment_id, **kwargs): | |
""" | |
Initializes the establishment settings, by creating the necessary | |
system options and associating them to an establishment. | |
""" | |
establishment = caModels.Establishment.objects.get(id=establishment_id) | |
establishment_parent_setting = establishment.settings | |
for setting_option in DEFAULT_ESTABLISHMENT_SETTING_OPTIONS: | |
name = setting_option | |
user_friendly_name = name.replace('_', ' ') | |
caModels.SystemSettingOption.objects.get_or_create( | |
settings_parent=establishment_parent_setting, | |
setting_name=name, | |
defaults={ | |
'user_friendly_name': user_friendly_name, | |
'description': user_friendly_name, | |
'parameter_required': False, | |
'enabled': True | |
} | |
) | |
for parm_setting_opt in DEFAULT_ESTABLISHMENT_SETTING_OPTIONS_WITH_PARAMS: | |
name = parm_setting_opt['name'] | |
user_friendly_name = name.replace('_', ' ') | |
caModels.SystemSettingOption.objects.get_or_create( | |
settings_parent=establishment_parent_setting, | |
setting_name=name, | |
defaults={ | |
'user_friendly_name': user_friendly_name, | |
'description': user_friendly_name, | |
'parameter_required': True, | |
'parameter_name': parm_setting_opt['parameter_name'], | |
'enabled': True | |
} | |
) | |
@task | |
def clean_stray_system_settings(): | |
stray_system_settings = caModels.SystemSetting.objects.filter( | |
establishment=None) | |
for system_setting in stray_system_settings: | |
system_setting.delete() | |
# pylint: enable=E1101 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment