예제 #1
0
def clean_users():
    # removing users will remove everything
    # since all data linked into it
    users = model.get_all("user")
    for user in users:
        user_id = user["id"]
        model.delete(table="user", field="id", value=user_id)
예제 #2
0
    def delete(self, record_id):
        """Delete specific record.

        note:
        SOA record can't be deleted. One zone must have minimum one SOA record at time.
        But it can be edited, see`record edit`.
        """
        try:
            record_model.is_exists(record_id)
        except Exception:
            return response(404)

        zone = zone_model.get_zone_by_record(record_id)
        zone_name = zone["zone"]

        try:
            serial_resource = get_serial_resource(zone_name)
            check_serial_limit(serial_resource)
        except Exception as e:
            return response(429, message=f"{e}")

        try:
            rtype = type_model.get_type_by_recordid(record_id)
            if rtype == "SOA":
                return response(403, message=f"Can't Delete SOA Record")
            if rtype != "SOA":
                update_serial(serial_resource)

            command.set_zone(record_id, "zone-unset")

            model.delete(table="record", field="id", value=record_id)
            return response(204)
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500)
예제 #3
0
    def delete(self):
        """Remove domain (zone) and all its related records."""
        parser = reqparse.RequestParser()
        parser.add_argument("zone", type=str, required=True)
        args = parser.parse_args()
        zone = args["zone"]

        try:
            zone_id = zone_model.get_zone_id(zone)
        except Exception:
            return response(404, message=f"Zone Not Found")

        try:
            records = record_model.get_records_by_zone(zone)
            for record in records:
                # zone-purge didn't work
                # all the records must be unset one-by-one. otherwise old record
                # will appear again if the same zone name crated.
                command.set_zone(record["id"], "zone-unset")
            command.set_config(zone, zone_id, "conf-unset")

            # other data (e.g record) deleted automatically
            # by cockroach when no PK existed
            model.delete(table="zone", field="id", value=zone_id)

            return response(204, data=zone)
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500)
예제 #4
0
    def delete(self, id_userdata):
        try:
            db.delete(table="tb_userdata",
                      field='id_userdata',
                      value=id_userdata)
        except Exception as e:
            message = {"status": False, "error": str(e)}
        else:
            message = "removing"

        finally:
            return response(200, message=message)
예제 #5
0
    def post(self):
        json_req = request.get_json(force=True)
        command = utils.get_command(request.path)
        command = 'dt_' + command
        init_data = cmd.parser(json_req, command)
        respons = {}
        if init_data['action'] == 'insert':
            table = init_data['data'][0]['table']
            fields = init_data['data'][0]['fields']
            try:
                result = model.insert(table, fields)
            except Exception as e:
                respons = {"status": False, "error": str(e)}
            else:
                respons = {"status": True, "messages": "Success", "id": result}
            finally:
                return response(200, data=fields, message=respons)
        if init_data['action'] == 'remove':
            table = ""
            tags = dict()
            fields = ""
            for i in init_data['data']:
                table = i['table']
                tags = i['tags']
            fields = str(list(tags.keys())[0])
            try:
                result = model.delete(table, fields, tags[fields])
            except Exception as e:
                respons = {"status": False, "messages": str(e)}
            else:
                respons = {"status": result, "messages": "Success!"}
            finally:
                return response(200, data=tags, message=respons)

        if init_data['action'] == 'where':
            obj_userdata = list()
            table = ""
            fields = ""
            tags = dict()
            for i in init_data['data']:
                table = i['table']
                tags = i['tags']
                for a in tags:
                    if tags[a] is not None:
                        fields = a
            try:
                result = model.get_by_id(table, fields, tags[fields])
            except Exception as e:
                respons = {"status": False, "messages": str(e)}
            else:
                for i in result:
                    data = {
                        "id_product": str(i['id_product']),
                        "nm_product": i["nm_product"],
                        "nm_databaseref": i["nm_databaseref"]
                    }
                    obj_userdata.append(data)
                respons = {"status": True, "messages": "Fine!"}
            finally:
                return response(200, data=obj_userdata, message=respons)
예제 #6
0
파일: ttl.py 프로젝트: sofyan48/domba-api
 def delete(self, key):
     try:
         data = model.delete("ttl", key)
     except Exception as e:
         return response(401, message=str(e))
     else:
         return response(200, data=data, message="Deleted")
예제 #7
0
 def delete(self, key):
     try:
         record = model.record_by_zone(key)
     except Exception as e:
         return response(401, message="Record Not Found | " + str(e))
     else:
         for i in record:
             try:
                 model.record_delete(i['key'])
             except Exception as e:
                 print(e)
     try:
         model.delete("zone", key)
     except Exception as e:
         return response(401, message=str(e))
     else:
         return response(200, message="Domain Or Zone Deleted")
