def clientCheckin(request, client_id): if not request.user.is_authenticated(): return HttpResponseRedirect("/") theClient = Client.objects.filter(pk=client_id) if len(theClient) == 1: theClient = theClient[0] else: return HttpResponseRedirect("/") if request.method == 'POST': # If the form has been submitted... form = CheckInForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data recordTypeId = form.cleaned_data['checkInType'] theRecordType = RecordType.objects.filter(id=recordTypeId) if len(theRecordType)==1: theRecordType = theRecordType[0] theTeams = Team.objects.filter(members=theClient).filter(active=True) aRecord = Record() aRecord.name = theRecordType.name aRecord.points = theRecordType.points aRecord.date = datetime.datetime.utcnow().replace(tzinfo=utc) aRecord.completedBy = theClient aRecord.submittedBy = request.user aRecord.save() for aTeam in theTeams: aRecord.teams.add(aTeam) return HttpResponseRedirect('/clients/') # Redirect after POST else: form = CheckInForm() # An unbound form context = { 'form': form, 'client': theClient, } return render(request, 'checkInClient.html', context)
def keyword_react(goobo, sender, recipient, message): """ react upon listened any keywords in LISTEN_KEYWORDS """ for keyword in settings.AUTO_RECORD_KEYWORDS: if keyword in message: record = Record() record.keyword = keyword record.sender = sender record.recipient = recipient record.message = message record.save() for keyword in settings.LISTEN_KEYWORDS: if keyword in message: goobo.say(recipient, "Command List: {}help". format(settings.COMMAND_PREFIX)) def get_min_diff(dt_1, dt_2): """get the minute difference from (dt_1 - dt_2)""" d1_ts = time.mktime(dt_1.timetuple()) d2_ts = time.mktime(dt_2.timetuple()) return int((d1_ts - d2_ts) / 60) auto_replys = AutoReply.objects.filter(is_active=True) for auto_reply in auto_replys: if auto_reply.keyword in message: now = datetime.datetime.now() min_diff = get_min_diff(now, auto_reply. date_modified.astimezone(LOCAL_TZ)) if auto_reply.count_down and min_diff < auto_reply.count_down: message = auto_reply.msg_cnt_dn.\ format(auto_reply.count_down - min_diff) else: message = auto_reply.msg goobo.say(recipient, message)