Beispiel #1
0
def countries():
    '''
    get country dictionar from pytz and add some extra.
    '''
    global _countries
    if not _countries:
        v = {}
        _countries = v
        try:
            from pytz import country_names
            for k, n in country_names.items():
                v[k.upper()] = n
        except:
            pass
    return _countries
Beispiel #2
0
def countries():
    '''
    get country dictionar from pytz and add some extra.
    '''
    global _countries
    if not _countries:
        v = {}
        _countries = v
        try:
            from pytz import country_names
            for k, n in country_names.items():
                v[k.upper()] = n
        except Exception:
            pass
    return _countries
Beispiel #3
0
    def fields(self):
        # Since @property is readonly we can't modify field values in display() method
        # Returns fields modified by display()
        if self._fields:
            return self._fields

        list_of_fields = [
            ew.SingleSelectField(
                name='sex',
                label='Gender',
                options=[
                    ew.Option(py_value=v, label=v, selected=False)
                    for v in ['Male', 'Female', 'Unknown', 'Other']
                ],
                validator=formencode.All(
                    V.OneOfValidator(['Male', 'Female', 'Unknown', 'Other']),
                    fev.UnicodeString(not_empty=True))),
            ew.SingleSelectField(
                name='country',
                label='Country of residence',
                validator=V.MapValidator(country_names, not_empty=False),
                options=[
                    ew.Option(
                        py_value=" ", label=" -- Unknown -- ", selected=False)
                ] + [
                    ew.Option(py_value=c, label=n, selected=False)
                    for c, n in sorted(country_names.items(),
                                       key=lambda (k, v): v)
                ],
                attrs={'onchange': 'selectTimezone(this.value)'}),
            ew.TextField(name='city',
                         label='City of residence',
                         attrs=dict(value=None),
                         validator=fev.UnicodeString(not_empty=False)),
            ew.SingleSelectField(
                name='timezone',
                label='Timezone',
                attrs={'id': 'tz'},
                validator=V.OneOfValidator(common_timezones, not_empty=False),
                options=[ew.Option(py_value=" ", label=" -- Unknown -- ")] + [
                    ew.Option(py_value=n, label=n)
                    for n in sorted(common_timezones)
                ])
        ]
        if asbool(tg.config.get('auth.allow_birth_date', True)):
            list_of_fields[1:1] = self.birth_date_fields

        return list_of_fields
Beispiel #4
0
    def fields(self):
        # Since @property is readonly we can't modify field values in display() method
        # Returns fields modified by display()
        if self._fields:
            return self._fields

        list_of_fields = [
            ew.SingleSelectField(
                name='sex',
                label='Gender',
                options=[ew.Option(py_value=v, label=v, selected=False)
                         for v in ['Male', 'Female', 'Unknown', 'Other']],
                validator=formencode.All(
                    V.OneOfValidator(['Male', 'Female', 'Unknown', 'Other']),
                    fev.UnicodeString(not_empty=True))),
            ew.SingleSelectField(
                name='country',
                label='Country of residence',
                validator=V.MapValidator(country_names, not_empty=False),
                options=[ew.Option(py_value=" ", label=" -- Unknown -- ", selected=False)] +
                        [ew.Option(py_value=c, label=n, selected=False)
                         for c, n in sorted(country_names.items(),
                                            key=lambda (k, v): v)],
                attrs={'onchange': 'selectTimezone(this.value)'}),
            ew.TextField(
                name='city',
                label='City of residence',
                attrs=dict(value=None),
                validator=fev.UnicodeString(not_empty=False)),
            ew.SingleSelectField(
                name='timezone',
                label='Timezone',
                attrs={'id': 'tz'},
                validator=V.OneOfValidator(common_timezones, not_empty=False),
                options=[ew.Option(py_value=" ", label=" -- Unknown -- ")] +
                        [ew.Option(py_value=n, label=n)
                         for n in sorted(common_timezones)])
        ]
        if asbool(tg.config.get('auth.allow_birth_date', True)):
            list_of_fields[1:1] = self.birth_date_fields

        return list_of_fields
