Skip to content

Commit

Permalink
hide sharing options when unconfigured.
Browse files Browse the repository at this point in the history
  • Loading branch information
jchate6 committed Oct 13, 2023
1 parent 19cf5ca commit 9750f2a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 28 deletions.
48 changes: 24 additions & 24 deletions tom_base/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,30 +237,30 @@
}

# Configuration for the TOM/Kafka Stream receiving data from this TOM
DATA_SHARING = {
'hermes': {
'DISPLAY_NAME': os.getenv('HERMES_DISPLAY_NAME', 'Hermes'),
'BASE_URL': os.getenv('HERMES_BASE_URL', 'https://hermes.lco.global/'),
'CREDENTIAL_USERNAME': os.getenv('SCIMMA_CREDENTIAL_USERNAME',
'set SCIMMA_CREDENTIAL_USERNAME value in environment'),
'CREDENTIAL_PASSWORD': os.getenv('SCIMMA_CREDENTIAL_PASSWORD',
'set SCIMMA_CREDENTIAL_PASSWORD value in environment'),
'USER_TOPICS': ['hermes.test', 'tomtoolkit.test']
},
'tom-demo-dev': {
'DISPLAY_NAME': os.getenv('TOM_DEMO_DISPLAY_NAME', 'TOM Demo Dev'),
'BASE_URL': os.getenv('TOM_DEMO_BASE_URL', 'http://tom-demo-dev.lco.gtn/'),
'USERNAME': os.getenv('TOM_DEMO_USERNAME', 'set TOM_DEMO_USERNAME value in environment'),
'PASSWORD': os.getenv('TOM_DEMO_PASSWORD', 'set TOM_DEMO_PASSWORD value in environment'),
},
'localhost-tom': {
# for testing; share with yourself
'DISPLAY_NAME': os.getenv('LOCALHOST_TOM_DISPLAY_NAME', 'Local'),
'BASE_URL': os.getenv('LOCALHOST_TOM_BASE_URL', 'http://127.0.0.1:8000/'),
'USERNAME': os.getenv('LOCALHOST_TOM_USERNAME', 'set LOCALHOST_TOM_USERNAME value in environment'),
'PASSWORD': os.getenv('LOCALHOST_TOM_PASSWORD', 'set LOCALHOST_TOM_PASSWORD value in environment'),
}
}
# DATA_SHARING = {
# 'hermes': {
# 'DISPLAY_NAME': os.getenv('HERMES_DISPLAY_NAME', 'Hermes'),
# 'BASE_URL': os.getenv('HERMES_BASE_URL', 'https://hermes.lco.global/'),
# 'CREDENTIAL_USERNAME': os.getenv('SCIMMA_CREDENTIAL_USERNAME',
# 'set SCIMMA_CREDENTIAL_USERNAME value in environment'),
# 'CREDENTIAL_PASSWORD': os.getenv('SCIMMA_CREDENTIAL_PASSWORD',
# 'set SCIMMA_CREDENTIAL_PASSWORD value in environment'),
# 'USER_TOPICS': ['hermes.test', 'tomtoolkit.test']
# },
# 'tom-demo-dev': {
# 'DISPLAY_NAME': os.getenv('TOM_DEMO_DISPLAY_NAME', 'TOM Demo Dev'),
# 'BASE_URL': os.getenv('TOM_DEMO_BASE_URL', 'http://tom-demo-dev.lco.gtn/'),
# 'USERNAME': os.getenv('TOM_DEMO_USERNAME', 'set TOM_DEMO_USERNAME value in environment'),
# 'PASSWORD': os.getenv('TOM_DEMO_PASSWORD', 'set TOM_DEMO_PASSWORD value in environment'),
# },
# 'localhost-tom': {
# # for testing; share with yourself
# 'DISPLAY_NAME': os.getenv('LOCALHOST_TOM_DISPLAY_NAME', 'Local'),
# 'BASE_URL': os.getenv('LOCALHOST_TOM_BASE_URL', 'http://127.0.0.1:8000/'),
# 'USERNAME': os.getenv('LOCALHOST_TOM_USERNAME', 'set LOCALHOST_TOM_USERNAME value in environment'),
# 'PASSWORD': os.getenv('LOCALHOST_TOM_PASSWORD', 'set LOCALHOST_TOM_PASSWORD value in environment'),
# }
# }

TOM_CADENCE_STRATEGIES = [
'tom_observations.cadences.retry_failed_observations.RetryFailedObservationsStrategy',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<a href="{% url 'tom_targets:update' pk=target.id %}" title="Update target" class="btn btn-primary">Update</a>
<a href="{% url 'tom_targets:share' pk=target.id %}" title="Share target" class="btn btn-info">Share</a>
{% if sharing %}
<a href="{% url 'tom_targets:share' pk=target.id %}" title="Share target" class="btn btn-info">Share</a>
{% endif %}
<a href="{% url 'tom_targets:delete' pk=target.id %}" title="Delete target" class="btn btn-warning">Delete</a>
8 changes: 6 additions & 2 deletions tom_targets/templates/tom_targets/target_grouping.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ <h1>Target Groupings</h1>
<tr>
<th>Group</th>
<th>Total Targets</th>
<th>Share</th>
{% if sharing %}
<th>Share</th>
{% endif %}
<th>Delete</th>
</tr>
</thead>
Expand All @@ -26,7 +28,9 @@ <h1>Target Groupings</h1>
<tr>
<td><button type="submit" class="btn btn-link" name="targetlist__name" value="{{group.id}}" title="View Group">{{ group.name }}</button></td>
<td valign="middle">{{ group.targets.count }}</td>
<td><a href="{% url 'targets:share-group' group.id%}" title="Share Group" class="btn btn-info">Share</a></td>
{% if sharing %}
<td><a href="{% url 'targets:share-group' group.id%}" title="Share Group" class="btn btn-info">Share</a></td>
{% endif %}
<td><a href="{% url 'targets:delete-group' group.id%}" title="Delete Group" class="btn btn-danger">Delete</a></td>
</tr>
{% empty %}
Expand Down
3 changes: 2 additions & 1 deletion tom_targets/templatetags/targets_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def target_buttons(target):
"""
Displays the Update and Delete buttons for a target.
"""
return {'target': target}
return {'target': target,
'sharing': getattr(settings, "DATA_SHARING", None)}


@register.inclusion_tag('tom_targets/partials/target_data.html')
Expand Down
10 changes: 10 additions & 0 deletions tom_targets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,16 @@ class TargetGroupingView(PermissionListMixin, ListView):
model = TargetList
paginate_by = 25

def get_context_data(self, *args, **kwargs):
"""
Adds ``settings.DATA_SHARING`` to the context to see if sharing has been configured.
:returns: context object
:rtype: dict
"""
context = super().get_context_data(*args, **kwargs)
context['sharing'] = getattr(settings, "DATA_SHARING", None)
return context


class TargetGroupingDeleteView(Raise403PermissionRequiredMixin, DeleteView):
"""
Expand Down

0 comments on commit 9750f2a

Please sign in to comment.