Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. def home_view(request, location):
  2. cards = Site.objects.get(sites=location.upper()
  3. ).site_cards.all().values('cards')
  4. # Convert query set to list of dictionaries, then to list of values of dictionaries, then to dictionary with same key,value pair
  5. vlans = json.load(open('allvendors/static/json/narf.json'))
  6. cards_dict = {c: vlans[location][c]
  7. for c in [d['cards'] for d in list(cards)]}
  8. home = {
  9. "site": location,
  10. "cards": cards_dict,
  11. }
  12. return render(request, 'allvendors/home.html', {"home": home})
  13.  
  14. {
  15. 'card1':{
  16. 'vlan':'101'
  17. },
  18. 'card2':{
  19. 'vlan':'102'
  20. },
  21. 'card3':{
  22. 'vlan':'103'
  23. },
  24. }
  25.  
  26. {% for card in home.cards %}
  27. <div class="card mb-4 box-shadow shadow">
  28. <div class="card-header">
  29. <h4 id="whatfor" class="my-0 font-weight-normal">{{ card|title }}</h4>
  30. </div>
  31. <div class="card-body">
  32. <h1 class="card-title pricing-card-title">Vlan:
  33. <small class="text-muted">
  34. <a href="#" target="_blank">
  35. {{ card.vlan }}
  36. </a>
  37. </small>
  38. </h1>
  39. <a class="text-decoration-none" href="{{ card|lower }}/">
  40. <button id="seedata" type="button" class="btn btn-lg btn-block btn-outline-primary">See
  41. Database</button>
  42. </a>
  43. </div>
  44. </div>
  45. {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement