示例#1
0
def view_testlinechange_get(request):  
    print('view testline info...')
    from view_testline import search_testline, search_testline2
    url = request.build_absolute_uri()
    print(url)
    if 'btsid' in url:
        btsid = url.split('btsid=')[1].split('&')[0]
        if btsid == '':
            testline_info = {}
            newtestlineid = str(new_testlineid())
            testline_info['testlineid'] = newtestlineid
        else:
            testline_info = search_testline(btsid)[0]
        context = {}
        context['info'] = testline_info
        print(testline_info)
        return render(request, "testlinechange.html", context)
    elif 'testlineid' in url:
        testlineid = url.split('testlineid=')[1].split('&')[0]
        if testlineid == '':
            testline_info = {}
            newtestlineid = str(new_testlineid())
            testline_info['testlineid'] = newtestlineid
        else:
            testline_info = search_testline2(testlineid)[0]
        context = {}
        context['info'] = testline_info
        print(testline_info)
        return render(request, "testlinechange.html", context)
示例#2
0
    def process_url(self, url, **kwargs):
        """
        Add authkey to the ``url`` and then open that url with django test client.

        Returns:
            The ID of created ``AuthKey`` instance
        """

        url = AuthKey.objects.wrap_url(url, **kwargs)
        path, args = url.split('?')[0], cgi.parse_qs(url.split('?')[1])
        self.client.get(url, args)
        return args[URLAUTH_AUTHKEY_NAME][0]
示例#3
0
文件: admin.py 项目: dan-gamble/cms
    def remote_view(self, request, object_id):
        if not self.has_change_permission(request):
            return HttpResponseForbidden(
                "You do not have permission to modify this file.")

        if request.method != 'POST':
            return HttpResponseNotAllowed(['POST'])

        url = request.POST.get('url', None)

        if not url:
            raise Http404("No URL supplied.")

        # Pull down the remote image and save it as a temporary file.
        img_temp = NamedTemporaryFile()
        img_temp.write(requests.get(url).content)
        img_temp.flush()

        obj = get_object_or_404(File, pk=object_id)
        obj.file.save(url.split('/')[-1], DjangoFile(img_temp))

        messages.success(
            request,
            'The file "{}" was changed successfully. You may edit it again below.'
            .format(obj.__str__()))
        return HttpResponse('{"status": "ok"}',
                            content_type='application/json')
示例#4
0
文件: urls.py 项目: johnjohndoe/c3nav
 def urls(self):
     include_editor = can_access_editor(self.request)
     urls = OrderedDict()
     for urlpattern in router.urls:
         if not include_editor and inspect.getmodule(
                 urlpattern.callback).__name__.startswith('c3nav.editor.'):
             continue
         name = urlpattern.name
         url = self._format_pattern(str(urlpattern.pattern)).replace(
             '{pk}', '{id}')
         base = url.split('/', 1)[0]
         if base == 'editor':
             if name == 'editor-list':
                 continue
             if name == 'editor-detail':
                 name = 'editor-api'
         elif base == 'session':
             if name == 'session-list':
                 name = 'session-info'
         if '-' in name:
             urls.setdefault(base, OrderedDict())[name.split('-',
                                                             1)[1]] = url
         else:
             urls[name] = url
     return urls
    def get_for_url(cls, url):
        root = PhotosFolder.get_root()
        url_parts = url.split('/')

        folder = root
        for part in url_parts:
            folder = folder.get_subfolder_for_slug(part)
            if folder is None:
                return None

        return folder
示例#6
0
文件: urls.py 项目: pkirchner/c3nav
 def urls(self):
     urls = OrderedDict()
     for urlpattern in router.urls:
         name = urlpattern.name
         url = self._format_pattern(urlpattern.regex.pattern)
         base = url.split('/', 1)[0]
         if '-' in name:
             urls.setdefault(base, OrderedDict())[name.split('-',
                                                             1)[1]] = url
         else:
             urls[name] = url
     return urls
示例#7
0
 def replacewithlink(matchobj):
     url = matchobj.group(0)
     sin = matchobj.start()
     bef2 = text[sin - 2:sin]
     if bef2 != '="' and bef2 != "='":
         postfix = ''
         url_postfix = url.split('&nbsp')
         if len(url_postfix) > 1:
             url = url_postfix[0]
             postfix = f'&nbsp{url_postfix[-1]}'
         return f'<a href="{url.strip()}" target="_blank" rel="nofollow">{url}</a>{postfix}'
     else:
         return url
