forked from OpenLXP/openlxp-xss
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search - Adds the ability to search within an LCV and create an Alias without a context #16
Open
bayfaub
wants to merge
11
commits into
main
Choose a base branch
from
search
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
66296eb
Create search.html
EdblackGitHub b3eab71
Update urls.py
EdblackGitHub 09f6c75
Update views.py
EdblackGitHub 1066542
Update models.py
EdblackGitHub 5eeb9ca
Update forms.py
EdblackGitHub 5536e79
Create create_alias.html
EdblackGitHub e3bfc0c
Update views.py
EdblackGitHub 0e78368
Update forms.py
EdblackGitHub 0325f7a
Update models.py
EdblackGitHub d71e01b
fixed search, alias without context still broken
bayfaub f67e319
updated term creation form to allow for NeoAlias without context, hid…
bayfaub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
from typing import List | ||
from uuid import uuid4 | ||
|
||
from collections import defaultdict | ||
from core.models import NeoTerm | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
GLOBAL_PROVIDER_OWNER_UID = "0xFFFFFFFF" | ||
|
@@ -23,6 +26,51 @@ def check_neo4j_connection(): | |
time.sleep(1) # Wait before retrying | ||
return False | ||
|
||
# Alias class incase you create and alias with no context | ||
class Alias(StructuredNode): | ||
alias = StringProperty(unique_index=True) # The alias name | ||
context = StringProperty(required=False, default=None) # Optional context | ||
points_to = RelationshipTo('NeoTerm', 'POINTS_TO') # The relationship to NeoTerm | ||
context_error = StringProperty(required=False) # Optional field to store error message | ||
|
||
def __str__(self): | ||
return self.alias | ||
|
||
def link_to_term(self, neo_term): | ||
"""Link this alias to a NeoTerm.""" | ||
if isinstance(neo_term, NeoTerm): | ||
self.points_to.connect(neo_term) | ||
|
||
def save(self, *args, **kwargs): | ||
"""Override the save method to automatically link the alias to a NeoTerm if context is provided.""" | ||
context_error = None # Initialize an error variable | ||
|
||
# Call the parent class save method | ||
super(Alias, self).save(*args, **kwargs) | ||
|
||
if self.context: | ||
# Get or create the NeoTerm based on the context | ||
term, created = NeoTerm.get_or_create(uid=self.context) | ||
if term: | ||
# Set relationships for the NeoTerm, including the alias | ||
term.set_relationships(definition_node, context_node, self) | ||
else: | ||
context_error = f"No matching NeoTerm found for context: {self.context}" | ||
else: | ||
# If no context is provided, link to a default NeoTerm (first available NeoTerm) | ||
term = NeoTerm.nodes.first() # You can change this to a specific fallback logic | ||
if term: | ||
self.link_to_term(term) | ||
else: | ||
context_error = "No NeoTerm available to link." | ||
|
||
# If an error was encountered, raise it so it can be caught in the view or returned to the form | ||
if context_error: | ||
self.context_error = context_error # Store the error message in the instance | ||
self.save() | ||
|
||
return context_error # Return the error message, if any | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really like the way you wrote this class. Is there anyway you can make NeoAlias work in a similar way? |
||
# Generated Logs to track instance, time of generation, uid, provider and lcv terms | ||
class GeneratedUIDLog(models.Model): | ||
uid = models.CharField(max_length=255, default="UNKNOWN") | ||
|
@@ -512,4 +560,4 @@ def report_all_term_uids(): | |
|
||
# # Find collisions (where length > 1) | ||
# collisions = {key: value for key, value in uid_dict.items() if len(value) > 1} | ||
# return collisions | ||
# return collisions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Search</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
background-color: #f9f9f9; | ||
} | ||
.container { | ||
width: 80%; | ||
margin: 0 auto; | ||
padding: 20px; | ||
} | ||
h1 { | ||
text-align: center; | ||
color: #333; | ||
} | ||
.form-group { | ||
margin-bottom: 20px; | ||
} | ||
label { | ||
font-size: 16px; | ||
margin-bottom: 8px; | ||
display: block; | ||
} | ||
input[type="text"], select, button { | ||
padding: 10px; | ||
font-size: 16px; | ||
width: 100%; | ||
max-width: 400px; | ||
margin-top: 5px; | ||
} | ||
button { | ||
background-color: #4CAF50; | ||
color: white; | ||
border: none; | ||
cursor: pointer; | ||
font-size: 16px; | ||
} | ||
button:hover { | ||
background-color: #45a049; | ||
} | ||
.results-list { | ||
margin-top: 30px; | ||
} | ||
.result-item { | ||
background-color: #fff; | ||
border: 1px solid #ddd; | ||
padding: 15px; | ||
margin-bottom: 10px; | ||
border-radius: 5px; | ||
} | ||
.error-message { | ||
color: red; | ||
font-size: 16px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Search CCV/LCV Definitions</h1> | ||
|
||
<form method="POST"> | ||
{% csrf_token %} | ||
<div class="form-group"> | ||
<label for="search_term">Search Term:</label> | ||
<input type="text" name="search_term" id="search_term" placeholder="Enter search term" required> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="search_type">Search By:</label> | ||
<select name="search_type" id="search_type"> | ||
<option value="alias">Alias</option> | ||
<option value="definition">Definition</option> | ||
<option value="context">Context</option> | ||
<option value="general">General</option> | ||
</select> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<button type="submit">Search</button> | ||
</div> | ||
</form> | ||
|
||
<!-- Display search results --> | ||
{% if results_data %} | ||
<div class="results-list"> | ||
<h3>Search Results</h3> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>UID</th> | ||
<th>Alias</th> | ||
<th>Definition</th> | ||
<th>Context</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for record in results_data %} | ||
<tr> | ||
<td>{{ record.0 }}</td> <!-- UID --> | ||
<td>{{ record.1 }}</td> <!-- Alias --> | ||
<td>{{ record.2 }}</td> <!-- Definition --> | ||
<td>{{ record.3|default:"No context" }}</td> <!-- Context (with default fallback) --> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
{% endif %} | ||
|
||
{% if error %} | ||
<p class="error-message">{{ error }}</p> | ||
{% endif %} | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anyway to make this work with NeoAlias?