Esempio n. 1
0
 def info(self, request):
   context: Context = request.context
   args: dict = context.args
   args = rename_field(args, 'community_id', 'community__id')
   args = rename_field(args, 'subdomain', 'community__subdomain')
   args = rename_field(args, 'donate_page_id', 'id')
   donate_page_setting_info, err = self.service.get_donate_page_setting_info(args)
   if err:
     return MassenergizeResponse(error=str(err), status=err.status)
   return MassenergizeResponse(data=donate_page_setting_info)
Esempio n. 2
0
 def about_us_page_setting_info_view(request) -> None: 
   context: Context = request.context
   args: dict = context.args
   args = rename_field(args, 'community_id', 'community__id')
   args = rename_field(args, 'subdomain', 'community__subdomain')
   args = rename_field(args, 'about_us_page_id', 'id')
   about_us_page_setting_info, err = self.service.get_about_us_page_setting_info(args)
   if err:
     return MassenergizeResponse(error=str(err), status=err.status)
   return MassenergizeResponse(data=about_us_page_setting_info)
Esempio n. 3
0
        def create_community_view(request) -> None:
            context: Context = request.context
            args = context.get_request_body()

            args['accepted_terms_and_conditions'] = parse_bool(
                args.pop('accepted_terms_and_conditions', None))
            if not args['accepted_terms_and_conditions']:
                return MassenergizeResponse(
                    error="Please accept the terms and conditions")

            ok, err = check_length(args, 'name', 3, 25)
            if not ok:
                return MassenergizeResponse(error=str(err))

            ok, err = check_length(args, 'subdomain', 4, 20)
            if not ok:
                return MassenergizeResponse(error=str(err))

            args['is_geographically_focused'] = parse_bool(
                args.pop('is_geographically_focused', False))
            args['is_published'] = parse_bool(args.pop('is_published', False))
            args['is_approved'] = parse_bool(args.pop('is_approved', False))

            args = rename_field(args, 'image', 'logo')
            args = parse_location(args)
            if not args['is_geographically_focused']:
                args.pop('location', None)

            community_info, err = self.service.create_community(context, args)
            if err:
                return MassenergizeResponse(error=str(err), status=err.status)
            return MassenergizeResponse(data=community_info)
Esempio n. 4
0
 def info(self, request):
   context: Context  = request.context
   args = context.get_request_body()
   args = rename_field(args, 'vendor_id', 'id')
   vendor_info, err = self.service.get_vendor_info(context, args)
   if err:
     return MassenergizeResponse(error=str(err), status=err.status)
   return MassenergizeResponse(data=vendor_info)
Esempio n. 5
0
 def delete_community_view(request) -> None:
     context: Context = request.context
     args: dict = context.args
     args = rename_field(args, 'community_id', 'id')
     community_info, err = self.service.delete_community(args)
     if err:
         return MassenergizeResponse(error=str(err), status=err.status)
     return MassenergizeResponse(data=community_info)
Esempio n. 6
0
 def testimonial_info_view(request) -> None: 
   context: Context = request.context
   args: dict = context.args
   args = rename_field(args, 'testimonial_id', 'id')
   testimonial_info, err = self.service.get_testimonial_info(context, args)
   if err:
     return MassenergizeResponse(error=str(err), status=err.status)
   return MassenergizeResponse(data=testimonial_info)
Esempio n. 7
0
 def info(self, request):
     context: Context = request.context
     args: dict = context.args
     args = rename_field(args, 'graph_id', 'id')
     graph_info, err = self.service.get_graph_info(context, args)
     if err:
         return MassenergizeResponse(error=str(err), status=err.status)
     return MassenergizeResponse(data=graph_info)
Esempio n. 8
0
 def message_info_view(request) -> None:
     context: Context = request.context
     args = context.get_request_body()
     args = rename_field(args, 'message_id', 'id')
     message_info, err = self.service.get_message_info(context, args)
     if err:
         return MassenergizeResponse(error=str(err), status=err.status)
     return MassenergizeResponse(data=message_info)
Esempio n. 9
0
 def update(self, request):
   context: Context = request.context
   args: dict = context.args
   args = rename_field(args,'id','user_id')
   user_id = args.pop('user_id', None)
   user_info, err = self.service.update_user(context, user_id, args)
   if err:
     return MassenergizeResponse(error=str(err), status=err.status)
   return MassenergizeResponse(data=user_info)
Esempio n. 10
0
 def publish(self, request):
   context: Context = request.context
   args: dict = context.args
   args = rename_field(args, 'vendor_id', 'id')
   args['is_published'] =True
   vendor_info, err = self.service.update(args)
   if err:
     return MassenergizeResponse(error=str(err), status=err.status)
   return MassenergizeResponse(data=vendor_info)
Esempio n. 11
0
 def update_testimonial_view(request) -> None: 
   context: Context = request.context
   args: dict = context.args
   
   is_approved = args.pop("is_approved", None)
   if is_approved:
     args["is_approved"] = parse_bool(is_approved)
   is_published = args.get("is_published", None)
   if is_published:
     args["is_published"] = parse_bool(is_published)
   args = rename_field(args, 'community_id', 'community')
   args = rename_field(args, 'action_id', 'action')
   args = rename_field(args, 'vendor_id', 'vendor')
   args['tags'] = parse_list(args.get('tags', []))
   testimonial_id = args.pop("testimonial_id", None)
   testimonial_info, err = self.service.update_testimonial(context, testimonial_id, args)
   if err:
     return MassenergizeResponse(error=str(err), status=err.status)
   return MassenergizeResponse(data=testimonial_info)
Esempio n. 12
0
    def create(self, request):
        context: Context = request.context
        args: dict = context.args
        args = rename_field(args, 'community_id', 'community')
        args = rename_field(args, 'action_id', 'action')
        args = rename_field(args, 'vendor_id', 'vendor')
        args['tags'] = parse_list(args.get('tags', []))

        is_approved = args.pop("is_approved", None)
        if is_approved:
            args["is_approved"] = parse_bool(is_approved)
        is_published = args.get("is_published", None)
        if is_published:
            args["is_published"] = parse_bool(is_published)

        graph_info, err = self.service.create_graph(context, args)
        if err:
            return MassenergizeResponse(error=str(err), status=err.status)
        return MassenergizeResponse(data=graph_info)
Esempio n. 13
0
 def delete_vendor_view(request) -> None:
     context: Context = request.context
     args: dict = context.args
     args = rename_field(args, 'vendor_id', 'id')
     vendor_id = args.pop('id', None)
     if not vendor_id:
         return CustomMassenergizeError("Please Provide Vendor Id")
     vendor_info, err = self.service.delete_vendor(vendor_id)
     if err:
         return MassenergizeResponse(error=str(err), status=err.status)
     return MassenergizeResponse(data=vendor_info)
Esempio n. 14
0
 def copy(self, request):
   context: Context = request.context
   args: dict = context.args
   args = rename_field(args, 'vendor_id', 'id')
   vendor_id = args.pop('id', None)
   if not vendor_id:
     return CustomMassenergizeError("Please Provide Vendor Id")
   vendor_info, err = self.service.copy_vendor(vendor_id)
   if err:
     return err
   return MassenergizeResponse(data=vendor_info)
Esempio n. 15
0
 def delete(self, request):
     context: Context = request.context
     args: dict = context.args
     args = rename_field(args, 'message_id', 'id')
     message_id = args.pop('id', None)
     if not message_id:
         return CustomMassenergizeError("Please Provide Message Id")
     message_info, err = self.service.delete_message(message_id)
     if err:
         return MassenergizeResponse(error=str(err), status=err.status)
     return MassenergizeResponse(data=message_info)
Esempio n. 16
0
    def update(self, request):
        context: Context = request.context
        args: dict = context.args

        args = rename_field(args, 'id', 'community_id')
        community_id = args.get('community_id', None)
        if not community_id:
            return MassenergizeResponse(error='Please provide an ID')

        if (args.get('name', None)):
            ok, err = check_length(args, 'name', 3, 25)
            if not ok:
                return MassenergizeResponse(error=str(err))

        if (args.get('subdomain', None)):
            ok, err = check_length(args, 'subdomain', 4, 20)
            if not ok:
                return MassenergizeResponse(error=str(err))

        if (args.get('owner_name', None)):
            args['owner_name'] = args.get('owner_name', None)
        if (args.get('owner_email', None)):
            args['owner_email'] = args.get('owner_email', None)
        if (args.get('owner_phone_number', None)):
            args['owner_phone_number'] = args.get('owner_phone_number', None)

        if (args.get('is_geographically_focused', False)):
            args['is_geographically_focused'] = parse_bool(
                args.pop('is_geographically_focused', False))
        if (args.get('is_published', None)):
            args['is_published'] = parse_bool(args.pop('is_published', None))
        if (args.get('is_approved', None)):
            args['is_approved'] = parse_bool(args.pop('is_approved', None))

        args = rename_field(args, 'image', 'logo')
        args = parse_location(args)

        community_info, err = self.service.update_community(context, args)
        if err:
            return MassenergizeResponse(error=str(err), status=err.status)
        return MassenergizeResponse(data=community_info)
