Add Authentication and Basic CRUD for Repos 49/37549/2
authorakhilbatra898 <akhil.batra@research.iiit.ac.in>
Sat, 15 Jul 2017 04:14:23 +0000 (09:44 +0530)
committerakhilbatra898 <akhil.batra@research.iiit.ac.in>
Sat, 15 Jul 2017 04:27:26 +0000 (09:57 +0530)
 - Map urls to the CRUD views
 - Add html templates for the views
 - Set authentication settings

Change-Id: Ifcfe39a8341d44376e322d195e995fcaa1716d7d
Signed-off-by: akhilbatra898 <akhil.batra@research.iiit.ac.in>
qtip/web/bench/migrations/0004_auto_20170715_0325.py [new file with mode: 0644]
qtip/web/bench/models.py
qtip/web/bench/urls.py [new file with mode: 0644]
qtip/web/bench/views.py
qtip/web/templates/bench/base.html [new file with mode: 0644]
qtip/web/templates/bench/repo_form.html [new file with mode: 0644]
qtip/web/templates/registration/login.html [new file with mode: 0644]
qtip/web/web/settings.py
qtip/web/web/urls.py

diff --git a/qtip/web/bench/migrations/0004_auto_20170715_0325.py b/qtip/web/bench/migrations/0004_auto_20170715_0325.py
new file mode 100644 (file)
index 0000000..74296cc
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.3 on 2017-07-15 03:25
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('bench', '0003_auto_20170713_0225'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='repo',
+            name='name',
+            field=models.CharField(max_length=200),
+        ),
+    ]
index 0594dbd..863af73 100644 (file)
@@ -11,6 +11,7 @@
 from __future__ import unicode_literals
 
 from django.db import models
+from django.urls import reverse
 
 # Create your models here.
 
@@ -19,6 +20,9 @@ class Repo(models.Model):
     name = models.CharField(max_length=200, blank=False)
     github_link = models.URLField(unique=True)
 
+    def get_absolute_url(self):
+        return reverse('repo_update', args=[self.pk])
+
 
 class Task(models.Model):
     start_time = models.DateTimeField(auto_now_add=True)
diff --git a/qtip/web/bench/urls.py b/qtip/web/bench/urls.py
new file mode 100644 (file)
index 0000000..3af4eb8
--- /dev/null
@@ -0,0 +1,21 @@
+##############################################################################
+# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.conf.urls import include, url
+
+import views
+
+urlpatterns = [
+    url('^', include('django.contrib.auth.urls')),
+    url('^repos/$', views.ReposView.as_view(), name='repos'),
+    url('^repos/(?P<pk>\d+)$', views.RepoUpdate.as_view(), name='repo_update'),
+]
index da5c56c..786b67d 100644 (file)
@@ -1,6 +1,41 @@
+##############################################################################
+# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
+from django.contrib.auth.mixins import LoginRequiredMixin
+# from django.utils.decorators import method_decorator
+from django.views.generic.edit import CreateView, UpdateView
+
+import models
+
 # from django.shortcuts import render
 
 # Create your views here.
+
+
+class ReposView(LoginRequiredMixin, CreateView):
+    model = models.Repo
+    fields = '__all__'
+
+    def get_context_data(self, **kwargs):
+        context = super(ReposView, self).get_context_data(**kwargs)
+        context["repos"] = self.model.objects.all()
+        return context
+
+
+class RepoUpdate(LoginRequiredMixin, UpdateView):
+    model = models.Repo
+    fields = '__all__'
+
+    def get_context_data(self, **kwargs):
+        context = super(RepoUpdate, self).get_context_data(**kwargs)
+        context["repos"] = self.model.objects.all()
+        return context
diff --git a/qtip/web/templates/bench/base.html b/qtip/web/templates/bench/base.html
new file mode 100644 (file)
index 0000000..f0d3610
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <title>QTIP Benchmarking Services</title>
+    </head>
+    <body>
+        {% block content %}
+        {% endblock %}
+    </body>
+</html>
\ No newline at end of file
diff --git a/qtip/web/templates/bench/repo_form.html b/qtip/web/templates/bench/repo_form.html
new file mode 100644 (file)
index 0000000..109436a
--- /dev/null
@@ -0,0 +1,15 @@
+{% extends 'bench/base.html' %}
+{% block content %}
+    <div>
+        <h3>Repos</h3>
+        {% for repo in repos %}
+        <li>{{ repo.name }}</li>
+        {% endfor %}
+    </div>
+    <form role="form" method="post" action="">{% csrf_token %}
+        {{ form }}
+        <div class=input-field" style="margin:30px 20px">
+            <button  type="submit" value="Login"/>Submit</button>
+        </div>
+    </form>
+{% endblock %}
diff --git a/qtip/web/templates/registration/login.html b/qtip/web/templates/registration/login.html
new file mode 100644 (file)
index 0000000..53da937
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <title>QTIP Benchmarking Services</title>
+    </head>
+    <body>
+        {% block content %}
+        <form role="form" method="post" action= "/bench/login/">{% csrf_token %}
+        {{ form }}
+            <div class=input-field" style="margin:30px 20px">
+                <button  type="submit" value="Login"/>Login</button>
+                <input type="hidden" name="next" value = "{{ next }}"/>
+            </div>
+        </form>
+        {% endblock %}
+    </body>
+</html>
\ No newline at end of file
index 30bb6e3..8963ea8 100644 (file)
@@ -55,7 +55,7 @@ ROOT_URLCONF = 'web.urls'
 TEMPLATES = [
     {
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
-        'DIRS': [],
+        'DIRS': ['templates'],
         'APP_DIRS': True,
         'OPTIONS': {
             'context_processors': [
@@ -119,3 +119,8 @@ USE_TZ = True
 # https://docs.djangoproject.com/en/1.11/howto/static-files/
 
 STATIC_URL = '/static/'
+
+# Auth Settings
+LOGIN_URL = '/bench/login/'
+LOGIN_REDIRECT_URL = '/bench/dashboard/'
+LOGOUT_REDIRECT_URL = LOGIN_URL
index b0de5fe..49aaeb9 100644 (file)
@@ -13,9 +13,10 @@ Including another URLconf
     1. Import the include() function: from django.conf.urls import url, include
     2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
 """
-from django.conf.urls import url
+from django.conf.urls import include, url
 from django.contrib import admin
 
 urlpatterns = [
+    url(r'^bench/', include('bench.urls')),
     url(r'^admin/', admin.site.urls),
 ]