-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from N5GEH/3-Work-on-projects-application
Work on projects application
- Loading branch information
Showing
14 changed files
with
231 additions
and
14 deletions.
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
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,19 @@ | ||
from crispy_forms.helper import FormHelper | ||
from crispy_forms.layout import Submit | ||
from django import forms | ||
from .models import Project | ||
|
||
|
||
class ProjectForm(forms.ModelForm): | ||
def __init__(self, *args, **kwargs): | ||
super(ProjectForm, self).__init__(*args, **kwargs) | ||
|
||
self.helper = FormHelper(self) | ||
|
||
self.helper.layout.append(Submit(name="save", value="Save")) | ||
|
||
class Meta: | ||
model = Project | ||
fields = ['name', 'description', 'fiware_service', 'webpage_url','logo'] | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% extends '_base.html' %} | ||
{% load crispy_forms_tags %} | ||
|
||
{% block content %} | ||
|
||
<div class="container"> | ||
<h2 class="my-4">{% if project.name %} Edit {{ project.name }} {% else %} Create New Project {% endif %}</h2> | ||
<form action="" method="post" enctype="multipart/form-data" | ||
{% if form_submitted %}class="was-validated" {% endif %}> | ||
{% csrf_token %} | ||
{% crispy form %} | ||
</form> | ||
</div> | ||
|
||
{% endblock %} |
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from django.contrib.auth.decorators import login_required | ||
from django.urls import path, include | ||
from django.urls import path | ||
|
||
from projects.views import Index | ||
from . import views | ||
|
||
app_name = "projects" | ||
urlpatterns = [ | ||
path("", login_required(Index.as_view()), name="projects"), | ||
path("<str:project_id>/alarming/", include("alarming.urls")), | ||
path("", login_required(views.Index.as_view()), name="index"), | ||
path("create", views.Create.as_view(), name="create"), | ||
path("<str:pk>/update", views.Update.as_view(), name="update"), | ||
path("<str:pk>/delete", views.Delete.as_view(), name="delete") | ||
] |
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 |
---|---|---|
@@ -1,3 +1,42 @@ | ||
from django.shortcuts import render | ||
from django.urls import reverse | ||
from django.views.generic import View | ||
from django.views.generic.edit import UpdateView, CreateView, \ | ||
DeleteView | ||
|
||
# Create your views here. | ||
from .forms import ProjectForm | ||
from .models import Project | ||
|
||
|
||
class Index(View): | ||
def get(self, request): | ||
projects = Project.objects.filter( | ||
name__icontains=request.GET.get('search', default="")) | ||
context = {'project_list': projects} | ||
return render(request, 'projects/index.html', context) | ||
|
||
|
||
class Update(UpdateView): | ||
model = Project | ||
template_name = 'projects/detail.html' | ||
form_class = ProjectForm | ||
|
||
def get_success_url(self): | ||
return reverse("projects:index") | ||
|
||
|
||
class Create(CreateView): | ||
model = Project | ||
template_name = 'projects/detail.html' | ||
form_class = ProjectForm | ||
|
||
def get_success_url(self): | ||
return reverse("projects:index") | ||
|
||
|
||
class Delete(DeleteView): | ||
model = Project | ||
template_name = 'projects/index.html' | ||
|
||
def get_success_url(self): | ||
return reverse("projects:index") |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
var deleteModal = document.getElementById('deleteModal') | ||
deleteModal.addEventListener('show.bs.modal', function (event) { | ||
// Button that triggered the modal | ||
var button = event.relatedTarget | ||
// Extract info from data-bs-* attribute | ||
var url = button.getAttribute('data-bs-url') | ||
|
||
var modalForm = deleteModal.querySelector('.modal-form') | ||
modalForm.attributes.getNamedItem('action').value = url | ||
}) |
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
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