Advertisement
melnichevv

Add Account

Nov 2nd, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. +class AddAccountForm(forms.ModelForm):
  2. + """
  3. + Add account form for TransCosmos
  4. + """
  5. + TERM_CHOICES = (
  6. + ('6', _('6-month')),
  7. + ('12', _('12-month'))
  8. + )
  9. + PRICING_TIERS = (
  10. + ('1', _('Tier 1')),
  11. + ('2', _('Tier 2')),
  12. + ('3', _('Tier 3'))
  13. + )
  14. + name = forms.CharField()
  15. + description = forms.CharField(widget=forms.Textarea)
  16. + start_date = forms.DateField()
  17. + license_term = forms.ChoiceField(widget=forms.RadioSelect, choices=TERM_CHOICES)
  18. + pricing_tier = forms.ChoiceField(widget=forms.Select(), choices=PRICING_TIERS)
  19. +
  20. + def __init__(self, *args, **kwargs):
  21. + if 'branding' in kwargs:
  22. + del kwargs['branding']
  23. +
  24. + super(AddAccountForm, self).__init__(*args, **kwargs)
  25. +
  26. + class Meta:
  27. + model = Org
  28. + fields = '__all__'
  29. +
  30. +
  31. class OrgGrantForm(forms.ModelForm):
  32. first_name = forms.CharField(help_text=_("The first name of the organization administrator"))
  33. last_name = forms.CharField(help_text=_("Your last name of the organization administrator"))
  34. @@ -590,7 +620,7 @@ class OrgCRUDL(SmartCRUDL):
  35. actions = ('signup', 'home', 'channels', 'webhook', 'edit', 'join', 'grant', 'create_login', 'choose',
  36. 'manage_accounts', 'manage', 'create','update', 'country', 'languages', 'clear_cache', 'download',
  37. 'twilio_connect', 'twilio_account', 'nexmo_configuration', 'nexmo_account', 'nexmo_connect', 'kik_connect',
  38. - 'export', 'import', 'plivo_connect', 'service', 'surveyor', 'opening_hours')
  39. + 'export', 'import', 'plivo_connect', 'service', 'surveyor', 'opening_hours', 'add_account')
  40.  
  41. model = Org
  42.  
  43. @@ -2214,6 +2244,32 @@ class OrgCRUDL(SmartCRUDL):
  44. return response
  45.  
  46.  
  47. + class AddAccount(Grant):
  48. + title = _("Add Account")
  49. + form_class = AddAccountForm
  50. + permission = None
  51. + success_message = ''
  52. + submit_button_name = _("Create Account")
  53. + fields = ('name', 'description', 'start_date', 'pricing_tier', 'license_term')
  54. +
  55. + def get_success_url(self):
  56. + return "%s?start" % reverse('public.public_welcome')
  57. +
  58. + def get_welcome_size(self):
  59. + welcome_topup_size = self.request.branding.get('welcome_topup', WELCOME_TOPUP_SIZE)
  60. + return welcome_topup_size
  61. +
  62. + def post_save(self, obj):
  63. + obj = super(OrgCRUDL.AddAccount, self).post_save(obj)
  64. + self.request.session['org_id'] = obj.pk
  65. +
  66. + user = authenticate(username=self.user.username, password=self.form.cleaned_data['password'])
  67. + login(self.request, user)
  68. + analytics.track(self.request.user.username, 'temba.org_signup', dict(org=obj.name))
  69. +
  70. + return obj
  71. +
  72. +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement