Commit ebb4929a by Szabolcs Gelencser

Add favorite mark, display on detail page

parent 583f2684
No preview for this file type
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-04-20 08:54
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0007_profile_network_limit'),
]
operations = [
migrations.AlterField(
model_name='favourite',
name='instance',
field=models.CharField(max_length=50),
),
migrations.AlterField(
model_name='favourite',
name='user',
field=models.CharField(max_length=50),
),
]
...@@ -82,8 +82,8 @@ class Message(TimeStampedModel, TimeFramedModel): ...@@ -82,8 +82,8 @@ class Message(TimeStampedModel, TimeFramedModel):
class Favourite(Model): class Favourite(Model):
instance = ForeignKey("vm.Instance") instance = CharField(max_length=50, blank=False)
user = ForeignKey(User) user = CharField(max_length=50, blank=False)
class Notification(TimeStampedModel): class Notification(TimeStampedModel):
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
{{ instance.name }} {{ instance.name }}
</div> </div>
<small>{{ instance.primary_host.get_fqdn }}</small> <small>{{ instance.primary_host.get_fqdn }}</small>
<small class="dashboard-vm-favourite" style="line-height: 39.6px;" data-vm="{{ instance.pk }}"> <small class="dashboard-vm-favourite" style="line-height: 39.6px;" data-vm="{{ instance.id }}">
{% if fav %} {% if fav %}
<i class="fa fa-star text-primary title-favourite" title="{% trans "Unfavourite" %}"></i> <i class="fa fa-star text-primary title-favourite" title="{% trans "Unfavourite" %}"></i>
{% else %} {% else %}
......
...@@ -137,7 +137,7 @@ class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView): ...@@ -137,7 +137,7 @@ class VmDetailView(LoginRequiredMixin, GraphMixin, DetailView):
'op': {i.op: i for i in ops}, 'op': {i.op: i for i in ops},
# 'connect_commands': user.profile.get_connect_commands(instance), # 'connect_commands': user.profile.get_connect_commands(instance),
'hide_tutorial': hide_tutorial, 'hide_tutorial': hide_tutorial,
'fav': [], #instance.favourite_set.filter(user=user).exists(), 'fav': Favourite.objects.filter(user=user.id, instance=instance.id).exists(),
'instance': self.object 'instance': self.object
}) })
...@@ -1392,15 +1392,13 @@ def vm_activity(request, pk): ...@@ -1392,15 +1392,13 @@ def vm_activity(request, pk):
class FavouriteView(TemplateView): class FavouriteView(TemplateView):
def post(self, *args, **kwargs): def post(self, *args, **kwargs):
user = self.request.user user_id = self.request.user.id
vm = Instance.objects.get(pk=self.request.POST.get("vm")) vm_id = self.request.POST.get("vm")
if not vm.has_level(user, 'user'):
raise PermissionDenied()
try: try:
Favourite.objects.get(instance=vm, user=user).delete() Favourite.objects.get(instance=vm_id, user=user_id).delete()
return HttpResponse("Deleted.") return HttpResponse("Deleted.")
except Favourite.DoesNotExist: except Favourite.DoesNotExist:
Favourite(instance=vm, user=user).save() Favourite(instance=vm_id, user=user_id).save()
return HttpResponse("Added.") return HttpResponse("Added.")
# #
# #
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-04-20 08:54
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('request', '0005_auto_20180403_1342'),
]
operations = [
migrations.AlterModelOptions(
name='request',
options={},
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-04-20 08:54
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('vm', '0010_auto_20180313_1628'),
]
operations = [
migrations.RemoveField(
model_name='node',
name='host',
),
migrations.RemoveField(
model_name='node',
name='tags',
),
migrations.RemoveField(
model_name='node',
name='traits',
),
migrations.RemoveField(
model_name='nodeactivity',
name='node',
),
migrations.RemoveField(
model_name='nodeactivity',
name='parent',
),
migrations.RemoveField(
model_name='nodeactivity',
name='user',
),
migrations.RemoveField(
model_name='instance',
name='node',
),
migrations.DeleteModel(
name='Node',
),
migrations.DeleteModel(
name='NodeActivity',
),
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment