本文整理汇总了Python中anaf.core.models.ModuleSetting.get方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleSetting.get方法的具体用法?Python ModuleSetting.get怎么用?Python ModuleSetting.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anaf.core.models.ModuleSetting
的用法示例。
在下文中一共展示了ModuleSetting.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: htdate
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get [as 别名]
def htdate(context, date, dateformat="DATE_FORMAT"):
""" Render date in the current locale
To render date in a custom format use Django format, details:
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
"""
if not date:
return ""
lang = translation.get_language()
localeformat = dateformat
formatspath = getattr(settings, "FORMAT_MODULE_PATH", "anaf.formats")
try:
modulepath = formatspath + "." + lang + ".formats"
module = __import__(modulepath, fromlist=[str(modulepath)])
localeformat = getattr(module, dateformat, dateformat)
except ImportError:
pass
request = context["request"]
user = None
if request.user.username:
try:
user = request.user.profile
except Exception:
pass
# timezone
default_timezone = settings.ANAF_SERVER_DEFAULT_TIMEZONE
try:
conf = ModuleSetting.get("default_timezone")[0]
default_timezone = conf.value
except:
pass
try:
conf = ModuleSetting.get("default_timezone", user=user)[0]
default_timezone = conf.value
except Exception:
default_timezone = settings.ANAF_SERVER_TIMEZONE[default_timezone][0]
all_timezones = settings.ANAF_SERVER_TIMEZONE
title = all_timezones[int(default_timezone)][1]
GMT = title[4:10] # with sign e.g. +06:00
sign = GMT[0:1] # + or -
hours = int(GMT[1:3]) # e.g. 06
mins = int(GMT[4:6])
if sign == "-":
date = date - timedelta(hours=hours, minutes=mins)
else:
date = date + timedelta(hours=hours, minutes=mins)
result = djangodate(date, localeformat)
return Markup(result)
示例2: htform
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get [as 别名]
def htform(context, form):
"Set time zone"
request = context["request"]
user = None
if request.user.username:
try:
user = request.user.profile
except Exception:
pass
# timezone
default_timezone = settings.ANAF_SERVER_DEFAULT_TIMEZONE
try:
conf = ModuleSetting.get("default_timezone")[0]
default_timezone = conf.value
except:
pass
try:
conf = ModuleSetting.get("default_timezone", user=user)[0]
default_timezone = conf.value
except Exception:
default_timezone = settings.ANAF_SERVER_TIMEZONE[default_timezone][0]
all_timezones = settings.ANAF_SERVER_TIMEZONE
title = all_timezones[int(default_timezone)][1]
GMT = title[4:10] # with sign e.g. +06:00
sign = GMT[0:1] # + or -
hours = int(GMT[1:3]) # e.g. 06
mins = int(GMT[4:6])
if not form.errors:
for field in form:
try:
date = datetime.strptime(str(field.form.initial[field.name]), "%Y-%m-%d %H:%M:%S")
if date:
if sign == "-":
field.form.initial[field.name] = date - timedelta(hours=hours, minutes=mins)
else:
field.form.initial[field.name] = date + timedelta(hours=hours, minutes=mins)
except:
pass
return form
示例3: sync
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get [as 别名]
def sync(user=None):
if user:
conf = ModuleSetting.get('nuvius_profile', user=user, strict=True)
else:
conf = ModuleSetting.get('nuvius_profile')
for item in conf:
profile = item.loads()
user = item.user
if user:
connector = Connector(profile_id=profile['id'])
active_resources = ModuleSetting.get_for_module(
'anaf.identities', 'integration_resource', user=user, strict=True)
for resource in active_resources:
res = resource.loads()
response = connector.get(
'/service/contact-book/contact/data.json/id' + profile['id'] + '/app' + str(res.resource_id))
data = DataBlock(response['data'])
if data.result_name == 'success':
_do_sync(data, user)
示例4: process_timezone_field
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get [as 别名]
def process_timezone_field(user, instance):
"Processes date and datetime fields according to the selected time zone"
from datetime import date, datetime, timedelta
default_timezone = settings.ANAF_SERVER_DEFAULT_TIMEZONE
try:
conf = ModuleSetting.get('default_timezone')[0]
default_timezone = conf.value
except Exception:
pass
try:
conf = ModuleSetting.get('default_timezone', user=user)[0]
default_timezone = conf.value
except Exception:
default_timezone = settings.ANAF_SERVER_TIMEZONE[default_timezone][0]
all_timezones = settings.ANAF_SERVER_TIMEZONE
title = all_timezones[int(default_timezone)][1]
GMT = title[4:10] # with sign e.g. +06:00
sign = GMT[0:1] # + or -
hours = int(GMT[1:3]) # e.g. 06
mins = int(GMT[4:6])
for field in instance.get_fields():
if field.name not in settings.ANAF_TIMEZONE_BLACKLIST:
if (isinstance(field, models.DateTimeField) or isinstance(field, models.DateField)) and \
getattr(instance, field.name):
cur_date = getattr(instance, field.name)
if sign == "-":
new_date = cur_date + \
timedelta(hours=hours, minutes=mins)
else:
new_date = cur_date - \
timedelta(hours=hours, minutes=mins)
setattr(instance, field.name, new_date)
elif isinstance(field, models.TimeField) and getattr(instance, field.name):
datetime.combine(date.today(), getattr(instance, field.name)) + timedelta(hours=hours, minutes=mins)
示例5: process_request
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get [as 别名]
def process_request(self, request):
"Set language for the current user"
lang = settings.ANAF_LANGUAGES_DEFAULT
if request.user.username:
try:
user = request.user.profile
conf = ModuleSetting.get('language', user=user)[0]
lang = conf.value
except IndexError:
pass
except AttributeError:
pass
else:
try:
conf = ModuleSetting.get(
'language', user__isnull=True, strict=True)[0]
lang = conf.value
except IndexError:
pass
lang = to_language(lang)
request.session['django_language'] = lang
示例6: humanize_datetime
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get [as 别名]
def humanize_datetime(context, value):
"""
Finds the difference between the datetime value given and now()
and returns appropriate humanize form
"""
request = context["request"]
user = None
if request.user.username:
try:
user = request.user.profile
except:
pass
# timezone
default_timezone = settings.ANAF_SERVER_DEFAULT_TIMEZONE
try:
conf = ModuleSetting.get("default_timezone")[0]
default_timezone = conf.value
except:
pass
try:
conf = ModuleSetting.get("default_timezone", user=user)[0]
default_timezone = conf.value
except Exception:
default_timezone = settings.ANAF_SERVER_TIMEZONE[default_timezone][0]
all_timezones = settings.ANAF_SERVER_TIMEZONE
title = all_timezones[int(default_timezone)][1]
GMT = title[4:10] # with sign e.g. +06:00
sign = GMT[0:1] # + or -
hours = int(GMT[1:3]) # e.g. 06
mins = int(GMT[4:6])
now = datetime.now()
if value:
if sign == "-":
value = value - timedelta(hours=hours, minutes=mins)
now = now - timedelta(hours=hours, minutes=mins)
else:
value = value + timedelta(hours=hours, minutes=mins)
now = now + timedelta(hours=hours, minutes=mins)
if isinstance(value, timedelta):
delta = value
elif isinstance(value, datetime):
delta = now - value
else:
delta = None
if delta:
if delta.days > 6: # May 15, 17:55
month = None
if value.strftime("%b") == "Jan":
month = _("Jan")
elif value.strftime("%b") == "Feb":
month = _("Feb")
elif value.strftime("%b") == "Mar":
month = _("Mar")
elif value.strftime("%b") == "Apr":
month = _("Apr")
elif value.strftime("%b") == "May":
month = _("May")
elif value.strftime("%b") == "Jun":
month = _("Jun")
elif value.strftime("%b") == "Jul":
month = _("Jul")
elif value.strftime("%b") == "Aug":
month = _("Aug")
elif value.strftime("%b") == "Sep":
month = _("Sep")
elif value.strftime("%b") == "Oct":
month = _("Oct")
elif value.strftime("%b") == "Nov":
month = _("Nov")
elif value.strftime("%b") == "Dec":
month = _("Dec")
return month + value.strftime(" %d, %H:%M")
if delta.days > 1: # Wednesday
if value.strftime("%A") == "Monday":
return _("Monday")
elif value.strftime("%A") == "Tuesday":
return _("Tuesday")
elif value.strftime("%A") == "Wednesday":
return _("Wednesday")
elif value.strftime("%A") == "Thursday":
return _("Thursday")
elif value.strftime("%A") == "Friday":
return _("Friday")
elif value.strftime("%A") == "Saturday":
return _("Saturday")
elif value.strftime("%A") == "Sunday":
return _("Sunday")
elif delta.days == 1:
return _("yesterday") # yesterday
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: from anaf.core.models import ModuleSetting [as 别名]
# 或者: from anaf.core.models.ModuleSetting import get [as 别名]
def __init__(self, user, *args, **kwargs):
"Sets choices and initial value"
super(SettingsForm, self).__init__(*args, **kwargs)
self.fields['default_perspective'].label = _("Default Perspective")
self.fields['language'].label = _("Language")
self.fields['default_timezone'].label = _("Time Zone")
self.fields['email_notifications'].label = _("E-mail Notifications")
self.user = user
self.fields['default_perspective'].queryset = Object.filter_permitted(
user, Perspective.objects)
try:
conf = ModuleSetting.get_for_module(
'anaf.core', 'default_perspective', user=self.user)[0]
default_perspective = Perspective.objects.get(pk=long(conf.value))
self.fields['default_perspective'].initial = default_perspective.id
except:
pass
self.fields['default_timezone'].choices = settings.ANAF_SERVER_TIMEZONE
timezone = settings.ANAF_SERVER_DEFAULT_TIMEZONE
try:
conf = ModuleSetting.get('default_timezone', user=user)[0]
timezone = conf.value
except:
pass
self.fields['default_timezone'].initial = timezone
self.fields['language'].choices = settings.ANAF_LANGUAGES
language = settings.ANAF_LANGUAGES_DEFAULT
try:
conf = ModuleSetting.get('language', user=user)[0]
language = conf.value
except IndexError:
pass
self.fields['language'].initial = language
try:
conf = ModuleSetting.get('email_notifications', user=user)[0]
self.fields['email_notifications'].initial = conf.value
except:
self.fields[
'email_notifications'].initial = settings.ANAF_ALLOW_EMAIL_NOTIFICATIONS
perspective = user.get_perspective()
modules = perspective.modules.filter(display=True).order_by('title')
if not modules:
modules = Module.objects.filter(display=True).order_by('title')
self.fields['notifications_for_modules'].choices = [
(module.pk, module.title) for module in modules]
try:
modules = NotificationSetting.objects.get(
owner=self.user).modules.all()
self.fields['notifications_for_modules'].initial = [
m.pk for m in modules]
except (NotificationSetting.DoesNotExist, NotificationSetting.MultipleObjectsReturned):
pass