예제 #1
0
def create(request):
    if request.method == 'POST':
        form = ReminderForm(request.POST)
        if form.is_valid():
            new_reminder = form.save(commit=False)
            new_reminder.user = request.user
            new_reminder.save()
            return HttpResponseRedirect("/dashboard")
    else:
        form = ReminderForm()

    return render_to_response("create.html", locals(), context_instance=RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: lig/picket_classic
def remind(request, bug):
    
    if request.method == 'POST':
        reminderForm = ReminderForm(request.POST, user=request.user)
        if reminderForm.is_valid():
            reminder_text = reminderForm.cleaned_data['text']
            reminder_recipients = reminderForm.cleaned_data['recipients']
            """ save note """
            bugnote = Bugnote(bug=bug, reporter=request.user,
                text='Reminder to %s: %s' %
                    (', '.join(map(str, reminder_recipients)), reminder_text),
                scope=reminderForm.cleaned_data['scope'])
            bugnote.save()
            """ send reminder """
            send_alerts(bug, reminder_recipients, reminder_text)
            request.user.message_set.create(message=_('Reminder(s) sent'))
            return HttpResponseRedirect(bug.get_absolute_url())
    else:
        reminderForm = ReminderForm(user=request.user)
    
    return direct_to_template(request, 'picket/reminder.html',
        {'bug': bug, 'reminder_form': reminderForm,})
예제 #3
0
def index():

    form = ReminderForm(request.form)
    if request.method == 'POST' and form.validate():
        with open('db.bin', 'wb') as f:

            # getting timezone with phone number
            raw_phone_number = request.form['phone']
            phone_number = phonenumbers.parse(raw_phone_number)
            time_zone = ptz.time_zones_for_number(phone_number)[0]

            pickle.dump(
                {
                    'phone': request.form['phone'],
                    'message': request.form['message'],
                    'timestamp': datetime.now(),
                    'time_zone': time_zone
                }, f)

        _time_zone = timezone(time_zone)
        time_zone_time = datetime.now(_time_zone)

        # timezone helps determining the night hours of user's country
        scheduler = BackgroundScheduler()
        scheduler.add_job(send_message,
                          'cron',
                          hour='7-23',
                          second=time_zone_time.second,
                          minute=time_zone_time.minute,
                          id="sms_job_id",
                          timezone=time_zone)
        # the above cronjob will run forever every hour from the time it called
        scheduler.start()
        # Shut down the scheduler when exiting the app
        atexit.register(lambda: scheduler.shutdown(wait=False))
        return redirect('/info')
    return render_template('home.html', form=form)