예제 #8
0
파일: ttl.py 프로젝트: w796933/RESTKnot
    def delete(self, ttl_id):
        try:
            row_count = model.delete(table="ttl", field="id", value=ttl_id)
            if not row_count:
                return response(404)

            return response(204)
        except Exception as e:
            return response(500, message=f"{e}")
예제 #9
0
    def delete(self, type_id):
        try:
            row_count = model.delete(table="type", field="id", value=type_id)
            if not row_count:
                return response(404)

            return response(204)
        except Exception:
            return response(500)
예제 #10
0
    def delete(self, user_id):
        try:
            row_count = model.delete(table="user", field="id", value=user_id)
            if not row_count:
                return response(404)

            return response(204)
        except Exception as e:
            current_app.logger.error(f"{e}")
            return response(500)
예제 #11
0
    def post(self):
        json_req = request.get_json(force=True)
        command = utils.get_command(request.path)
        command = 'dt_' + command
        init_data = cmd.parser(json_req, command)
        respons = dict()
        if init_data['action'] == 'insert':
            table = init_data['data'][0]['table']
            fields = init_data['data'][0]['fields']
            try:
                result = model.insert(table, fields)
            except Exception as e:
                respons = {"status": False, "error": str(e)}
            else:
                respons = {"status": True, "messages": "Success", "id": result}
            finally:
                return response(200, data=fields, message=respons)
        if init_data['action'] == 'remove':
            table = ""
            tags = dict()
            fields = ""
            for i in init_data['data']:
                table = i['table']
                tags = i['tags']
            fields = str(list(tags.keys())[0])
            try:
                result = model.delete(table, fields, tags[fields])
            except Exception as e:
                respons = {"status": False, "messages": str(e)}
            else:
                respons = {"status": result, "messages": "Success!"}
            finally:
                return response(200, data=tags, message=respons)

        if init_data['action'] == 'where':
            obj_userdata = list()
            table = ""
            fields = ""
            tags = dict()
            for i in init_data['data']:
                table = i['table']
                tags = i['tags']
                for a in tags:
                    if tags[a] is not None:
                        fields = a
            try:
                result = model.get_by_id(table, fields, tags[fields])
            except Exception as e:
                respons = {"status": False, "messages": str(e)}
            else:
                for i in result:
                    data = {
                        "id_hosting": str(i['id_hosting']),
                        "id_company_product": str(i['id_company_product']),
                        'spec_price': i['spec_price'],
                        "spec_storage": i['spec_storage'],
                        'spec_database': i['spec_database'],
                        "spec_free_domain": i['spec_free_domain'],
                        "spec_hosting_domain": i['spec_hosting_domain'],
                        'spec_subdomain': i['spec_subdomain'],
                        "spec_ftp_user": i['spec_ftp_user'],
                        "spec_control_panel": i['spec_control_panel'],
                        'spec_email_account': i['spec_email_account'],
                        "spec_spam_filter": i['spec_spam_filter'],
                        "date_time": i['date_time']
                    }
                    obj_userdata.append(data)
                respons = {"status": True, "messages": "Fine!"}
            finally:
                return response(200, data=obj_userdata, message=respons)
        if init_data['action'] == 'view':
            obj_userdata = list()
            table = ""
            fields = None
            tags = dict()
            for i in init_data['data']:
                table = i['table']
                tags = i['tags']
                for a in tags:
                    if tags[a] is not None:
                        fields = a
            column = model.get_columns("v_product_hosting")
            try:
                result = list()
                if fields is None:
                    query = """select * from v_product_hosting"""
                    db.execute(query)
                    rows = db.fetchall()
                    for row in rows:
                        result.append(dict(zip(column, row)))
                else:
                    query = """ select * from v_product_hosting where """ + fields + """='""" + tags[
                        fields] + """'"""
                    db.execute(query)
                    rows = db.fetchall()
                    for row in rows:
                        result.append(dict(zip(column, row)))
            except Exception as e:
                respons = {"status": False, "messages": str(e)}
            else:
                for i in result:
                    data = {
                        "id_company": str(i["id_company"]),
                        "id_product": str(i["id_product"]),
                        "id_hosting": str(i['id_hosting']),
                        "id_company_product": str(i['id_company_product']),
                        "id_additional_features":
                        str(i["id_additional_features"]),
                        "nm_company": i['nm_company'],
                        "url_company": i['url_company'],
                        "nm_product": i['nm_product'],
                        "nm_company_product": i['nm_company_product'],
                        "spec_storage": i['spec_storage'],
                        'spec_price': i['spec_price'],
                        "spec_storage": i['spec_storage'],
                        'spec_database': i['spec_database'],
                        "spec_free_domain": i['spec_free_domain'],
                        "spec_hosting_domain": i['spec_hosting_domain'],
                        'spec_subdomain': i['spec_subdomain'],
                        "spec_ftp_user": i['spec_ftp_user'],
                        "spec_control_panel": i['spec_control_panel'],
                        'spec_email_account': i['spec_email_account'],
                        "spec_spam_filter": i['spec_spam_filter'],
                        "date_time": i['date_time'],
                        "spec_features": i['spec_features'],
                        "spec_features_value": i['spec_features_value'],
                        "spec_features_price": i['spec_features_price']
                    }
                    obj_userdata.append(data)
                respons = {"status": True, "messages": "Fine!"}
            finally:
                return response(200, data=obj_userdata, message=respons)
예제 #12
0
    def post(self):
        json_req = request.get_json(force=True)
        command = utils.get_command(request.path)
        command = 'dt_' + command
        init_data = cmd.parser(json_req, command)
        respons = {}
        if init_data['action'] == 'insert':
            table = init_data['data'][0]['table']
            fields = init_data['data'][0]['fields']
            try:
                result = model.insert(table, fields)
            except Exception as e:
                respons = {"status": False, "error": str(e)}
            else:
                respons = {"status": True, "messages": "Success", "id": result}
            finally:
                return response(200, data=fields, message=respons)
        if init_data['action'] == 'remove':
            table = ""
            tags = dict()
            fields = ""
            for i in init_data['data']:
                table = i['table']
                tags = i['tags']
            fields = str(list(tags.keys())[0])
            try:
                result = model.delete(table, fields, tags[fields])
            except Exception as e:
                respons = {"status": False, "messages": str(e)}
            else:
                respons = {"status": result, "messages": "Success!"}
            finally:
                return response(200, data=tags, message=respons)
        if init_data['action'] == 'view':
            obj_userdata = list()
            table = ""
            fields = None
            tags = dict()
            for i in init_data['data']:
                table = i['table']
                tags = i['tags']
                for a in tags:
                    if tags[a] is not None:
                        fields = a
            column = model.get_columns("v_product_vm")
            try:
                result = list()
                if fields is None:
                    query = """select * from v_product_vm"""
                    db.execute(query)
                    rows = db.fetchall()
                    for row in rows:
                        result.append(dict(zip(column, row)))
                else:
                    query = """ select * from v_product_vm_test where """ + fields + """='""" + tags[
                        fields] + """'"""
                    db.execute(query)
                    rows = db.fetchall()
                    for row in rows:
                        result.append(dict(zip(column, row)))
            except Exception as e:
                respons = {"status": False, "messages": str(e)}
            else:
                for i in result:
                    data = {
                        "id_company": str(i['id_company']),
                        "id_company_product": str(i['id_company_product']),
                        "id_product": str(i['id_product']),
                        'id_vm': str(i['id_vm']),
                        "id_additional_features":
                        str(i['id_additional_features']),
                        "nm_company": i['nm_company'],
                        "url_company": i['url_company'],
                        'nm_company_product': i['nm_company_product'],
                        "nm_product": i['nm_product'],
                        "currency_used": i['currency_used'],
                        'spec_clock': i['spec_clock'],
                        "spec_ram": i['spec_ram'],
                        "spec_os": i['spec_os'],
                        'spec_storage_volume': i['spec_storage_volume'],
                        "spec_ssd_volume": i['spec_ssd_volume'],
                        "spec_snapshot_volume": i['spec_snapshot_volume'],
                        "spec_template_volume": i['spec_template_volume'],
                        'spec_iso_volume': i['spec_iso_volume'],
                        "spec_public_ip": i['spec_public_ip'],
                        "spec_backup_storage": i['spec_backup_storage'],
                        'spec_features': i['spec_features'],
                        "spec_features_value": i['spec_features_value'],
                        "spec_features_price": i['spec_features_price'],
                        'spec_price': i['spec_price'],
                        "date_time": i['date_time']
                    }
                    obj_userdata.append(data)
                respons = {"status": True, "messages": "Fine!"}
            finally:
                return response(200, data=obj_userdata, message=respons)

        if init_data['action'] == 'where':
            obj_userdata = list()
            table = ""
            fields = ""
            tags = dict()
            for i in init_data['data']:
                table = i['table']
                tags = i['tags']
                for a in tags:
                    if tags[a] is not None:
                        fields = a
            try:
                result = model.get_by_id(table, fields, tags[fields])
            except Exception as e:
                respons = {"status": False, "messages": str(e)}
            else:
                for i in result:
                    data = {
                        "id_vm": str(i['id_vm']),
                        "id_company_product": str(i['id_company_product']),
                        "spec_vcpu": i['spec_vcpu'],
                        'spec_clock': i['spec_clock'],
                        "spec_ram": i['spec_ram'],
                        "spec_os": i['spec_os'],
                        "spec_storage_volume": i['spec_storage_volume'],
                        'spec_ssd_volume': i['spec_ssd_volume'],
                        "spec_snapshot_volume": i['spec_snapshot_volume'],
                        "spec_template_volume": i['spec_template_volume'],
                        'spec_iso_volume': i['spec_iso_volume'],
                        "spec_public_ip": i['spec_public_ip'],
                        "spec_backup_storage": i['spec_backup_storage'],
                        'spec_price': i['spec_price'],
                        "spec_notes": i['spec_notes'],
                        "date_time": i['date_time']
                    }
                    obj_userdata.append(data)
                respons = {"status": True, "messages": "Fine!"}
            finally:
                return response(200, data=obj_userdata, message=respons)
예제 #13
0
    def post(self):
        json_req = request.get_json(force=True)
        command = utils.get_command(request.path)
        command = "zn_" + command
        init_data = cmd.parser(json_req, command)
        respons = dict()
        if init_data['action'] == 'insert':
            table = init_data['data'][0]['table']
            fields = init_data['data'][0]['fields']
            try:
                result = model.insert(table, fields)
            except Exception as e:
                respons = {"status": False, "error": str(e)}
            else:
                respons = {"status": True, "messages": "Fine!", "id": result}
            finally:
                return response(200, data=fields, message=respons)
        if init_data['action'] == 'where':
            obj_userdata = list()
            table = ""
            fields = ""
            tags = dict()
            for i in init_data['data']:
                table = i['table']
                tags = i['tags']
                for a in tags:
                    if tags[a] is not None:
                        fields = a
            try:
                result = model.get_by_id(table, fields, tags[fields])
            except Exception as e:
                respons = {"status": False, "messages": str(e)}
            else:
                for i in result:
                    data = {
                        "id_content": str(i['id_content']),
                        "id_ttldata": str(i['id_ttldata']),
                        "nm_content": str(i['nm_content'])
                    }
                    obj_userdata.append(data)
                respons = {"status": True, "messages": "Fine!"}
            finally:
                return response(200, data=obj_userdata, message=respons)
        if init_data['action'] == 'remove':
            table = ""
            tags = dict()
            fields = ""
            for i in init_data['data']:
                table = i['table']
                tags = i['tags']
                for a in tags:
                    if tags[a] is not None:
                        fields = a
            try:
                result = model.delete(table, fields, tags[fields])
            except Exception as e:
                respons = {"status": False, "messages": str(e)}
            else:
                respons = {"status": result, "messages": "Fine Deleted!"}
            finally:
                return response(200, data=tags, message=respons)

        if init_data['action'] == 'view':
            obj_userdata = list()
            table = ""
            fields = None
            tags = dict()
            for i in init_data['data']:
                table = i['table']
                tags = i['tags']
                for a in tags:
                    if tags[a] is not None:
                        fields = a
            column = model.get_columns("v_contentdata")
            try:
                result = list()
                if fields is None:
                    query = """select * from v_contentdata"""
                    db.execute(query)
                    rows = db.fetchall()
                    for row in rows:
                        result.append(dict(zip(column, row)))
                else:
                    query = """ select * from v_contentdata where """ + fields + """='""" + tags[
                        fields] + """'"""
                    db.execute(query)
                    rows = db.fetchall()
                    for row in rows:
                        result.append(dict(zip(column, row)))
            except Exception as e:
                respons = {"status": False, "messages": str(e)}
            else:
                for i in result:
                    data = {
                        "id_content": str(i['id_content']),
                        "nm_zone": str(i['nm_zone']),
                        "nm_record": str(i['nm_record']),
                        "nm_type": str(i['nm_type']),
                        "nm_ttl": i['nm_ttl'],
                        "id_record": str(i['id_record']),
                        "nm_content": str(i['nm_content']),
                    }
                    obj_userdata.append(data)
                respons = {"status": True, "messages": "Fine!"}
            finally:
                return response(200, data=obj_userdata, message=respons)