def enterprise_add(request): """ Agrega empresa dentro de una asociación, para ello deberá agregarse con una sede Principal """ d = Enterprise() d.sede = "Principal" if request.method == "POST": try: sid = transaction.savepoint() d.name = request.POST.get("name") d.tax_id = request.POST.get("tax_id") d.type_e = request.POST.get("type_e") d.solution_id = request.POST.get("solution_id") # solution=Solution.objects.get(id=d.solution_id) #no es necesario if normalize("NFKD", u"%s" % d.name).encode( "ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode( "ascii", "ignore").lower() for col in Enterprise.objects.values("name").exclude( id=d.id)): raise Exception( ("Empresa <b>%(name)s</b> ya existe.") % {"name": d.name}) if Enterprise.objects.exclude(id=d.id).filter( tax_id=d.tax_id).count() > 0: raise Exception("La empresa con RUC <b>%s</b> ya existe " % (d.tax_id)) d.save() headquar = Headquar() headquar.name = request.POST.get("sede") headquar.association_id = DataAccessToken.get_association_id( request.session) headquar.enterprise = d if normalize("NFKD", u"%s" % headquar.name).encode( "ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode( "ascii", "ignore").lower() for col in Headquar.objects.values("name").exclude( id=headquar.id).filter( enterprise_id=headquar.enterprise_id)): raise Exception("La sede <b>%s</b> ya existe " % (headquar.name)) headquar.save() if d.id: Message.info(request, ( "Empresa <b>%(name)s</b> ha sido registrado correctamente." ) % {"name": d.name}) return Redirect.to_action(request, "index") except Exception, e: transaction.savepoint_rollback(sid) Message.error(request, e)
def enterprise_add(request): """ Agrega empresa dentro de una asociación, para ello deberá agregarse con una sede Principal """ d = Enterprise() d.sede = "Principal" if request.method == "POST": try: sid = transaction.savepoint() d.name = request.POST.get("name") d.tax_id = request.POST.get("tax_id") d.type_e = request.POST.get("type_e") d.solution_id = request.POST.get("solution_id") # solution=Solution.objects.get(id=d.solution_id) #no es necesario if normalize("NFKD", u"%s" % d.name).encode("ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode("ascii", "ignore").lower() for col in Enterprise.objects.values("name").exclude(id=d.id) ): raise Exception(("Empresa <b>%(name)s</b> ya existe.") % {"name":d.name}) if Enterprise.objects.exclude(id=d.id).filter(tax_id=d.tax_id).count() > 0: raise Exception("La empresa con RUC <b>%s</b> ya existe " % (d.tax_id)) d.save() headquar = Headquar() headquar.name = request.POST.get("sede") headquar.association_id = DataAccessToken.get_association_id(request.session) headquar.enterprise = d if normalize("NFKD", u"%s" % headquar.name).encode("ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode("ascii", "ignore").lower() for col in Headquar.objects.values("name").exclude(id=headquar.id).filter(enterprise_id=headquar.enterprise_id) ): raise Exception("La sede <b>%s</b> ya existe " % (headquar.name)) headquar.save() if d.id: Message.info(request, ("Empresa <b>%(name)s</b> ha sido registrado correctamente.") % {"name":d.name}) return Redirect.to_action(request, "index") except Exception, e: transaction.savepoint_rollback(sid) Message.error(request, e)
def form_valid(self, form): sid = transaction.savepoint() try: association = Association( name=form.cleaned_data['association_name'], type_a=form.cleaned_data['type_e'], solution=form.cleaned_data['solution']) association.save() self.object = form.save(commit=False) self.object.save() headquar = Headquar(name="Principal", association=association, enterprise=self.object) headquar.save() solution_id = self.request.POST.get("solution") solution = Solution.objects.get(pk=solution_id) # asigna permisos al usuario para manipular datos de cierta sede, # empresa o asociación user = self.request.user enterprise = self.object group_dist_list = [] for module in solution.module_set.all(): # .distinct() for group in module.initial_groups.all(): if len(group_dist_list) == 0: group_dist_list.append(group.id) user.groups.add(group) user_association = UserAssociation() user_association.user = user user_association.association = association user_association.group = group user_association.save() user_enterprise = UserEnterprise() user_enterprise.user = user user_enterprise.enterprise = enterprise user_enterprise.group = group user_enterprise.save() user_headquar = UserHeadquar() user_headquar.user = user user_headquar.headquar = headquar user_headquar.group = group user_headquar.save() else: if group.id not in group_dist_list: group_dist_list.append(group.id) user.groups.add(group) user_association = UserAssociation() user_association.user = user user_association.association = association user_association.group = group user_association.save() user_enterprise = UserEnterprise() user_enterprise.user = user user_enterprise.enterprise = enterprise user_enterprise.group = group user_enterprise.save() user_headquar = UserHeadquar() user_headquar.user = user user_headquar.headquar = headquar user_headquar.group = group user_headquar.save() msg = _('The %(name)s "%(obj)s" was added successfully.') % { 'name': force_text(self.model._meta.verbose_name), 'obj': force_text(self.object) } if self.object.id: messages.success(self.request, msg) log.warning(msg, extra=log_params(self.request)) return super(EnterpriseAssociationCreateView, self).form_valid(form) except Exception as e: try: transaction.savepoint_rollback(sid) except: pass messages.success(self.request, e) log.warning(e, extra=log_params(self.request)) return super(EnterpriseAssociationCreateView, self).form_invalid(form)
def add_enterprise(request): d = Enterprise() if request.method == "POST": try: sid = transaction.savepoint() d.enterprise_name = request.POST.get("enterprise_name") d.enterprise_tax_id = request.POST.get("enterprise_tax_id") d.association_name = request.POST.get("association_name") d.association_type_a = request.POST.get("association_type_a") d.solution_id = request.POST.get("solution_id") solution = Solution.objects.get(id=d.solution_id) d.logo = request.POST.get("empresa_logo") user = request.user association = Association(name=d.association_name, type_a=d.association_type_a, solution=solution, logo=d.logo) if normalize("NFKD", u"%s" % d.association_name).encode("ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode("ascii", "ignore").lower() for col in Association.objects.values("name") ): raise Exception("La asociación <b>%s</b> ya existe " % (d.association_name)) association.save() enterprise = Enterprise(name=d.enterprise_name, tax_id=d.enterprise_tax_id, type_e=d.association_type_a, solution=solution, logo=d.logo) if normalize("NFKD", u"%s" % d.enterprise_name).encode("ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode("ascii", "ignore").lower() for col in Enterprise.objects.values("name") ): raise Exception("La empresa <b>%s</b> ya existe " % (d.enterprise_name)) if Enterprise.objects.filter(tax_id=d.enterprise_tax_id).count() > 0: raise Exception("La empresa con RUC <b>%s</b> ya existe " % (d.enterprise_tax_id)) enterprise.save() headquar = Headquar(name="Principal", association=association, enterprise=enterprise) headquar.save() # asigna permisos al usuario para manipular datos de cierta sede, empresa o asociación group_dist_list = [] for module in solution.module_set.all(): # .distinct() for group in module.initial_groups.all() : if len(group_dist_list) == 0 : group_dist_list.append(group.id) user.groups.add(group) user_profile_association = UserProfileAssociation() user_profile_association.user = user user_profile_association.association = association user_profile_association.group = group user_profile_association.save() user_profile_enterprise = UserProfileEnterprise() user_profile_enterprise.user = user user_profile_enterprise.enterprise = enterprise user_profile_enterprise.group = group user_profile_enterprise.save() user_profile_headquar = UserProfileHeadquar() user_profile_headquar.user = user user_profile_headquar.headquar = headquar user_profile_headquar.group = group user_profile_headquar.save() else : if group.id not in group_dist_list: group_dist_list.append(group.id) user.groups.add(group) user_profile_association = UserProfileAssociation() user_profile_association.user = user user_profile_association.association = association user_profile_association.group = group user_profile_association.save() user_profile_enterprise = UserProfileEnterprise() user_profile_enterprise.user = user user_profile_enterprise.enterprise = enterprise user_profile_enterprise.group = group user_profile_enterprise.save() user_profile_headquar = UserProfileHeadquar() user_profile_headquar.user = user user_profile_headquar.headquar = headquar user_profile_headquar.group = group user_profile_headquar.save() Message.info(request, ("Empresa <b>%(name)s</b> ha sido registrado correctamente!.") % {"name":d.enterprise_name}) return Redirect.to(request, "/accounts/choice_headquar/") except Exception, e: transaction.savepoint_rollback(sid) Message.error(request, e)
def signup_sys(request): if request.user.is_authenticated(): return HttpResponseRedirect("/accounts/choice_headquar/") d = Person() d.first_name = "" d.last_name = "" d.identity_num = "" if request.method == "POST": try: sid = transaction.savepoint() d.first_name = request.POST.get("first_name") d.last_name = request.POST.get("last_name") d.username = request.POST.get("login") d.enterprise_name = request.POST.get("enterprise_name") d.enterprise_tax_id = request.POST.get("enterprise_tax_id") d.association_name = request.POST.get("association_name") d.association_type_a = request.POST.get("association_type_a") d.solution_id = request.POST.get("solution_id") d.email = request.POST.get("email") d.photo = request.POST.get("persona_fotografia") d.identity_type = Person.DEFAULT #request.POST.get("identity_type") d.identity_num = request.POST.get("identity_num") identity_type_display = dict((x, y) for x, y in Person.IDENTITY_TYPES)[d.identity_type] solution = Solution.objects.get(id=d.solution_id) d.solution = solution if User.objects.filter(username=d.username).count() > 0: raise Exception("El usuario <b>%s</b> ya existe " % d.username) if User.objects.filter(email=d.email).count() > 0: raise Exception("El email <b>%s</b> ya existe " % d.email) user = User.objects.create_user(username=d.username, email=d.email, password=request.POST.get("password")) if normalize("NFKD", u"%s %s" % (d.first_name, d.last_name)).encode("ascii", "ignore").lower() in list( normalize("NFKD", u"%s %s" % (col["first_name"], col["last_name"])).encode("ascii", "ignore").lower() for col in Person.objects.values("first_name", "last_name").filter(identity_type=d.identity_type, identity_num=d.identity_num) ): raise Exception("La persona <b>%s %s</b> con %s:<b>%s</b> ya existe " % (d.first_name, d.last_name, identity_type_display, d.identity_num)) if Person.objects.filter(identity_type=d.identity_type, identity_num=d.identity_num).count() > 0: raise Exception("La persona con %s:<b>%s</b> ya existe " % (identity_type_display, d.identity_num)) person = Person(first_name=d.first_name, last_name=d.last_name, identity_type=d.identity_type, identity_num=d.identity_num, photo=d.photo) person.save() profile = Profile(user=user) profile.person = person profile.save() association = Association(name=d.association_name, type_a=d.association_type_a, solution=solution) if normalize("NFKD", u"%s" % d.association_name).encode("ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode("ascii", "ignore").lower() for col in Association.objects.values("name") ): raise Exception("La asociación <b>%s</b> ya existe " % (d.association_name)) association.save() enterprise = Enterprise(name=d.enterprise_name, tax_id=d.enterprise_tax_id, type_e=d.association_type_a, solution=solution) if normalize("NFKD", u"%s" % d.enterprise_name).encode("ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode("ascii", "ignore").lower() for col in Enterprise.objects.values("name") ): raise Exception("La empresa <b>%s</b> ya existe " % (d.enterprise_name)) if Enterprise.objects.filter(tax_id=d.enterprise_tax_id).count() > 0: raise Exception("La empresa con RUC <b>%s</b> ya existe " % (d.enterprise_tax_id)) enterprise.save() headquar = Headquar(name="Principal", association=association, enterprise=enterprise) headquar.save() # asigna permisos al usuario para manipular datos de cierta sede, empresa o asociación group_dist_list = [] for module in solution.module_set.all(): # .distinct() for group in module.initial_groups.all() : if len(group_dist_list) == 0 : group_dist_list.append(group.id) user.groups.add(group) user_profile_association = UserProfileAssociation() user_profile_association.user = user user_profile_association.association = association user_profile_association.group = group user_profile_association.save() user_profile_enterprise = UserProfileEnterprise() user_profile_enterprise.user = user user_profile_enterprise.enterprise = enterprise user_profile_enterprise.group = group user_profile_enterprise.save() user_profile_headquar = UserProfileHeadquar() user_profile_headquar.user = user user_profile_headquar.headquar = headquar user_profile_headquar.group = group user_profile_headquar.save() else : if group.id not in group_dist_list: group_dist_list.append(group.id) user.groups.add(group) user_profile_association = UserProfileAssociation() user_profile_association.user = user user_profile_association.association = association user_profile_association.group = group user_profile_association.save() user_profile_enterprise = UserProfileEnterprise() user_profile_enterprise.user = user user_profile_enterprise.enterprise = enterprise user_profile_enterprise.group = group user_profile_enterprise.save() user_profile_headquar = UserProfileHeadquar() user_profile_headquar.user = user user_profile_headquar.headquar = headquar user_profile_headquar.group = group user_profile_headquar.save() Message.info(request, ("Cuenta <b>%(name)s</b> ha sido registrado correctamente!.") % {"name":d.username}) if request.is_ajax(): request.path = "/accounts/login/" # /app/controller_path/action/$params return redirect("/accounts/login/") # return login_sys(request) else: return redirect("/accounts/login/") except Exception, e: transaction.savepoint_rollback(sid) Message.error(request, e)
def headquar_add(request): """ Agrega sede """ d = Headquar() d.phone = "" d.address = "" if request.method == "POST": try: sid = transaction.savepoint() d.name = request.POST.get("name") d.phone = request.POST.get("phone") d.address = request.POST.get("address") d.is_main = False d.locality_name = request.POST.get("locality_name") if request.POST.get("locality_name"): d.locality, is_locality_created = Locality.objects.get_or_create( name=request.POST.get("locality_name"), # name__iexact ) d.association_id = DataAccessToken.get_association_id(request.session) d.enterprise_id = DataAccessToken.get_enterprise_id(request.session) if normalize("NFKD", u"%s" % d.name).encode("ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode("ascii", "ignore").lower() for col in Headquar.objects.values("name").exclude(id=d.id).filter(enterprise_id=d.enterprise_id) ): raise Exception("La sede <b>%s</b> ya existe " % (d.name)) d.save() if d.id: Message.info(request, ("Sede <b>%(name)s</b> ha sido registrado correctamente.") % {"name":d.name}) return Redirect.to_action(request, "index") except Exception, e: transaction.savepoint_rollback(sid) Message.error(request, e)
def form_valid(self, form): sid = transaction.savepoint() try: association = Association( name=form.cleaned_data['association_name'], type_a=form.cleaned_data['type_e'], solution=form.cleaned_data['solution']) association.save() self.object = form.save(commit=False) self.object.save() headquar = Headquar( name="Principal", association=association, enterprise=self.object) headquar.save() solution_id = self.request.POST.get("solution") solution = Solution.objects.get(pk=solution_id) # asigna permisos al usuario para manipular datos de cierta sede, # empresa o asociación user = self.request.user enterprise = self.object group_dist_list = [] for module in solution.module_set.all(): # .distinct() for group in module.initial_groups.all(): if len(group_dist_list) == 0: group_dist_list.append(group.id) user.groups.add(group) user_association = UserAssociation() user_association.user = user user_association.association = association user_association.group = group user_association.save() user_enterprise = UserEnterprise() user_enterprise.user = user user_enterprise.enterprise = enterprise user_enterprise.group = group user_enterprise.save() user_headquar = UserHeadquar() user_headquar.user = user user_headquar.headquar = headquar user_headquar.group = group user_headquar.save() else: if group.id not in group_dist_list: group_dist_list.append(group.id) user.groups.add(group) user_association = UserAssociation() user_association.user = user user_association.association = association user_association.group = group user_association.save() user_enterprise = UserEnterprise() user_enterprise.user = user user_enterprise.enterprise = enterprise user_enterprise.group = group user_enterprise.save() user_headquar = UserHeadquar() user_headquar.user = user user_headquar.headquar = headquar user_headquar.group = group user_headquar.save() msg = _('The %(name)s "%(obj)s" was added successfully.') % { 'name': force_text(self.model._meta.verbose_name), 'obj': force_text(self.object) } if self.object.id: messages.success(self.request, msg) log.warning(msg, extra=log_params(self.request)) return super(EnterpriseAssociationCreateView, self).form_valid(form) except Exception as e: try: transaction.savepoint_rollback(sid) except: pass messages.success(self.request, e) log.warning(e, extra=log_params(self.request)) return super(EnterpriseAssociationCreateView, self).form_invalid(form)
def add_enterprise(request): d = Enterprise() if request.method == "POST": try: sid = transaction.savepoint() d.enterprise_name = request.POST.get("enterprise_name") d.enterprise_tax_id = request.POST.get("enterprise_tax_id") d.association_name = request.POST.get("association_name") d.association_type_a = request.POST.get("association_type_a") d.solution_id = request.POST.get("solution_id") solution = Solution.objects.get(id=d.solution_id) d.logo = request.POST.get("empresa_logo") user = request.user association = Association(name=d.association_name, type_a=d.association_type_a, solution=solution, logo=d.logo) if normalize("NFKD", u"%s" % d.association_name).encode( "ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode( "ascii", "ignore").lower() for col in Association.objects.values("name")): raise Exception("La asociación <b>%s</b> ya existe " % (d.association_name)) association.save() enterprise = Enterprise(name=d.enterprise_name, tax_id=d.enterprise_tax_id, type_e=d.association_type_a, solution=solution, logo=d.logo) if normalize("NFKD", u"%s" % d.enterprise_name).encode( "ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode( "ascii", "ignore").lower() for col in Enterprise.objects.values("name")): raise Exception("La empresa <b>%s</b> ya existe " % (d.enterprise_name)) if Enterprise.objects.filter( tax_id=d.enterprise_tax_id).count() > 0: raise Exception("La empresa con RUC <b>%s</b> ya existe " % (d.enterprise_tax_id)) enterprise.save() headquar = Headquar(name="Principal", association=association, enterprise=enterprise) headquar.save() # asigna permisos al usuario para manipular datos de cierta sede, empresa o asociación group_dist_list = [] for module in solution.module_set.all(): # .distinct() for group in module.initial_groups.all(): if len(group_dist_list) == 0: group_dist_list.append(group.id) user.groups.add(group) user_profile_association = UserProfileAssociation() user_profile_association.user = user user_profile_association.association = association user_profile_association.group = group user_profile_association.save() user_profile_enterprise = UserProfileEnterprise() user_profile_enterprise.user = user user_profile_enterprise.enterprise = enterprise user_profile_enterprise.group = group user_profile_enterprise.save() user_profile_headquar = UserProfileHeadquar() user_profile_headquar.user = user user_profile_headquar.headquar = headquar user_profile_headquar.group = group user_profile_headquar.save() else: if group.id not in group_dist_list: group_dist_list.append(group.id) user.groups.add(group) user_profile_association = UserProfileAssociation() user_profile_association.user = user user_profile_association.association = association user_profile_association.group = group user_profile_association.save() user_profile_enterprise = UserProfileEnterprise() user_profile_enterprise.user = user user_profile_enterprise.enterprise = enterprise user_profile_enterprise.group = group user_profile_enterprise.save() user_profile_headquar = UserProfileHeadquar() user_profile_headquar.user = user user_profile_headquar.headquar = headquar user_profile_headquar.group = group user_profile_headquar.save() Message.info( request, ("Empresa <b>%(name)s</b> ha sido registrado correctamente!.") % {"name": d.enterprise_name}) return Redirect.to(request, "/accounts/choice_headquar/") except Exception, e: transaction.savepoint_rollback(sid) Message.error(request, e)
def signup_sys(request): if request.user.is_authenticated(): return HttpResponseRedirect("/accounts/choice_headquar/") d = Person() d.first_name = "" d.last_name = "" d.identity_num = "" if request.method == "POST": try: sid = transaction.savepoint() d.first_name = request.POST.get("first_name") d.last_name = request.POST.get("last_name") d.username = request.POST.get("login") d.enterprise_name = request.POST.get("enterprise_name") d.enterprise_tax_id = request.POST.get("enterprise_tax_id") d.association_name = request.POST.get("association_name") d.association_type_a = request.POST.get("association_type_a") d.solution_id = request.POST.get("solution_id") d.email = request.POST.get("email") d.photo = request.POST.get("persona_fotografia") d.identity_type = Person.DEFAULT #request.POST.get("identity_type") d.identity_num = request.POST.get("identity_num") identity_type_display = dict( (x, y) for x, y in Person.IDENTITY_TYPES)[d.identity_type] solution = Solution.objects.get(id=d.solution_id) d.solution = solution if User.objects.filter(username=d.username).count() > 0: raise Exception("El usuario <b>%s</b> ya existe " % d.username) if User.objects.filter(email=d.email).count() > 0: raise Exception("El email <b>%s</b> ya existe " % d.email) user = User.objects.create_user( username=d.username, email=d.email, password=request.POST.get("password")) if normalize( "NFKD", u"%s %s" % (d.first_name, d.last_name) ).encode("ascii", "ignore").lower() in list( normalize("NFKD", u"%s %s" % (col["first_name"], col["last_name"])).encode( "ascii", "ignore").lower() for col in Person.objects.values("first_name", "last_name") .filter(identity_type=d.identity_type, identity_num=d.identity_num)): raise Exception( "La persona <b>%s %s</b> con %s:<b>%s</b> ya existe " % (d.first_name, d.last_name, identity_type_display, d.identity_num)) if Person.objects.filter(identity_type=d.identity_type, identity_num=d.identity_num).count() > 0: raise Exception("La persona con %s:<b>%s</b> ya existe " % (identity_type_display, d.identity_num)) person = Person(first_name=d.first_name, last_name=d.last_name, identity_type=d.identity_type, identity_num=d.identity_num, photo=d.photo) person.save() profile = Profile(user=user) profile.person = person profile.save() association = Association(name=d.association_name, type_a=d.association_type_a, solution=solution) if normalize("NFKD", u"%s" % d.association_name).encode( "ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode( "ascii", "ignore").lower() for col in Association.objects.values("name")): raise Exception("La asociación <b>%s</b> ya existe " % (d.association_name)) association.save() enterprise = Enterprise(name=d.enterprise_name, tax_id=d.enterprise_tax_id, type_e=d.association_type_a, solution=solution) if normalize("NFKD", u"%s" % d.enterprise_name).encode( "ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode( "ascii", "ignore").lower() for col in Enterprise.objects.values("name")): raise Exception("La empresa <b>%s</b> ya existe " % (d.enterprise_name)) if Enterprise.objects.filter( tax_id=d.enterprise_tax_id).count() > 0: raise Exception("La empresa con RUC <b>%s</b> ya existe " % (d.enterprise_tax_id)) enterprise.save() headquar = Headquar(name="Principal", association=association, enterprise=enterprise) headquar.save() # asigna permisos al usuario para manipular datos de cierta sede, empresa o asociación group_dist_list = [] for module in solution.module_set.all(): # .distinct() for group in module.initial_groups.all(): if len(group_dist_list) == 0: group_dist_list.append(group.id) user.groups.add(group) user_profile_association = UserProfileAssociation() user_profile_association.user = user user_profile_association.association = association user_profile_association.group = group user_profile_association.save() user_profile_enterprise = UserProfileEnterprise() user_profile_enterprise.user = user user_profile_enterprise.enterprise = enterprise user_profile_enterprise.group = group user_profile_enterprise.save() user_profile_headquar = UserProfileHeadquar() user_profile_headquar.user = user user_profile_headquar.headquar = headquar user_profile_headquar.group = group user_profile_headquar.save() else: if group.id not in group_dist_list: group_dist_list.append(group.id) user.groups.add(group) user_profile_association = UserProfileAssociation() user_profile_association.user = user user_profile_association.association = association user_profile_association.group = group user_profile_association.save() user_profile_enterprise = UserProfileEnterprise() user_profile_enterprise.user = user user_profile_enterprise.enterprise = enterprise user_profile_enterprise.group = group user_profile_enterprise.save() user_profile_headquar = UserProfileHeadquar() user_profile_headquar.user = user user_profile_headquar.headquar = headquar user_profile_headquar.group = group user_profile_headquar.save() Message.info( request, ("Cuenta <b>%(name)s</b> ha sido registrado correctamente!.") % {"name": d.username}) if request.is_ajax(): request.path = "/accounts/login/" # /app/controller_path/action/$params return redirect("/accounts/login/") # return login_sys(request) else: return redirect("/accounts/login/") except Exception, e: transaction.savepoint_rollback(sid) Message.error(request, e)
def headquar_add(request): """ Agrega sede """ d = Headquar() d.phone = "" d.address = "" if request.method == "POST": try: sid = transaction.savepoint() d.name = request.POST.get("name") d.phone = request.POST.get("phone") d.address = request.POST.get("address") d.is_main = False d.locality_name = request.POST.get("locality_name") if request.POST.get("locality_name"): d.locality, is_locality_created = Locality.objects.get_or_create( name=request.POST.get("locality_name"), # name__iexact ) d.association_id = DataAccessToken.get_association_id( request.session) d.enterprise_id = DataAccessToken.get_enterprise_id( request.session) if normalize("NFKD", u"%s" % d.name).encode( "ascii", "ignore").lower() in list( normalize("NFKD", u"%s" % col["name"]).encode( "ascii", "ignore").lower() for col in Headquar.objects.values("name").exclude( id=d.id).filter(enterprise_id=d.enterprise_id)): raise Exception("La sede <b>%s</b> ya existe " % (d.name)) d.save() if d.id: Message.info( request, ("Sede <b>%(name)s</b> ha sido registrado correctamente.") % {"name": d.name}) return Redirect.to_action(request, "index") except Exception, e: transaction.savepoint_rollback(sid) Message.error(request, e)