示例#8
0
def userprofile_view(request):
	url = request.path
	if url is not None:
		username = url.split('/')[-1]
		which_user = get_object_or_404(User, username=username)
		user_posts = Post.objects.filter(user=which_user).order_by('-timestamp')
	if which_user:
		context = {
			"username_destination": username,
			"which_user": which_user,
			"user_posts": user_posts,
		}
		return render(request, "profile.html", context)
	else:
		raise Http404
示例#9
0
def unpjax(url):
    """
    Removes `_pjax` param from query string of a given url::

        <a href="{{ request.get_full_path|unpjax }}"></a>
    """
    if "?" in url:
        base, qs = url.split("?", 1)
        if "_pjax" in qs:
            qs = QueryDict(qs, mutable=True)
            qs.pop("_pjax", None)
            qs = qs.urlencode()
            if qs:
                return base + "?" + qs
            return base
    return url
示例#10
0
def unpjax(url):
    """
    Removes `_pjax` param from query string of a given url::

        <a href="{{ request.get_full_path|unpjax }}"></a>
    """
    if "?" in url:
        base, qs = url.split("?", 1)
        if "_pjax" in qs:
            qs = QueryDict(qs, mutable=True)
            qs.pop("_pjax", None)
            qs = qs.urlencode()
            if qs:
                return base + "?" + qs
            return base
    return url
示例#11
0
文件: views.py 项目: yvess/smartmin
def smart_url(url, id=None):
    """
    URLs that start with @ are reversed, using the passed in arguments.

    Otherwise a straight % substitution is applied.
    """
    if url.find("@") >= 0:
        (args, value) = url.split('@')

        if args:
            return reverse(value, args=[id])
        else:
            return reverse(value)
    else:
        if id is None:
            return url
        else:
            return url % id
示例#12
0
def smart_url(url, obj=None):
    """
    URLs that start with @ are reversed, using the passed in arguments.

    Otherwise a straight % substitution is applied.
    """
    if url.find("@") >= 0:
        (args, value) = url.split('@')

        if args:
            val = getattr(obj, args, None)
            return reverse(value, args=[val])
        else:
            return reverse(value)
    else:
        if obj is None:
            return url
        else:
            return url % obj.id
示例#13
0
 def urls(self):
     include_editor = can_access_editor(self.request)
     urls = OrderedDict()
     for urlpattern in router.urls:
         if not include_editor and inspect.getmodule(urlpattern.callback).__name__.startswith('c3nav.editor.'):
             continue
         name = urlpattern.name
         url = self._format_pattern(str(urlpattern.pattern)).replace('{pk}', '{id}')
         base = url.split('/', 1)[0]
         if base == 'editor':
             if name == 'editor-list':
                 continue
             if name == 'editor-detail':
                 name = 'editor-api'
         elif base == 'session':
             if name == 'session-list':
                 name = 'session-info'
         if '-' in name:
             urls.setdefault(base, OrderedDict())[name.split('-', 1)[1]] = url
         else:
             urls[name] = url
     return urls
示例#14
0
文件: admin.py 项目: lewiscollard/cms
    def remote_view(self, request, object_id):
        if not self.has_change_permission(request):
            return HttpResponseForbidden("You do not have permission to modify this file.")

        if request.method != 'POST':
            return HttpResponseNotAllowed(['POST'])

        url = request.POST.get('url', None)

        if not url:
            raise Http404("No URL supplied.")

        # Pull down the remote image and save it as a temporary file.
        img_temp = NamedTemporaryFile()
        img_temp.write(requests.get(url).content)
        img_temp.flush()

        obj = get_object_or_404(File, pk=object_id)
        obj.file.save(url.split('/')[-1], DjangoFile(img_temp))

        messages.success(request, 'The file "{}" was changed successfully. You may edit it again below.'.format(
            obj.__str__()
        ))
        return HttpResponse('{"status": "ok"}', content_type='application/json')
示例#15
0
def render_url(url):
    """
    Removes GET parameters from URL.
    """
    return url.split("?")[0]
示例#16
0
def calculate(request):
    if request.method == 'POST':
        """
        Get data inject from html
        """
        # upload and get file
        uploaded_file = request.FILES['file_name']
        fs = FileSystemStorage()
        name = fs.save(uploaded_file.name, uploaded_file)

        url = fs.url(name)
        # get minsupp and minconf
        minsupp = request.POST['minsupp']
        minconf = request.POST['minconf']
        # get algorithm
        selectedAlgorithm = request.POST['selectedAlgorithm']

        BASE_DIR = dirname(os.path.dirname(os.path.abspath(__file__)))
        url_split = url.split("/")
        for value in url_split:
            if value == '':
                url_split.remove(value)
        for value in url_split:
            BASE_DIR = BASE_DIR + "\\" + str(value)
        # read dataset
        if name.find(".csv") != -1:
            store_data = pd.read_csv(BASE_DIR, header=None)
        if name.find(".xlsx") != -1:
            store_data = pd.read_excel(BASE_DIR, header=None)

        # change data conform algorithm
        records = []
        for i in range(0, len(store_data)):

            records.append([
                str(store_data.values[i, j])
                for j in range(0, len(store_data.columns))
            ])

        records_withoutNan = []

        for i in range(0, len(records)):
            new = []
            for j in range(0, len(records[i])):
                if str(records[i][j]) != "nan":
                    new.append(str(records[i][j]))
            records_withoutNan.append(new)

        te = TransactionEncoder()
        te_ary = te.fit(records_withoutNan).transform(records_withoutNan)
        df = pd.DataFrame(te_ary, columns=te.columns_)
        """
        function APRIORI algorithm
        return alist rules
        in rules have (super rules, sup rules and confidence every a rules)
        """
        def apriori_find_association_rules(dataset, minsup, minconf):
            patterns_ap = apriori(df,
                                  min_support=float(minsupp) / 100,
                                  use_colnames=True)
            rules_ap = association_rules(patterns_ap,
                                         metric="confidence",
                                         min_threshold=float(minconf) / 100)
            rules_ap_sort_descending = rules_ap.sort_values(by="lift",
                                                            ascending=False)
            return rules_ap_sort_descending

        """
        function FP-GROWTH algorithm
        return pattens, rules
        in rules have (super rules, sup rules and confidence every a rules)
        """

        def fpgrowth_find_association_rules(dataset, minsup, minconf):
            patterns_fp = fpgrowth(df,
                                   min_support=float(minsupp) / 100,
                                   use_colnames=True,
                                   verbose=0)
            rules_fp = association_rules(patterns_fp,
                                         metric="confidence",
                                         min_threshold=float(minconf) / 100)
            rules_fp_sort_descending = rules_fp.sort_values(by="lift",
                                                            ascending=False)
            return rules_fp_sort_descending

        """
        set event use Apriori or FP_Growth
        """
        if selectedAlgorithm == 'Apriori':
            """
            association_results_APRIORI: is a List Object Apriori return after calculate
            """
            association_results_APRIORI = apriori_find_association_rules(
                df, minsupp, minconf)
            rules_ap_antecedents_list = list(
                association_results_APRIORI['antecedents'])
            rules_ap_consequents_list = list(
                association_results_APRIORI['consequents'])
            rules_ap_support_list = list(
                association_results_APRIORI['support'])
            rules_ap_confidence_list = list(
                association_results_APRIORI['confidence'])
            rules_ap_lift_list = list(association_results_APRIORI['lift'])

            rules_ap_final = []
            for i in range(0, len(rules_ap_antecedents_list)):
                onerules = {}
                onerules['antecedents'] = list(rules_ap_antecedents_list[i])
                onerules['consequents'] = list(rules_ap_consequents_list[i])
                onerules['support'] = round(rules_ap_support_list[i], 3)
                onerules['confidence'] = round(rules_ap_confidence_list[i], 3)
                onerules['lift'] = round(rules_ap_lift_list[i], 3)
                rules_ap_final.append(onerules)

            return render(
                request, 'website/show_rules.html', {
                    'selectedAlgorithm': selectedAlgorithm,
                    'lenrules': len(rules_ap_final),
                    'lendata': len(df),
                    'association_rules': rules_ap_final
                })
        elif selectedAlgorithm == 'FP-Growth':

            association_results_FPGROWTH = fpgrowth_find_association_rules(
                df, minsupp, minconf)

            rules_fp_antecedents_list = list(
                association_results_FPGROWTH['antecedents'])
            rules_fp_consequents_list = list(
                association_results_FPGROWTH['consequents'])
            rules_fp_support_list = list(
                association_results_FPGROWTH['support'])
            rules_fp_confidence_list = list(
                association_results_FPGROWTH['confidence'])
            rules_fp_lift_list = list(association_results_FPGROWTH['lift'])

            rules_fp_final = []
            for i in range(0, len(rules_fp_antecedents_list)):
                onerules = {}
                onerules['antecedents'] = list(rules_fp_antecedents_list[i])
                onerules['consequents'] = list(rules_fp_consequents_list[i])
                onerules['support'] = round(rules_fp_support_list[i], 3)
                onerules['confidence'] = round(rules_fp_confidence_list[i], 3)
                onerules['lift'] = round(rules_fp_lift_list[i], 3)
                rules_fp_final.append(onerules)
            return render(
                request, 'website/show_rules.html', {
                    'selectedAlgorithm': selectedAlgorithm,
                    'lenrules': len(rules_fp_final),
                    'lendata': len(df),
                    'association_rules': rules_fp_final
                })
示例#17
0
def get_mapproxy(layer,
                 seed=False,
                 ignore_warnings=True,
                 renderd=False,
                 config_as_yaml=True):
    """Creates a mapproxy config for a given layer-like object.
       Compatible with django-registry and GeoNode.
    """
    bbox = list(wkt2geom(layer.wkt_geometry))
    bbox = ",".join([format(x, '.4f') for x in bbox])
    url = str(layer.source)

    layer_name = str(layer.title)

    srs = 'EPSG:4326'
    bbox_srs = 'EPSG:4326'
    grid_srs = 'EPSG:3857'

    default_source = {
        'type': 'wms',
        'coverage': {
            'bbox': bbox,
            'srs': srs,
            'bbox_srs': bbox_srs,
            'supported_srs': ['EPSG:4326', 'EPSG:900913', 'EPSG:3857'],
        },
        'req': {
            'layers': str(layer.title),
            'url': url,
            'transparent': True,
        },
    }

    if layer.type == 'ESRI:ArcGIS:MapServer' or layer.type == 'ESRI:ArcGIS:ImageServer':
        # blindly replace it with /arcgis/
        url = url.replace("/ArcGIS/rest/", "/arcgis/")
        # same for uppercase
        url = url.replace("/arcgis/rest/", "/arcgis/")
        # and for old versions
        url = url.replace("ArcX/rest/services", "arcx/services")
        # in uppercase or lowercase
        url = url.replace("arcx/rest/services", "arcx/services")

        srs = 'EPSG:3857'
        bbox_srs = 'EPSG:4326'

        default_source = {
            'type': 'arcgis',
            'req': {
                'url': url.split('?')[0],
                'grid': 'default_grid',
                'transparent': True,
            },
        }

    # A source is the WMS config
    sources = {'default_source': default_source}

    # A grid is where it will be projects (Mercator in our case)
    grids = {
        'default_grid': {
            'tile_size': [256, 256],
            'srs': grid_srs,
            'origin': 'nw',
        }
    }

    # A cache that does not store for now. It needs a grid and a source.
    caches = {
        'default_cache': {
            'disable_storage': True,
            'grids': ['default_grid'],
            'sources': ['default_source']
        },
    }

    # The layer is connected to the cache
    layers = [
        {
            'name': layer_name,
            'sources': ['default_cache'],
            'title': "%s" % layer.title,
        },
    ]

    # Services expose all layers.
    # WMS is used for reprojecting
    # TMS is used for easy tiles
    # Demo is used to test our installation, may be disabled in final version
    services = {
        'wms': {
            'image_formats': ['image/png'],
            'md': {
                'abstract': 'This is the Harvard HyperMap Proxy.',
                'title': 'Harvard HyperMap Proxy'
            },
            'srs': ['EPSG:4326', 'EPSG:3857'],
            'srs_bbox': 'EPSG:4326',
            'bbox': bbox,
            'versions': ['1.1.1']
        },
        'wmts': {
            'restful':
            True,
            'restful_template':
            '/{Layer}/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}.png',
        },
        'tms': {
            'origin': 'nw',
        },
        'demo': None,
    }

    global_config = {
        'http': {
            'ssl_no_cert_checks': True
        },
    }

    # Populate a dictionary with custom config changes
    extra_config = {
        'caches': caches,
        'grids': grids,
        'layers': layers,
        'services': services,
        'sources': sources,
        'globals': global_config,
    }

    yaml_config = yaml.dump(extra_config, default_flow_style=False)
    # If you want to test the resulting configuration. Turn on the next
    # line and use that to generate a yaml config.
    # assert False

    conf = configure_mapproxy(extra_config)
    # Create a MapProxy App
    app = MapProxyApp(conf.configured_services(), conf.base_config)

    # Wrap it in an object that allows to get requests by path as a string.
    if (config_as_yaml):
        return app, yaml_config

    return app, extra_config
示例#18
0
def render_url(url):
    """
    Removes GET parameters from URL.
    """
    return url.split("?")[0]