Beispiel #5
0
 class fields(ew_core.NameList):
     sex = ew.SingleSelectField(
         label='Gender',
         options=[
             ew.Option(py_value=v, label=v, selected=False)
             for v in ['Male', 'Female', 'Unknown', 'Other']
         ],
         validator=formencode.All(
             V.OneOfValidator(['Male', 'Female', 'Unknown', 'Other']),
             fev.UnicodeString(not_empty=True)))
     birthdate = ew.TextField(label='Birth date',
                              validator=V.DateValidator(),
                              attrs=dict(value=None))
     exp = _HTMLExplanation(text="Use the format DD/MM/YYYY",
                            show_errors=False)
     country = ew.SingleSelectField(
         label='Country of residence',
         validator=V.MapValidator(country_names, not_empty=False),
         options = [
             ew.Option(
                 py_value=" ", label=" -- Unknown -- ", selected=False)] +\
             [ew.Option(py_value=c, label=n, selected=False)
              for c,n in sorted(country_names.items(),
                                key=lambda (k,v):v)],
         attrs={'onchange':'selectTimezone(this.value)'})
     city = ew.TextField(label='City of residence',
                         attrs=dict(value=None),
                         validator=fev.UnicodeString(not_empty=False))
     timezone=ew.SingleSelectField(
         label='Timezone',
         attrs={'id':'tz'},
         validator=V.OneOfValidator(common_timezones, not_empty=False),
         options=[
              ew.Option(
                  py_value=" ",
                  label=" -- Unknown -- ")] + \
              [ew.Option(py_value=n, label=n)
               for n in sorted(common_timezones)])
Beispiel #6
0
class Address(models.Model):
    """
    Address
    """

    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    customer = models.ForeignKey(Account,
                                 verbose_name=_("Account"),
                                 on_delete=models.CASCADE)
    full_name = models.CharField(_("Full Name"), max_length=25)
    phone = models.CharField(_("Phone Number"), max_length=20)
    postcode = models.CharField(_("Postal Code"), max_length=10)
    address_line = models.CharField(_("Address Line 1"), max_length=50)
    address_line2 = models.CharField(_("Address Line 2"),
                                     max_length=50,
                                     blank=True)
    town_city = models.CharField(_("Town/City"), max_length=50)
    state_province = models.CharField(_("State/Province"),
                                      max_length=10,
                                      blank=True)
    country = models.CharField(_("Country"),
                               max_length=2,
                               default="US",
                               choices=country_names.items())
    delivery_instructions = models.CharField(_("Delivery Instructions"),
                                             max_length=255,
                                             blank=True)
    created_at = models.DateTimeField(_("Created at"), auto_now_add=True)
    updated_at = models.DateTimeField(_("Updated at"), auto_now=True)
    default = models.BooleanField(_("Default"), default=False)

    class Meta:
        verbose_name = "Address"
        verbose_name_plural = "Addresses"

    def __str__(self):
        return "{} Address".format(self.full_name)
Beispiel #7
0
def find_timezone_name(tz_name):
    """
    Return list of matching timezones by name, country code, or country name.
    Search is case insensitive.
    """
    from pytz import all_timezones_set, country_timezones, country_names
    if tz_name in all_timezones_set:
        return [tz_name]
    # Case insensitive matching:
    tz_name = tz_name.upper()
    timzones = {tz.upper(): tz for tz in all_timezones_set}
    if tz_name in timzones:
        return [timzones[tz_name]]
    # Select by country code:
    if tz_name in country_timezones:
        return country_timezones[tz_name]
    # Select by country name:
    country_codes = {
        name.upper(): code
        for code, name in country_names.items()
    }
    if tz_name in country_codes:
        return country_timezones[country_codes[tz_name]]
    return []
Beispiel #8
0

from nimbus.shared import signals
from nimbus.libs import systemprocesses
from nimbus.shared.fields import check_domain
from nimbus.base.models import UUIDSingletonModel as BaseModel



NTP_CHECK_SERVER = [ "/usr/sbin/ntpdate", "-q" ]

EMPTY_CHOICES = [('', '----------')]

COUNTRY_CHOICES = [ item \
                    for item in \
                    sorted(country_names.items(), key=itemgetter(1)) ]


NTP_SERVERS = [
    "a.ntp.br",
    "b.ntp.br",
    "c.ntp.br",
    "d.ntp.br",
    "pool.ntp.br",
    "pool.ntp.org"
]




class Timezone(BaseModel):
Beispiel #9
0
ACCOUNT_ID = 'account_id'
ACTIVE = 'active'
SHOWN_IN = 'shown_in'

LAT = 'lat'
LON = 'lon'
LATITUDE = 'latitude'
ADMIN_PHONE = 'admin_phone'
ADMIN_EMAIL = 'admin_email'
LONGITUDE = 'longitude'
COUNTRY = 'country'
STREET = 'street'
CITY = 'city'
ADDRESS = 'address'
STATE = 'state'
COUNTRIES_CHOICES: dict = country_names.items()

STATUS = 'status'

DEFAULT = 'default'

AUTHORIZATION = 'Authorization'
FILE = 'file'
TIME_STAMP = 'read_time_local'
ACCESS_TOKEN = 'access_token'
DP = 'DP'
ZOURA = 'ZOURA'
TELEMETRIES = 'telemetries'
DEVICES = 'devices'
SITES = 'sites'
ACCOUNTS = 'accounts'
Beispiel #10
0
from django.db.models.signals import post_save
from django.conf import settings
from django.core.exceptions import ValidationError

from nimbus.shared import signals
from nimbus.libs import systemprocesses
from nimbus.shared.fields import check_domain
from nimbus.base.models import UUIDSingletonModel as BaseModel

NTP_CHECK_SERVER = ["/usr/sbin/ntpdate", "-q"]

EMPTY_CHOICES = [('', '----------')]

COUNTRY_CHOICES = [ item \
                    for item in \
                    sorted(country_names.items(), key=itemgetter(1)) ]

NTP_SERVERS = [
    "a.ntp.br", "b.ntp.br", "c.ntp.br", "d.ntp.br", "pool.ntp.br",
    "pool.ntp.org"
]


class Timezone(BaseModel):
    ntp_server = models.CharField('Servidor ntp',
                                  max_length=255,
                                  blank=False,
                                  null=False,
                                  default="pool.ntp.br",
                                  validators=[check_domain])
    country = models.CharField('País',
Beispiel #11
0
#just check in

from datetime import datetime, date, timedelta, timezone
from pytz import timezone, country_timezones, country_names

country_codes = {country: code for code, country in country_names.items()}

task_type = input('Enter task:')
country = input('Enter country:')
email_start_time = '19:00:00'
email_end_time = '21:00:00'
call_start_time = '13:00:00'
call_end_time = '14:30:00'
sms_start_time = '10:00:00'
sms_end_time = '17:00:00'

if task_type == 'email' and country == 'India':
    start_time = email_start_time
    end_time = email_end_time

elif task_type == 'call' and country == 'India':
    start_time = call_start_time
    end_time = call_end_time
elif task_type == 'sms' and country == 'India':
    start_time = sms_start_time
    end_time = sms_end_time
elif task_type == 'call' and country == 'United States':
    start_time = call_start_time
    end_time = call_end_time
elif task_type == 'email' and country == 'United States':
    start_time = email_start_time
Beispiel #12
0
from django.db.models.signals import post_save
from django.conf import settings
from django.core.exceptions import ValidationError


from nimbus.shared import signals
from nimbus.libs import systemprocesses
from nimbus.shared.fields import check_domain
from nimbus.base.models import UUIDSingletonModel as BaseModel


NTP_CHECK_SERVER = ["/usr/sbin/ntpdate", "-q"]

EMPTY_CHOICES = [("", "----------")]

COUNTRY_CHOICES = [item for item in sorted(country_names.items(), key=itemgetter(1))]


NTP_SERVERS = ["a.ntp.br", "b.ntp.br", "c.ntp.br", "d.ntp.br", "pool.ntp.br", "pool.ntp.org"]


class Timezone(BaseModel):
    ntp_server = models.CharField(
        "Servidor ntp", max_length=255, blank=False, null=False, default="pool.ntp.br", validators=[check_domain]
    )
    country = models.CharField("País", max_length=255, blank=False, choices=COUNTRY_CHOICES)
    area = models.CharField("Região", max_length=255, blank=False, null=False)

    def clean(self):

        if self.ntp_server in NTP_SERVERS: