Skip to content

Commit

Permalink
adding invitation company on create company
Browse files Browse the repository at this point in the history
  • Loading branch information
sarias-eb committed Jun 11, 2020
1 parent f9ab5d2 commit 4c14abf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions supplier_app/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,8 @@ def setUp(self):
'eb_entity':'1',
'description':
'Bringing the world together through live experiences',
'email': '[email protected]',
'language': 'en',
}
self.client = Client()
self.ap_user = User.objects.create_user(email='[email protected]')
Expand Down
11 changes: 7 additions & 4 deletions supplier_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@
from utils.send_email import company_invitation_notification
from utils.htmltopdf import render_to_pdf


class CompanyCreatorView(UserLoginPermissionRequiredMixin, CreateView):
model = Company
fields = '__all__'
template_name = 'supplier_app/AP/company_creation.html'
success_url = reverse_lazy('company-list')
permission_required = (
CAN_CREATE_COMPANY_PERM,
)
Expand All @@ -115,6 +115,7 @@ def form_valid(self, form):
company = self.save_company(form)
InvitingBuyer.objects.create(company=company, inviting_buyer=self.request.user)
EBEntityCompany.objects.create(company=company, eb_entity=EBEntity.objects.get(pk=form.data['eb_entity']))
company_invite(self.request, company)
return HttpResponseRedirect(self.get_success_url())

def save_company(self, forms):
Expand All @@ -132,6 +133,7 @@ def get_failure_url(self):
)
return reverse('company-create')


class CompanyListView(LoginRequiredMixin, ListView):
model = Company
template_name = 'supplier_app/AP/company_list.html'
Expand Down Expand Up @@ -550,14 +552,15 @@ def get_success_url(self):


@transaction.atomic
def company_invite(request):
def company_invite(request, company=None):
try:
old_language = translation.get_language()
language = request.POST['language']
translation.activate(language)
email = [request.POST['email']]
company_id = request.POST['company_id']
company = Company.objects.get(pk=company_id)
if not company:
company_id = request.POST['company_id']
company = Company.objects.get(pk=company_id)
company_unique_token = CompanyUniqueToken(company=company)
company_unique_token.assing_company_token
company_unique_token.save()
Expand Down
14 changes: 14 additions & 0 deletions templates/supplier_app/AP/company_creation.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ <h6>{% trans "Description" %}</h6>
</div>
<textarea name="description" cols="40" rows="10" required="" id="id_description" class='form-control'></textarea>
</div>
<div class="form-row">
<input class="form-control form-control-sm col-md-5 m-1 " type="email" name="email" placeholder="Email">
<select class="form-control form-control-sm col-md-3 m-1" name="language" class="selectpicker" data-width="fit">
<option value="en" data-content="<span class='flag-icon flag-icon-us'></span> English">
{% trans "English" %}
</option>
<option value="es" data-content='<span class="flag-icon flag-icon-br"></span> Español'>
{% trans "Spanish" %}
</option>
<option value="pt-br"data-content='<span class="flag-icon flag-icon-br"></span> Portuguese'>
{% trans "Portuguese" %}
</option>
</select>
</div>
<input type="submit" value="{% trans 'Create Company' %}" class='btn btn-success m-2'>
<a class="btn btn-danger" href="{% url 'company-list' %}">{% trans "Cancel" %}</a>
</form>
Expand Down

0 comments on commit 4c14abf

Please sign in to comment.