<commit_before>from datetime import timedelta, datetime, time
import json
from couchdbkit import ResourceNotFound
from django.contrib import messages
from django.db import transaction
from django.utils.decorators import method_decorator
import pytz
from django.urls import reverse
from django.http import HttpResponseRedirect, Http404, HttpResponse
from corehq.apps.app_manager.dbaccessors import get_apps_in_domain
from corehq.apps.style.decorators import use_datatables, use_jquery_ui, \
    use_timepicker, use_select2
from corehq.apps.translations.models import StandaloneTranslationDoc
from corehq.const import SERVER_DATETIME_FORMAT
from corehq.util.timezones.conversions import ServerTime
from dimagi.utils.couch.cache.cache_core import get_redis_client
from django.utils.translation import ugettext as _, ugettext_noop, ugettext_lazy
from corehq import privileges
from corehq.apps.accounting.decorators import requires_privilege_with_fallback
from corehq.apps.app_manager.models import Form
from corehq.apps.app_manager.util import get_case_properties
from corehq.apps.hqwebapp.views import (CRUDPaginatedViewMixin,
    DataTablesAJAXPaginationMixin)
from corehq import toggles
from dimagi.utils.logging import notify_exception

from corehq.apps.reminders.forms import (
    BroadcastForm,
    SimpleScheduleCaseReminderForm,
    CaseReminderEventForm,
    CaseReminderEventMessageForm,
    ComplexScheduleCaseReminderForm,
    KeywordForm,
    NO_RESPONSE,
)
from corehq.apps.reminders.models import (
    CaseReminderHandler,
    CaseReminderEvent,
    EVENT_AS_OFFSET,
    ON_DATETIME,
    REMINDER_TYPE_ONE_TIME,
    REMINDER_TYPE_DEFAULT,
    SEND_LATER,
    METHOD_SMS_SURVEY,
    METHOD_STRUCTURED_SMS,
    RECIPIENT_SENDER,
    METHOD_IVR_SURVEY,
)
from corehq.apps.sms.models import Keyword, KeywordAction
from corehq.apps.sms.views import BaseMessagingSectionView
from corehq.apps.users.decorators import require_permission
from corehq.apps.users.models import Permissions
from dimagi.utils.decorators.memoized import memoized
from .models import UI_SIMPLE_FIXED, UI_COMPLEX
from .util import can_use_survey_reminders, get_form_list, get_form_name, get_recipient_name
from corehq.apps.domain.models import Domain
from corehq.util.timezones.utils import get_timezone_for_user
from custom.ewsghana.forms import EWSBroadcastForm

ACTION_ACTIVATE = 'activate'
ACTION_DEACTIVATE = 'deactivate'
ACTION_DELETE = 'delete'

reminders_framework_permission = lambda *args, **kwargs: (
    require_permission(Permissions.edit_data)(
        requires_privilege_with_fallback(privileges.REMINDERS_FRAMEWORK)(*args, **kwargs)
    )
)

survey_reminders_permission = lambda *args, **kwargs: (
    require_permission(Permissions.edit_data)(
        requires_privilege_with_fallback(privileges.INBOUND_SMS)(*args, **kwargs)
    )
)


def get_project_time_info(domain):
    timezone = get_timezone_for_user(None, domain)
    now = pytz.utc.localize(datetime.utcnow())
    timezone_now = now.astimezone(timezone)
    return (timezone, now, timezone_now)


class ScheduledRemindersCalendarView(BaseMessagingSectionView):
    urlname = 'scheduled_reminders'
    page_title = ugettext_noop("Reminder Calendar")
    template_name = 'reminders/partial/scheduled_reminders.html'

    @method_decorator(requires_privilege_with_fallback(privileges.OUTBOUND_SMS))
    @method_decorator(reminders_framework_permission)
    def dispatch(self, *args, **kwargs):
        return super(BaseMessagingSectionView, self).dispatch(*args, **kwargs)

    @property
    def page_context(self):
        page_context = super(ScheduledRemindersCalendarView, self).page_context
        timezone = Domain.get_by_name(self.domain).get_default_timezone()
        reminders = CaseReminderHandler.get_all_reminders(self.domain)
        dates = []
        now = datetime.utcnow()
        timezone_now = datetime.now(timezone)
        today = timezone_now.date()

        def adjust_next_fire_to_timezone(reminder_utc):
            return ServerTime(reminder_utc.next_fire).user_time(timezone).done()

        if reminders:
            start_date = adjust_next_fire_to_timezone(reminders[0]).date()
            if today < start_date:
                start_date = today
            end_date = adjust_next_fire_to_timezone(reminders[-1]).date()
        else:
            start_date = end_date = today
        # make sure start date is a Monday and enddate is a Sunday
        start_date -= timedelta(days=start_date.weekday())
        end_date += timedelta(days=6 - end_date.weekday())
        while start_date <= end_date:
            dates.append(start_date)
            start_date += timedelta(days=1)
<commit_msg>Make datetime naive<commit_after>from datetime import timedelta, datetime, time
import json
from couchdbkit import ResourceNotFound
from django.contrib import messages
from django.db import transaction
from django.utils.decorators import method_decorator
import pytz
from django.urls import reverse
from django.http import HttpResponseRedirect, Http404, HttpResponse
from corehq.apps.app_manager.dbaccessors import get_apps_in_domain
from corehq.apps.style.decorators import use_datatables, use_jquery_ui, \
    use_timepicker, use_select2
from corehq.apps.translations.models import StandaloneTranslationDoc
from corehq.const import SERVER_DATETIME_FORMAT
from corehq.util.timezones.conversions import ServerTime
from dimagi.utils.couch.cache.cache_core import get_redis_client
from django.utils.translation import ugettext as _, ugettext_noop, ugettext_lazy
from corehq import privileges
from corehq.apps.accounting.decorators import requires_privilege_with_fallback
from corehq.apps.app_manager.models import Form
from corehq.apps.app_manager.util import get_case_properties
from corehq.apps.hqwebapp.views import (CRUDPaginatedViewMixin,
    DataTablesAJAXPaginationMixin)
from corehq import toggles
from dimagi.utils.logging import notify_exception

from corehq.apps.reminders.forms import (
    BroadcastForm,
    SimpleScheduleCaseReminderForm,
    CaseReminderEventForm,
    CaseReminderEventMessageForm,
    ComplexScheduleCaseReminderForm,
    KeywordForm,
    NO_RESPONSE,
)
from corehq.apps.reminders.models import (
    CaseReminderHandler,
    CaseReminderEvent,
    EVENT_AS_OFFSET,
    ON_DATETIME,
    REMINDER_TYPE_ONE_TIME,
    REMINDER_TYPE_DEFAULT,
    SEND_LATER,
    METHOD_SMS_SURVEY,
    METHOD_STRUCTURED_SMS,
    RECIPIENT_SENDER,
    METHOD_IVR_SURVEY,
)
from corehq.apps.sms.models import Keyword, KeywordAction
from corehq.apps.sms.views import BaseMessagingSectionView
from corehq.apps.users.decorators import require_permission
from corehq.apps.users.models import Permissions
from dimagi.utils.decorators.memoized import memoized
from .models import UI_SIMPLE_FIXED, UI_COMPLEX
from .util import can_use_survey_reminders, get_form_list, get_form_name, get_recipient_name
from corehq.apps.domain.models import Domain
from corehq.util.timezones.utils import get_timezone_for_user
from custom.ewsghana.forms import EWSBroadcastForm

ACTION_ACTIVATE = 'activate'
ACTION_DEACTIVATE = 'deactivate'
ACTION_DELETE = 'delete'

reminders_framework_permission = lambda *args, **kwargs: (
    require_permission(Permissions.edit_data)(
        requires_privilege_with_fallback(privileges.REMINDERS_FRAMEWORK)(*args, **kwargs)
    )
)

survey_reminders_permission = lambda *args, **kwargs: (
    require_permission(Permissions.edit_data)(
        requires_privilege_with_fallback(privileges.INBOUND_SMS)(*args, **kwargs)
    )
)


def get_project_time_info(domain):
    timezone = get_timezone_for_user(None, domain)
    now = pytz.utc.localize(datetime.utcnow())
    timezone_now = now.astimezone(timezone)
    return (timezone, now, timezone_now)


class ScheduledRemindersCalendarView(BaseMessagingSectionView):
    urlname = 'scheduled_reminders'
    page_title = ugettext_noop("Reminder Calendar")
    template_name = 'reminders/partial/scheduled_reminders.html'

    @method_decorator(requires_privilege_with_fallback(privileges.OUTBOUND_SMS))
    @method_decorator(reminders_framework_permission)
    def dispatch(self, *args, **kwargs):
        return super(BaseMessagingSectionView, self).dispatch(*args, **kwargs)

    @property
    def page_context(self):
        page_context = super(ScheduledRemindersCalendarView, self).page_context
        timezone = Domain.get_by_name(self.domain).get_default_timezone()
        reminders = CaseReminderHandler.get_all_reminders(self.domain)
        dates = []
        now = datetime.utcnow()
        timezone_now = datetime.now(timezone)
        today = timezone_now.date()

        def adjust_next_fire_to_timezone(reminder_utc):
            return ServerTime(reminder_utc.next_fire).user_time(timezone).done().replace(tzinfo=None)

        if reminders:
            start_date = adjust_next_fire_to_timezone(reminders[0]).date()
            if today < start_date:
                start_date = today
            end_date = adjust_next_fire_to_timezone(reminders[-1]).date()
        else:
            start_date = end_date = today
        # make sure start date is a Monday and enddate is a Sunday
        start_date -= timedelta(days=start_date.weekday())
        end_date += timedelta(days=6 - end_date.weekday())
        while start_date <= end_date:
            dates.append(start_date)
            start_date += timedelta(days=1)

{'fraction_non_alphanumeric': 0.07181672882258924, 'fraction_numerical': 0.0017048481619605753, 'mean_word_length': 4.7231707317073175, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1856843', 'n_tokens_mistral': 3029, 'n_tokens_neox': 2969, 'n_words': 560}