views.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.template import RequestContext
  4. from django.shortcuts import render_to_response, render
  5. from django.contrib.auth.decorators import login_required
  6. from django.http import Http404
  7. from django.conf import settings
  8. from forms import PersonMemberChangeForm, OrganizationMemberChangeForm
  9. @login_required
  10. def index(request):
  11. has_isp_feed = 'isp' in [k for k, _, _ in settings.FEEDS]
  12. return render_to_response('members/index.html',
  13. {'has_isp_feed': has_isp_feed},
  14. context_instance=RequestContext(request))
  15. @login_required
  16. def detail(request):
  17. membership_info_url = settings.MEMBER_MEMBERSHIP_INFO_URL
  18. context={
  19. 'membership_info_url': membership_info_url,
  20. }
  21. if settings.MEMBER_CAN_EDIT_PROFILE:
  22. if request.user.type == "natural_person":
  23. form_cls = PersonMemberChangeForm
  24. else:
  25. form_cls = OrganizationMemberChangeForm
  26. if request.method == "POST":
  27. form = form_cls(data = request.POST, instance = request.user)
  28. if form.is_valid():
  29. form.save()
  30. else:
  31. form = form_cls(instance = request.user)
  32. context['form'] = form
  33. return render(request, 'members/detail.html', context)
  34. @login_required
  35. def subscriptions(request):
  36. subscriptions = request.user.get_active_subscriptions()
  37. old_subscriptions = request.user.get_inactive_subscriptions()
  38. return render_to_response('members/subscriptions.html',
  39. {'subscriptions': subscriptions,
  40. 'old_subscriptions': old_subscriptions},
  41. context_instance=RequestContext(request))
  42. @login_required
  43. def invoices(request):
  44. balance = request.user.balance
  45. invoices = request.user.invoices.filter(validated=True).order_by('-date')
  46. payments = request.user.payments.filter().order_by('-date')
  47. return render_to_response('members/invoices.html',
  48. {'balance' : balance,
  49. 'invoices': invoices,
  50. 'payments': payments},
  51. context_instance=RequestContext(request))
  52. @login_required
  53. def contact(request):
  54. return render_to_response('members/contact.html',
  55. context_instance=RequestContext(request))