def handle(self, text): #If contact is not registered inform them and do not proceed to check requests if self.msg.contact == None: self.respond("Seems you are not registered. %s" % RegisterHandler.HELP_TEXT) return supply_items = set(re.findall('\S+', text)) request = None supply_requests=None try: for supply_item in supply_items: try: supply_type = SupplyType.objects.get(slug=supply_item) except: self.respond("Supply %s not found." % (supply_item)) continue supply_requests = SupplyRequest.active().filter(type=supply_type) if supply_requests: match = False for request in supply_requests: if request.requested_by: if request.requested_by == self.msg.contact: self.respond("Your request for %(supply)s has status: %(status)s as of %(date)s.", supply=request.type.name, status=request.get_status_display().upper(), date=request.modified.strftime("%B %d, %Y at %I:%M:%S %p")) match = True if not match: self.respond("Request for %s by %s not found" % (supply_type, self.msg.contact)) else: self.respond("Request for %s by %s not found" % (supply_type, self.msg.contact)) except Exception, e: self.error(e)
def handle(self, text): if not self.msg.contact: self.respond("Sorry you have to register to report supplies. %s" %\ RegisterHandler.HELP_TEXT) return # for convenience contact = self.msg.contact location = self.msg.contact.location processed_supplies = [] inactive_supplies = [] unknown_supplies = [] supply_codes = text.split(" ") for code in supply_codes: try: supply = SupplyType.objects.get(slug__iexact=code) # check for pending requests try: # if the below doesn't fail we already have a pending request pending = SupplyRequest.active().get(location=location, type=supply) pending.status = "delivered" pending.save() processed_supplies.append(pending) except SupplyRequest.DoesNotExist: # this was a known supply type, but we didn't have an active request inactive_supplies.append(supply) except SupplyType.DoesNotExist: unknown_supplies.append(code) if processed_supplies: self.respond( "Your confirmation that %(supplies)s were delivered has been received. Enjoy your new stuff!", supplies=" and ".join( [supply.type.name for supply in processed_supplies])) if inactive_supplies: self.respond( "You don't have any active requests for %(supplies)s.", supplies=" and ".join( [supply.name for supply in inactive_supplies])) if unknown_supplies: self.respond( "Sorry, I don't know about any supplies with code %(supplies)s.", supplies=" or ".join([code for code in unknown_supplies]))
def handle(self, text): supply_codes = text.split(" ") if not self.msg.contact: self.respond("Sorry you have to register to request supplies. %s" %\ RegisterHandler.HELP_TEXT) return # for convenience contact = self.msg.contact location = self.msg.contact.location created_supplies = [] pending_supplies = [] unknown_supplies = [] for code in supply_codes: try: supply = SupplyType.objects.get(slug__iexact=code) # check for pending requests try: # if the below doesn't fail we already have a pending request pending = SupplyRequest.active().get(location=location, type=supply, requested_by=self.msg.contact) pending_supplies.append(pending) except SupplyRequest.DoesNotExist: # normal flow -- create a new supply request for this request = SupplyRequest.objects.create(type=supply, status="requested", location=self.msg.contact.location, requested_by=self.msg.contact) created_supplies.append(supply) except SupplyType.DoesNotExist: unknown_supplies.append(code) if created_supplies: self.respond("Your request for more %(supplies)s has been received.", supplies=" and ".join([supply.name for supply in created_supplies])) if unknown_supplies: self.respond("Sorry, I don't know about any supplies with code %(supplies)s.", supplies=" or ".join([code for code in unknown_supplies])) if pending_supplies: self.respond("You already have requested %(supplies)s. To check status send STATUS <SUPPLY CODE>.", supplies=" and ".join([supply.type.name for supply in pending_supplies]))
def handle(self, text): if not self.msg.contact: self.respond("Sorry you have to register to report supplies. %s" %\ RegisterHandler.HELP_TEXT) return # for convenience contact = self.msg.contact location = self.msg.contact.location processed_supplies = [] inactive_supplies = [] unknown_supplies = [] supply_codes = text.split(" ") for code in supply_codes: try: supply = SupplyType.objects.get(slug__iexact=code) # check for pending requests try: # if the below doesn't fail we already have a pending request pending = SupplyRequest.active().get(location=location, type=supply) pending.status = "delivered" pending.save() processed_supplies.append(pending) except SupplyRequest.DoesNotExist: # this was a known supply type, but we didn't have an active request inactive_supplies.append(supply) except SupplyType.DoesNotExist: unknown_supplies.append(code) if processed_supplies: self.respond("Your confirmation that %(supplies)s were delivered has been received. Enjoy your new stuff!", supplies=" and ".join([supply.type.name for supply in processed_supplies])) if inactive_supplies: self.respond("You don't have any active requests for %(supplies)s.", supplies=" and ".join([supply.name for supply in inactive_supplies])) if unknown_supplies: self.respond("Sorry, I don't know about any supplies with code %(supplies)s.", supplies=" or ".join([code for code in unknown_supplies]))
def handle(self, text): #If contact is not registered inform them and do not proceed to check requests if self.msg.contact == None: self.respond("Seems you are not registered. %s" % RegisterHandler.HELP_TEXT) return supply_items = set(re.findall('\S+', text)) request = None supply_requests = None try: for supply_item in supply_items: try: supply_type = SupplyType.objects.get(slug=supply_item) except: self.respond("Supply %s not found." % (supply_item)) continue supply_requests = SupplyRequest.active().filter( type=supply_type) if supply_requests: match = False for request in supply_requests: if request.requested_by: if request.requested_by == self.msg.contact: self.respond( "Your request for %(supply)s has status: %(status)s as of %(date)s.", supply=request.type.name, status=request.get_status_display().upper( ), date=request.modified.strftime( "%B %d, %Y at %I:%M:%S %p")) match = True if not match: self.respond("Request for %s by %s not found" % (supply_type, self.msg.contact)) else: self.respond("Request for %s by %s not found" % (supply_type, self.msg.contact)) except Exception, e: self.error(e)