summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Zamotaev <nzamotaev@luxoft.com>2018-05-30 17:48:03 +0300
committerNikolay Zamotaev <nzamotaev@luxoft.com>2018-06-20 12:32:45 +0000
commita3a904bb9733ff88a83e8fdf940d6d1890b4c6ae (patch)
treea22518939eeed19b21bb90fdabeba36d0b1cd2ca
parentb129d99669dfbb81e8f71d8f2531e72285d1c698 (diff)
[deployment-server] Implemented "All" metacategory
The change was done to add ability to see full list of applications in neptune3-ui. It also includes code for setting up a virtual environment from which to run the server. Change-Id: Ib33b31a5f334fcc8c3a32ef7eff093bc364d9df5 Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
-rw-r--r--.gitignore2
-rw-r--r--README.md8
-rw-r--r--appstore/settings.py2
-rw-r--r--requirements.txt12
-rw-r--r--store/admin.py19
-rw-r--r--store/api.py11
-rw-r--r--store/migrations/0001_initial.py3
-rw-r--r--store/models.py25
-rw-r--r--store/static/img/admin/arrow-down.gifbin0 -> 105 bytes
-rw-r--r--store/static/img/admin/arrow-up.gifbin0 -> 105 bytes
10 files changed, 59 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
index cdf247c..1baae07 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,5 @@
db.sqlite3
media/
certificates/
+.idea/*
+venv/*
diff --git a/README.md b/README.md
index e229442..9f38da1 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,14 @@ the Neptune IVI UI and the Pelagicore Application Manager.
Architecture
============
+Setting up the server in virtualenv:
+
+virtualenv ./venv
+./venv/bin/pip install -r requirements.txt
+
+(libffi-dev is also needed)
+
+
The server is based on Python/Django.
The reference platform is Debian Jessie and the packages needed there are:
diff --git a/appstore/settings.py b/appstore/settings.py
index d8111e7..f3bb472 100644
--- a/appstore/settings.py
+++ b/appstore/settings.py
@@ -40,7 +40,7 @@ https://docs.djangoproject.com/en/1.7/ref/settings/
"""
APPSTORE_MAINTENANCE = False
-APPSTORE_PLATFORM_ID = 'AM'
+APPSTORE_PLATFORM_ID = 'NEPTUNE3'
APPSTORE_PLATFORM_VERSION = 1
APPSTORE_DOWNLOAD_EXPIRY = 10 # in minutes
APPSTORE_BIND_TO_DEVICE_ID = True # unique downloads for each device
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..6f033fe
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,12 @@
+pkg-resources==0.0.0
+PyYAML
+django==1.7.9
+django-common
+pyOpenSSL
+M2Crypto
+Enum34
+ipaddress
+cffi
+paramiko
+cryptography
+
diff --git a/store/admin.py b/store/admin.py
index a009d07..7eb07a1 100644
--- a/store/admin.py
+++ b/store/admin.py
@@ -44,8 +44,21 @@ from store.models import *
from utilities import parseAndValidatePackageMetadata
from utilities import iconPath
+class CategoryAdminForm(forms.ModelForm):
+ class Meta:
+ exclude = ["id", "rank"]
+
+ def save(self, commit=False):
+ m = super(CategoryAdminForm, self).save(commit)
+ try:
+ test = Category.objects.all().order_by('-rank')[:1].values('rank')[0]['rank'] + 1
+ except:
+ test = 0
+ m.rank = test
+ return m
class CategoryAdmin(admin.ModelAdmin):
+ form = CategoryAdminForm
list_display = ('name', 'move')
ordering = ('rank',)
@@ -57,7 +70,7 @@ class CategoryAdmin(admin.ModelAdmin):
return obj.name
name.short_description = ugettext_lazy('Item caption')
- def move(sefl, obj):
+ def move(self, obj):
"""
Returns html with links to move_up and move_down views.
"""
@@ -90,7 +103,7 @@ class CategoryAdmin(admin.ModelAdmin):
item.decrease_rank()
else:
raise PermissionDenied
- return redirect('admin:appstore_category_changelist')
+ return redirect('admin:store_category_changelist')
def move_down(self, request, item_pk):
"""
@@ -102,7 +115,7 @@ class CategoryAdmin(admin.ModelAdmin):
item.increase_rank()
else:
raise PermissionDenied
- return redirect('admin:appstore_category_changelist')
+ return redirect('admin:store_category_changelist')
class AppAdminForm(forms.ModelForm):
diff --git a/store/api.py b/store/api.py
index bcd2c82..a6e4c9a 100644
--- a/store/api.py
+++ b/store/api.py
@@ -98,9 +98,7 @@ def appList(request):
apps = apps.filter(name__contains = request.REQUEST['filter'])
if 'category_id' in request.REQUEST:
catId = request.REQUEST['category_id']
- if catId == '0':
- apps = apps.filter(isTopApp__exact = True)
- else:
+ if catId != -1: # All metacategory
apps = apps.filter(category__exact = catId)
appList = list(apps.values('id', 'name', 'vendor__name', 'rating', 'price', 'briefDescription', 'category'))
@@ -186,7 +184,10 @@ def appDownload(request, path):
def categoryList(request):
# this is not valid JSON, since we are returning a list!
- return JsonResponse(list(Category.objects.all().order_by('rank').values('id', 'name')), safe = False)
+ allmeta = [{'id': -1, 'name': 'All'}, ] #All metacategory
+ categoryobject = Category.objects.all().order_by('rank').values('id', 'name')
+ categoryobject=allmeta + list(categoryobject)
+ return JsonResponse(categoryobject, safe = False)
def categoryIcon(request):
@@ -194,7 +195,7 @@ def categoryIcon(request):
# there are no category icons (yet), so we just return the icon of the first app in this category
try:
- app = App.objects.filter(category__exact = request.REQUEST['id']).order_by('-dateModified')[0]
+ app = App.objects.filter(category__exact = request.REQUEST['id']).order_by('-dateModified')[0] #FIXME - the category icon is unimplemented
with open(iconPath(app.id), 'rb') as iconPng:
response.write(iconPng.read())
except:
diff --git a/store/migrations/0001_initial.py b/store/migrations/0001_initial.py
index 56a3af0..496cde9 100644
--- a/store/migrations/0001_initial.py
+++ b/store/migrations/0001_initial.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
#############################################################################
##
## Copyright (C) 2016 Pelagicore AG
@@ -48,7 +49,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.CharField(max_length=200, serialize=False, primary_key=True)),
('name', models.CharField(max_length=200)),
- ('file', models.FileField(upload_to=store.models.content_file_name)),
+ ('file', models.FileField(storage=store.models.OverwriteStorage(), upload_to=store.models.content_file_name)),
('briefDescription', models.TextField()),
('description', models.TextField()),
('dateAdded', models.DateField(auto_now_add=True)),
diff --git a/store/models.py b/store/models.py
index d1a05f1..e305045 100644
--- a/store/models.py
+++ b/store/models.py
@@ -48,21 +48,21 @@ class Category(models.Model):
def is_first(self):
"""
-Returns ``True`` if item is the first one in the menu.
-"""
+ Returns ``True`` if item is the first one in the menu.
+ """
return Category.objects.filter(rank__lt = self.rank).count() == 0
def is_last(self):
"""
-Returns ``True`` if item is the last one in the menu.
-"""
+ Returns ``True`` if item is the last one in the menu.
+ """
return Category.objects.filter(rank__gt = self.rank).count() == 0
def increase_rank(self):
"""
-Changes position of this item with the next item in the
-menu. Does nothing if this item is the last one.
-"""
+ Changes position of this item with the next item in the
+ menu. Does nothing if this item is the last one.
+ """
try:
next_item = Category.objects.filter(rank__gt = self.rank)[0]
except IndexError:
@@ -72,9 +72,9 @@ menu. Does nothing if this item is the last one.
def decrease_rank(self):
"""
-Changes position of this item with the previous item in the
-menu. Does nothing if this item is the first one.
-"""
+ Changes position of this item with the previous item in the
+ menu. Does nothing if this item is the first one.
+ """
try:
list = Category.objects.filter(rank__lt = self.rank).reverse()
prev_item = list[len(list) - 1]
@@ -85,10 +85,9 @@ menu. Does nothing if this item is the first one.
def swap_ranks(self, other):
"""
-Swap positions with ``other`` menu item.
-"""
+ Swap positions with ``other`` menu item.
+ """
maxrank = 5000
- print(maxrank)
prev_rank, self.rank = self.rank, maxrank
self.save()
self.rank, other.rank = other.rank, prev_rank
diff --git a/store/static/img/admin/arrow-down.gif b/store/static/img/admin/arrow-down.gif
new file mode 100644
index 0000000..96d0c03
--- /dev/null
+++ b/store/static/img/admin/arrow-down.gif
Binary files differ
diff --git a/store/static/img/admin/arrow-up.gif b/store/static/img/admin/arrow-up.gif
new file mode 100644
index 0000000..cf2f2e0
--- /dev/null
+++ b/store/static/img/admin/arrow-up.gif
Binary files differ