Geen omschrijving

storefront.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. from .models import Store, PostCategory, Post, MenuItem
  2. from .pos import MessageSys
  3. from itertools import chain
  4. class StoreFront:
  5. def __init__(self, storeId):
  6. self.store = Store.objects.get(pk=storeId)
  7. self.messageSys = MessageSys(self.store)
  8. @property
  9. def storeId(self):
  10. return self.store.id
  11. @classmethod
  12. def globalSearch(cls, q):
  13. qs1 = Post.objects.filter(title__icontains=q)
  14. qs2 = MenuItem.objects.filter(name__icontains=q)
  15. return list(chain(qs1, qs2))
  16. def primaryMenus(self):
  17. pass
  18. def secondaryMenus(self):
  19. pass
  20. @property
  21. def addressText(self):
  22. return self.store.addressText
  23. def search(self, **kwargs):
  24. print("Search")
  25. q = kwargs.get('q', None)
  26. if q:
  27. qs1 = Post.objects.filter(title__icontains=q, store=self.store)
  28. qs2 = MenuItem.objects.filter(name__icontains=q, store=self.store)
  29. return list(chain(qs1, qs2))
  30. else:
  31. return []
  32. def addToCart(self, orderId, menuId):
  33. pass
  34. def viewCart(self, orderId):
  35. pass
  36. def messageForm(self, oid=None, request=None):
  37. return self.messageSys.form(oid, request)
  38. @property
  39. def fullName(self):
  40. return f"{self.store.name}"
  41. def getPosts(self, **kwargs):
  42. cat = kwargs.get('cat', None)
  43. try:
  44. if cat:
  45. pc = PostCategory.objects.get(name=cat)
  46. return pc.post_set.filter(store=self.store)
  47. except:
  48. return None
  49. def getPostById(self, pid):
  50. return Post.objects.get(pk=pid)
  51. def getMenus(self, **kwargs):
  52. return self.store.menuitem_set.filter(**kwargs)
  53. @property
  54. def logo(self):
  55. if self.store.logo:
  56. return self.store.logo.url
  57. else:
  58. return None
  59. @property
  60. def description(self):
  61. return self.store.description
  62. @property
  63. def location(self):
  64. return (self.store.address, self.store.geolocation)
  65. @property
  66. def tel_number(self):
  67. return self.store.phone_number
  68. @property
  69. def fax_number(self):
  70. return self.store.fax_number
  71. @property
  72. def lineId(self):
  73. return self.store.lineId
  74. @property
  75. def email(self):
  76. return self.store.email