Esempio n. 17
0
        def update_vendor_view(request) -> None:
            context: Context = request.context
            args = context.get_request_body()
            args = rename_field(args, 'id', 'vendor_id')
            validator: Validator = Validator()
            (validator.expect("vendor_id", int).expect(
                "key_contact_name", str, is_required=False).expect(
                    "key_contact_email", str, is_required=False).expect(
                        "onboarding_contact_email", str,
                        is_required=False).expect(
                            "name", str, is_required=False).expect(
                                "email", str, is_required=False).expect(
                                    "is_verified", bool,
                                    is_required=False).expect(
                                        "phone_number", str,
                                        is_required=False).expect(
                                            "have_address",
                                            bool,
                                            is_required=False).expect(
                                                "is_published",
                                                bool,
                                                is_required=False).expect(
                                                    "communities",
                                                    list,
                                                    is_required=False).
             expect("service_area_states", list, is_required=False).expect(
                 "properties_serviced",
                 list, is_required=False).expect("tags",
                                                 list,
                                                 is_required=False).expect(
                                                     "image",
                                                     "file",
                                                     is_required=False).expect(
                                                         "location",
                                                         "location",
                                                         is_required=False))

            args, err = validator.verify(args)
            if err:
                return err

            args['key_contact'] = {}
            key_contact_name = args.pop('key_contact_name', None)
            key_contact_email = args.pop('key_contact_email', None)
            if key_contact_name:
                args['key_contact']["name"] = key_contact_name
            if key_contact_email:
                args['key_contact']["email"] = key_contact_email

            vendor_info, err = self.service.update_vendor(context, args)
            if err:
                return MassenergizeResponse(error=str(err), status=err.status)
            return MassenergizeResponse(data=vendor_info)
Esempio n. 18
0
    def create(self, request):
        context: Context = request.context
        args: dict = context.args
        args = rename_field(args, 'community_id', 'community')
        args = rename_field(args, 'action_id', 'action')
        args = rename_field(args, 'vendor_id', 'vendor')
        args = rename_field(args, 'preferredName', 'preferred_name')
        args['tags'] = parse_list(args.get('tags', []))

        # check validity - these should be IDs
        community = args.get('community', None)
        if community and not isinstance(community, int):
            args["community"] = parse_int(community)

        action = args.get('action', None)
        if action and not isinstance(action, int):
            args["action"] = parse_int(action)

        vendor = args.get('vendor', None)
        if vendor and not isinstance(vendor, int):
            args["vendor"] = parse_int(vendor)

        # To do, if we decide:
        # if user specifies other_vendor and passed to API - should record it as an unapproved vendor

        is_approved = args.pop("is_approved", None)
        if is_approved:
            args["is_approved"] = parse_bool(is_approved)
        is_published = args.get("is_published", None)
        if is_published:
            args["is_published"] = parse_bool(is_published)

        # no anonymous option anymore
        args["anonymous"] = False

        testimonial_info, err = self.service.create_testimonial(context, args)
        if err:
            return MassenergizeResponse(error=str(err), status=err.status)
        return MassenergizeResponse(data=testimonial_info)
Esempio n. 19
0
  def create(self, request):
    context: Context = request.context
    args: dict = context.args
    args = rename_field(args, 'community_id', 'community')

    (self.validator
      .add("name", str, is_required=True)
      .add("email", str, is_required=True)
      .add("community_id", str, is_required=False)
    )

    args, err = self.validator.verify(args)
    if err:
      return err
  
    community_id = args.pop('community', None)
    if community_id and not isinstance(community_id, int):
        community_id = parse_int(community_id)
    subscriber_info, err = self.service.create_subscriber(community_id ,args)
    if err:
      return MassenergizeResponse(error=str(err), status=err.status)
    return MassenergizeResponse(data=subscriber_info)