Beispiel #1
0
def creating_provider():
    providers = Provider.query.all()
    form = ProviderForm(request.form)
    if request.method == 'POST':
        name = form.name.data
        Provider.save(Provider(name=name))
    return render_template('provider.html', providers=providers, form=form)
Beispiel #2
0
    def register_provider(self, message, role, clinic, name):
        """ Adds people into the system 
            JOIN CHW PASSWORD LAST FIRST ALIAS"""

        # If error in role, assume CHW
        try:
            role = Role.objects.get(code=role.lower())
        except Role.DoesNotExist:
            role = Role.objects.get(code="chw")

        # retrieve clinic
        try:
            clinic = Location.objects.get(code=clinic.lower())
        except Location.DoesNotExist:
            clinic = None

        # PHA _must_ be affiliated to a Clinic
        if role.code == "pha" and clinic == None:
            message.respond(
                _(u"Registration Failed. PHA needs correct clinic ID. '%(input)s' is not.") % {"input": clinic}
            )
            return True

        # Create provier
        try:
            alias, fn, ln = Provider.parse_name(name)
            provider = Provider(alias=alias, first_name=fn, last_name=ln, location=clinic, role=role)
            provider.save()

            # attach the reporter to the current connection
            message.persistant_connection.reporter = provider
            message.persistant_connection.save()
        except Exception, e:
            message.respond(_(u"Registration failed: %(error)s") % {"error": e.args})
Beispiel #3
0
    def register(self, request, **kwargs):
        self.method_check(request,allowed=['post','options'])

        data = self.deserialize(request,request.body,format=request.META.get('CONTENT_TYPE','application/json'))
        username = data.get('username','')
        password = data.get('password','')
        type = data.get('type','')

        #Basic Validation
        if User.objects.filter(username=username).exists():
            return self.create_response(request,{'success':False,'reason':'Username Existed!',},HttpForbidden)
        new_user = User.objects.create_user(username=username, email=username, password=password)
        new_user.save()

        #Devider User Type => Normal User or Provider
        #user group
        if type == 'provider':
            provider_g = Group.objects.get_or_create(name='provider')[0]
            provider_g.user_set.add(new_user)
            provider = Provider(user=new_user)
            provider.save()
        else:  #By default, register as normal user
            normaluser_g = Group.objects.get_or_create(name='normaluser')[0]
            normaluser_g.user_set.add(new_user)
            normaluser = NormalUser(user=new_user)
            normaluser.save()

        response = self.create_response(request,{'success':True})
    	response['Access-Control-Allow-Origin'] = "*"
        response['Access-Control-Allow-Methods'] = "GET, PUT, POST, PATCH"
        return response
Beispiel #4
0
def init_db(request):
    provider = Provider(max_credit=1000,
                        remaining_credit=1000,
                        credit_risk_level=80000,
                        avg_roi=0)
    purchaser = Purchaser(qr_code=111111, credit_risk_level=0)
    provider.save()
    purchaser.save()
    return HttpResponse("success")
Beispiel #5
0
def service_provider(request, id= ''):
    """
        endpoint: /provider/<id>/
        method: GET
        response: Service provider object stored in Database
        method: Post
        body: Json (name,email,phone,currency)
        response: 201, Newly created Service provider object
        method: Put
        body: Json (name,email,phone,currency)
        response: 200, Updated Service Provider Object
        method: Delete
        response: 204, No content
        ________________________________________________________________________________________
        endpoint: /provider/all
        method: GET
        response: Array of all service provider objects
    """
    try:
        if request.method == "POST":
            data = json.loads(request.body)
            provider = Provider(name=data['name'], email=data['email'], phone=data['phone'],
                                currency=data['currency'],service_area=[])
            provider.save()
            return json_response(provider.to_json(), 201)
        if request.method == "GET":
            if id is None or id == '':
                providers= Provider.objects.all()
                return json_response(providers.to_json(), 200)
            else:
                provider = Provider.objects.get(pk=id)
                return json_response(provider.to_json(), 200)
        provider = Provider.objects.get(pk=id)
        if request.method == "PUT":
            data = json.loads(request.body)
            provider.name = data['name']
            provider.email = data['email']
            provider.phone = data['phone']
            provider.currency = data['currency']
            provider.save()
            return json_response(provider.to_json(), 200)
        if request.method == "DELETE":
            provider.delete()
            return json_response('',204)
    except Exception as e:
        response = error_handler(e)
        return response
Beispiel #6
0
    def register_provider (self, message, role, password, last, first, alias, mobile):
        ''' Adds people into the system 
            JOIN CHW PASSWORD LAST FIRST ALIAS'''
        
        # If error in role, assume CHW
        role    = role.upper()
        if role == 'PHA':
            role    = Provider.PHA_ROLE
        else:
            role    = Provider.CHW_ROLE

        # retrieve clinic
        clinic      = Facility.by_alias(password)
        
        # PHA _must_ be affiliated to a Clinic
        if role == Provider.PHA_ROLE and clinic == None:
            message.respond(_(u"Registration Failed. PHA needs correct clinic ID. '%(input)s' is not.") % {'input': password})
            return True

        # Verify alias availability
        dumb    = Provider.by_alias(alias)
        if not dumb == None:
            message.respond(_(u"Registration Failed. Alias already in use by %(prov)s") % {'prov': dumb.display_full()})
            return True

        # Verify mobile slot
        dumb    = Provider.by_mobile(mobile)
        if not dumb == None:
            message.respond(_(u"Registration Failed. mobile number already in use by %(prov)s") % {'prov': dumb.display_full()})
            return True
        
        # Create provier
        provider    = Provider(alias=alias, first_name=first, last_name=last, role=role, active=True, clinic=clinic, mobile=mobile)
        provider.save()

        # send notifications
        message.respond(_(u"SUCCESS. %(prov)s has been registered with alias %(al)s.") % {'prov': provider.display_full(), 'al': provider.alias})
        
        if not provider.mobile == None:
            message.forward(provider.mobile, _(u"Welcome %(prov)s. You have been registered with alias %(al)s.") % {'prov': provider.display_full(), 'al': provider.alias})
    
        return True
Beispiel #7
0
    def setUp(self):

       u = get_user_model()()
       u.id = 1
       u.username = '******'
       u.first_name = 'test'
       u.last_name = 'test'
       u.email = 'test'
       u.set_password('test') 
       u.save()

       p = Provider()
       p.id = 1
       p.user = u
       p.name = "test"  
       p.email = "*****@*****.**" 
       p.phone = 12312312
       p.currency = "USD"
       p.language = "DE"
       p.save()

       u = get_user_model()()
       u.id = 2
       u.username = '******'
       u.first_name = 'test2'
       u.last_name = 'test2'
       u.email = '*****@*****.**'
       u.set_password('test') 
       u.save()

       p = Provider()
       p.id = 2
       p.user = u
       p.name = "test2"  
       p.email = "*****@*****.**" 
       p.phone = 123123212
       p.currency = "USD"
       p.language = "EN"
       p.save()

       self.url = reverse("provider:provider-detail",kwargs={"pk":1})