diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..1f35c1436a423986da8bba6848b435c44a340e3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,81 @@ +# Meta +django-template-heroku-template.* + +# Virtual environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Python cache files +__pycache__/ + +# SQLite database +db.sqlite3 +db.sqlite3-journal + +# User-uploaded media +media + +# Collected static files +staticfiles/ + +# Coverage +.coverage +.coverage.* +coverage.* +htmlcov/ + +# Chromedriver +chromedriver +chromedriver.exe + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows shortcuts +*.lnk diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..16e0752539472d84cf21ed16dd50776cafe5dcee --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,18 @@ +image: python:3.8 +stages: + - deploy + +Deployment: + rules: + - if: '$CI_COMMIT_REF_NAME == "main"' + image: ruby:2.7 + stage: deploy + before_script: + - gem install dpl + - wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh + script: + - dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_API_KEY + - heroku run --app $HEROKU_APP_NAME migrate + environment: + name: production + url: https://$HEROKU_APP_NAME.herokuapp.com diff --git a/Procfile b/Procfile new file mode 100644 index 0000000000000000000000000000000000000000..8d6a8b353af50829344d4b216121490fddb33cce --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +migrate: python manage.py migrate +web: gunicorn remindme_log.wsgi diff --git a/README.md b/README.md index 253c04b6e70be558d5ae478163885be5aaa17636..cba45a1e1ad04e32d8ca94e2cbf6b80cfdef02bd 100644 --- a/README.md +++ b/README.md @@ -1,92 +1 @@ -# remindme-log - - - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.cs.ui.ac.id/remindme/remindme-log.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.cs.ui.ac.id/remindme/remindme-log/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +### RemindeMe! Log Service \ No newline at end of file diff --git a/log/__init__.py b/log/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/log/admin.py b/log/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..4318c630510cdb3887f160c26c37e9bb0b1aee4d --- /dev/null +++ b/log/admin.py @@ -0,0 +1,47 @@ +from django.contrib import admin +from django.contrib.auth.models import User +from django.contrib.auth.models import Group +from .models import Log, LogType + +# Register your models here. +class LogAdmin(admin.ModelAdmin): + list_display = ('id', + 'time', + 'service', + 'get_log_type', + 'host', + 'user', + 'method', + 'path', + 'code', + 'request_body', + 'response') + readonly_fields = list_display + + def get_log_type(self, obj): + logging_type = LogType.objects.get(id=obj.type.id) + return str(logging_type.name) + + def has_add_permission(self, request, obj=None): + return + + def has_delete_permission(self, request, obj=None): + return False + + def has_change_permission(self, request, obj=None): + return False + +class LogTypeAdmin(admin.ModelAdmin): + list_display = ('id', + 'name') + readonly_fields = list_display + + +admin.site.register(Log, LogAdmin) +admin.site.register(LogType, LogTypeAdmin) +admin.site.unregister(User) +admin.site.unregister(Group) + +admin.site.site_header = "RemindMe! Log Site" +admin.site.site_title = "Log" +admin.site.index_title = "RemindMe!" \ No newline at end of file diff --git a/log/apps.py b/log/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..514f844a905cd93a3a6cd9a597df84fe6b8bdfb9 --- /dev/null +++ b/log/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + +class LogConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'log' diff --git a/log/migrations/0001_initial.py b/log/migrations/0001_initial.py new file mode 100644 index 0000000000000000000000000000000000000000..40da884f183377206e47e6577b440ff1fbc25af1 --- /dev/null +++ b/log/migrations/0001_initial.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2.13 on 2022-05-26 08:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Log', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('time', models.DateTimeField()), + ('service', models.DateTimeField()), + ('host', models.CharField(max_length=100)), + ('user', models.CharField(default='guest', max_length=100)), + ('method', models.CharField(max_length=6)), + ('path', models.IntegerField(max_length=3)), + ('size', models.IntegerField()), + ], + ), + ] diff --git a/log/migrations/0002_auto_20220526_1856.py b/log/migrations/0002_auto_20220526_1856.py new file mode 100644 index 0000000000000000000000000000000000000000..95abf6ab9bd4e8385b037022bd094d5640215a6c --- /dev/null +++ b/log/migrations/0002_auto_20220526_1856.py @@ -0,0 +1,54 @@ +# Generated by Django 3.2.13 on 2022-05-26 11:56 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('log', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='LogType', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(choices=[('INFO', 'INFO'), ('WARNING', 'WARNING'), ('ERROR', 'ERROR')], max_length=7)), + ], + ), + migrations.RenameField( + model_name='log', + old_name='size', + new_name='code', + ), + migrations.AddField( + model_name='log', + name='request_body', + field=models.TextField(default=''), + preserve_default=False, + ), + migrations.AddField( + model_name='log', + name='response', + field=models.TextField(default=''), + preserve_default=False, + ), + migrations.AlterField( + model_name='log', + name='path', + field=models.CharField(max_length=100), + ), + migrations.AlterField( + model_name='log', + name='service', + field=models.CharField(max_length=100), + ), + migrations.AddField( + model_name='log', + name='type', + field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='log.logtype'), + preserve_default=False, + ), + ] diff --git a/log/migrations/0003_alter_logtype_name.py b/log/migrations/0003_alter_logtype_name.py new file mode 100644 index 0000000000000000000000000000000000000000..948bfae6a39881541f0e6b389350954ec0b310be --- /dev/null +++ b/log/migrations/0003_alter_logtype_name.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.13 on 2022-05-26 12:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('log', '0002_auto_20220526_1856'), + ] + + operations = [ + migrations.AlterField( + model_name='logtype', + name='name', + field=models.CharField(max_length=7), + ), + ] diff --git a/log/migrations/0004_auto_20220526_2041.py b/log/migrations/0004_auto_20220526_2041.py new file mode 100644 index 0000000000000000000000000000000000000000..278c92e6f31dec6742ecbf2b151bce63cdd88fc8 --- /dev/null +++ b/log/migrations/0004_auto_20220526_2041.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.13 on 2022-05-26 13:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('log', '0003_alter_logtype_name'), + ] + + operations = [ + migrations.AlterField( + model_name='log', + name='request_body', + field=models.TextField(blank=True), + ), + migrations.AlterField( + model_name='log', + name='response', + field=models.TextField(blank=True), + ), + ] diff --git a/log/migrations/__init__.py b/log/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/log/models.py b/log/models.py new file mode 100644 index 0000000000000000000000000000000000000000..e7c0baa8f88f6d700d8d1265133fd708a7b09374 --- /dev/null +++ b/log/models.py @@ -0,0 +1,21 @@ +from django.db import models + +class LogType(models.Model): + name = models.CharField(max_length=7) + +class Log(models.Model): + time = models.DateTimeField() + service = models.CharField(max_length=100) + type = models.ForeignKey( + LogType, + on_delete=models.CASCADE + ) + host = models.CharField(max_length=100) + user = models.CharField(max_length=100, default="guest") + method = models.CharField(max_length=6) + path = models.CharField(max_length=100) + code = models.IntegerField() + request_body = models.TextField(blank=True) + response = models.TextField(blank=True) + + diff --git a/log/serializers.py b/log/serializers.py new file mode 100644 index 0000000000000000000000000000000000000000..eac0ad9d8f06d2308fe0f459bddf467cde4572c9 --- /dev/null +++ b/log/serializers.py @@ -0,0 +1,12 @@ +from rest_framework import serializers +from .models import Log, LogType + +class LogTypeSerializer(serializers.ModelSerializer): + class Meta: + model = LogType + fields = "__all__" + +class LogSerializer(serializers.ModelSerializer): + class Meta: + model = Log + fields = "__all__" \ No newline at end of file diff --git a/log/tests.py b/log/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/log/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/log/urls.py b/log/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..6b35879e0720a763ef70a43eef3d76de451534bf --- /dev/null +++ b/log/urls.py @@ -0,0 +1,10 @@ +from django.urls import path +from rest_framework.urlpatterns import format_suffix_patterns +from .views import ListLog, ListLogType + +urlpatterns = [ + path('log/', ListLog.as_view()), + path('log-type/', ListLogType.as_view()), +] + +urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/log/views.py b/log/views.py new file mode 100644 index 0000000000000000000000000000000000000000..b1f4d6914b655051cb639ea3cbf005df77f09ce9 --- /dev/null +++ b/log/views.py @@ -0,0 +1,32 @@ +from rest_framework import generics +from rest_framework.exceptions import ValidationError +from djangorestframework_camel_case.parser import (CamelCaseFormParser, + CamelCaseJSONParser, + CamelCaseMultiPartParser) +from djangorestframework_camel_case.render import (CamelCaseBrowsableAPIRenderer, + CamelCaseJSONRenderer) + +from .serializers import LogTypeSerializer, LogSerializer +from .models import LogType, Log + +class ListLog(generics.ListCreateAPIView): + serializer_class = LogSerializer + parser_classes = (CamelCaseMultiPartParser, CamelCaseFormParser, CamelCaseJSONParser) + renderer_classes = (CamelCaseJSONRenderer, CamelCaseBrowsableAPIRenderer) + + def get_queryset(self): + return Log.objects.all() + + def perform_create(self, serializer): + serializer.save() + +class ListLogType(generics.ListCreateAPIView): + serializer_class = LogTypeSerializer + parser_classes = (CamelCaseMultiPartParser, CamelCaseFormParser, CamelCaseJSONParser) + renderer_classes = (CamelCaseJSONRenderer, CamelCaseBrowsableAPIRenderer) + + def get_queryset(self): + return LogType.objects.all() + + def perform_create(self, serializer): + serializer.save() diff --git a/main/__init__.py b/main/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/main/admin.py b/main/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..8c38f3f3dad51e4585f3984282c2a4bec5349c1e --- /dev/null +++ b/main/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/main/apps.py b/main/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..833bff671ade712d855d40ff4a8740f568c1a86d --- /dev/null +++ b/main/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class MainConfig(AppConfig): + name = 'main' diff --git a/main/migrations/__init__.py b/main/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/main/models.py b/main/models.py new file mode 100644 index 0000000000000000000000000000000000000000..71a836239075aa6e6e4ecb700e9c42c95c022d91 --- /dev/null +++ b/main/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/main/static/img/django-logo-negative.svg b/main/static/img/django-logo-negative.svg new file mode 100644 index 0000000000000000000000000000000000000000..6a6d9b0625dc255df48ed9241b051f5d33794864 --- /dev/null +++ b/main/static/img/django-logo-negative.svg @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generator: Adobe Illustrator 12.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 51448) --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [ + <!ENTITY ns_svg "http://www.w3.org/2000/svg"> + <!ENTITY ns_xlink "http://www.w3.org/1999/xlink"> +]> +<svg version="1.0" id="Layer_1" xmlns="&ns_svg;" xmlns:xlink="&ns_xlink;" width="504.09" height="215.994" + viewBox="0 0 504.09 215.994" overflow="visible" enable-background="new 0 0 504.09 215.994" xml:space="preserve"> +<path fill="#092E20" d="M504.09,187.994c0,15.464-12.536,28-28,28H28c-15.464,0-28-12.536-28-28V28C0,12.536,12.536,0,28,0h448.09 + c15.464,0,28,12.536,28,28V187.994z"/> +<g> + <g> + <path fill="#FFFFFF" d="M86.945,33.919h23.872v110.496c-12.246,2.325-21.237,3.255-31.002,3.255 + c-29.142,0-44.333-13.174-44.333-38.443c0-24.336,16.122-40.147,41.078-40.147c3.875,0,6.82,0.311,10.386,1.239V33.919z + M86.945,89.539c-2.79-0.929-5.115-1.239-8.06-1.239c-12.091,0-19.067,7.441-19.067,20.46c0,12.713,6.666,19.688,18.912,19.688 + c2.634,0,4.805-0.155,8.215-0.618V89.539z"/> + <path fill="#FFFFFF" d="M148.793,70.783v55.341c0,19.065-1.395,28.21-5.58,36.117c-3.876,7.596-8.992,12.399-19.532,17.67 + l-22.167-10.541c10.541-4.96,15.656-9.297,18.911-15.966c3.411-6.819,4.497-14.727,4.497-35.498V70.783H148.793z M124.922,34.046 + h23.871v24.493h-23.871V34.046z"/> + <path fill="#FFFFFF" d="M163.212,76.209c10.542-4.961,20.617-7.13,31.623-7.13c12.246,0,20.306,3.255,23.872,9.611 + c2.014,3.564,2.634,8.214,2.634,18.137v48.517c-10.697,1.552-24.182,2.636-34.102,2.636c-19.996,0-28.988-6.977-28.988-22.476 + c0-16.744,11.936-24.493,41.234-26.975v-5.271c0-4.339-2.17-5.888-8.216-5.888c-8.835,0-18.756,2.479-28.058,7.285V76.209z + M200.57,114.187c-15.812,1.552-20.927,4.031-20.927,10.231c0,4.65,2.946,6.821,9.456,6.821c3.566,0,6.82-0.311,11.471-1.084 + V114.187z"/> + <path fill="#FFFFFF" d="M232.968,74.505c14.105-3.722,25.731-5.426,37.512-5.426c12.246,0,21.082,2.788,26.354,8.216 + c4.96,5.113,6.509,10.693,6.509,22.632v46.813h-23.871v-45.884c0-9.145-3.1-12.557-11.625-12.557c-3.255,0-6.2,0.311-11.007,1.706 + v56.734h-23.871V74.505z"/> + <path fill="#FFFFFF" d="M312.623,159.761c8.372,4.339,16.742,6.354,25.577,6.354c15.655,0,22.321-6.354,22.321-21.546 + c0-0.154,0-0.31,0-0.467c-4.65,2.326-9.301,3.257-15.5,3.257c-20.927,0-34.26-13.797-34.26-35.652 + c0-27.128,19.688-42.473,54.564-42.473c10.232,0,19.688,1.084,31.159,3.407l-8.174,17.222c-6.356-1.241-0.509-0.167-5.312-0.632 + v2.48l0.309,10.074l0.154,13.022c0.155,3.253,0.155,6.51,0.311,9.764c0,2.945,0,4.342,0,6.512c0,20.462-1.705,30.073-6.82,37.977 + c-7.441,11.627-20.307,17.362-38.598,17.362c-9.301,0-17.36-1.396-25.732-4.651V159.761z M360.057,88.455c-0.31,0-0.619,0-0.774,0 + h-1.706c-4.649-0.155-10.074,1.084-13.796,3.409c-5.734,3.257-8.681,9.146-8.681,17.518c0,11.937,5.892,18.756,16.432,18.756 + c3.255,0,5.891-0.62,8.99-1.55v-1.705v-6.51c0-2.79-0.154-5.892-0.154-9.146l-0.154-11.006l-0.156-7.905V88.455z"/> + <path fill="#FFFFFF" d="M433.543,68.77c23.871,0,38.443,15.037,38.443,39.371c0,24.957-15.19,40.613-39.373,40.613 + c-23.873,0-38.599-15.036-38.599-39.216C394.015,84.424,409.207,68.77,433.543,68.77z M433.076,129.533 + c9.147,0,14.573-7.596,14.573-20.773c0-13.019-5.271-20.771-14.415-20.771c-9.457,0-14.884,7.598-14.884,20.771 + C418.351,121.938,423.777,129.533,433.076,129.533z"/> + </g> +</g> +</svg> diff --git a/main/templates/main/home.html b/main/templates/main/home.html new file mode 100644 index 0000000000000000000000000000000000000000..8db10eaeb21f49edb7ffba4070f3004a794fa708 --- /dev/null +++ b/main/templates/main/home.html @@ -0,0 +1,10 @@ +{% extends 'base.html' %} +{% load static %} + +{% block meta %} +<title>RemindeMe! Log Service</title> +{% endblock meta %} + +{% block content %} + <h1>RemindeMe! Log Service</h1> +{% endblock content %} diff --git a/main/tests.py b/main/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..1d7a136d564dfbd85038cfd701175dc117c009de --- /dev/null +++ b/main/tests.py @@ -0,0 +1,41 @@ +from django.test import LiveServerTestCase, TestCase, tag +from django.urls import reverse +from selenium import webdriver + + +@tag('functional') +class FunctionalTestCase(LiveServerTestCase): + """Base class for functional test cases with selenium.""" + + @classmethod + def setUpClass(cls): + super().setUpClass() + # Change to another webdriver if desired (and update CI accordingly). + options = webdriver.chrome.options.Options() + # These options are needed for CI with Chromium. + options.headless = True # Disable GUI. + options.add_argument('--no-sandbox') + options.add_argument('--disable-dev-shm-usage') + cls.selenium = webdriver.Chrome(options=options) + + @classmethod + def tearDownClass(cls): + cls.selenium.quit() + super().tearDownClass() + + +class MainTestCase(TestCase): + def test_root_url_status_200(self): + response = self.client.get('/') + self.assertEqual(response.status_code, 200) + # You can also use path names instead of explicit paths. + response = self.client.get(reverse('main:home')) + self.assertEqual(response.status_code, 200) + + +class MainFunctionalTestCase(FunctionalTestCase): + def test_root_url_exists(self): + self.selenium.get(f'{self.live_server_url}/') + html = self.selenium.find_element_by_tag_name('html') + self.assertNotIn('not found', html.text.lower()) + self.assertNotIn('error', html.text.lower()) diff --git a/main/urls.py b/main/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..e6179c347da20e7b42e61e028a0cafe199866809 --- /dev/null +++ b/main/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from . import views + +app_name = 'main' + +urlpatterns = [ + path('', views.home, name='home'), +] diff --git a/main/views.py b/main/views.py new file mode 100644 index 0000000000000000000000000000000000000000..baea324616005abee11a57483242b699de18373b --- /dev/null +++ b/main/views.py @@ -0,0 +1,5 @@ +from django.shortcuts import render + + +def home(request): + return render(request, 'main/home.html') diff --git a/manage.py b/manage.py new file mode 100644 index 0000000000000000000000000000000000000000..f2777ed2905be7acb0ce546ee1c20b8ade8a21c3 --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'remindme_log.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/remindme_log/__init__.py b/remindme_log/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/remindme_log/asgi.py b/remindme_log/asgi.py new file mode 100644 index 0000000000000000000000000000000000000000..640e6425d3deff8077570e4fafcc8caad901f928 --- /dev/null +++ b/remindme_log/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for remindme_log project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'remindme_log.settings') + +application = get_asgi_application() diff --git a/remindme_log/settings.py b/remindme_log/settings.py new file mode 100644 index 0000000000000000000000000000000000000000..f61232e6592b9d893952f2d2cb82b8972b1810b0 --- /dev/null +++ b/remindme_log/settings.py @@ -0,0 +1,169 @@ +""" +Django settings for remindme_log project. + +Generated by 'django-admin startproject' using Django 3.2.13. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +import os +from pathlib import Path + +import dj_database_url + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ +# for best-practices. + +# SECURITY WARNING: keep the secret key used in production secret! +# Please set SECRET_KEY environment variable in your production environment +# (e.g. Heroku). +SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-rtov0$+fq$_v)#58&dz%v!-7i5jduaua*l9_c_&gy_ql+&$zg^') + +# Automatically determine environment by detecting if DATABASE_URL variable. +# DATABASE_URL is provided by Heroku if a database add-on is added +# (e.g. Heroku Postgres). +PRODUCTION = os.getenv('DATABASE_URL') is not None + +# SECURITY WARNING: don't run with debug turned on in production! +# If you want to enable debugging on Heroku for learning purposes, +# set this to True. +DEBUG = not PRODUCTION + +HEROKU_APP_NAME = os.getenv('HEROKU_APP_NAME', '') + +ALLOWED_HOSTS = [f'{HEROKU_APP_NAME}.herokuapp.com'] + +if not PRODUCTION: + ALLOWED_HOSTS += ['.localhost', '127.0.0.1', '[::1]'] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'main', + 'rest_framework', + 'log', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'remindme_log.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + BASE_DIR / 'templates', + ], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'remindme_log.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + +# Set database settings automatically using DATABASE_URL. +if PRODUCTION: + DATABASES['default'] = dj_database_url.config( + conn_max_age=600, ssl_require=True + ) + + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.2/topics/i18n/ +# Feel free to change these according to your needs. + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +# This is the directory for storing `collectstatic` results. +# This shouldn't be included in your Git repository. +STATIC_ROOT = BASE_DIR / 'staticfiles' + +# You can use this directory to store project-wide static files. +STATICFILES_DIRS = [ + BASE_DIR / 'static', +] + +# Make sure the directories exist to prevent errors when doing `collectstatic`. +for directory in [*STATICFILES_DIRS, STATIC_ROOT]: + directory.mkdir(exist_ok=True) + +# Enable compression and caching features of whitenoise. +# You can remove this if it causes problems on your setup. +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' + diff --git a/remindme_log/urls.py b/remindme_log/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..8efc8a649d4122015811bd231c5e2dd960fdf555 --- /dev/null +++ b/remindme_log/urls.py @@ -0,0 +1,23 @@ +"""remindme_log URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import include, path + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('main.urls')), + path('api/', include('log.urls')), +] diff --git a/remindme_log/wsgi.py b/remindme_log/wsgi.py new file mode 100644 index 0000000000000000000000000000000000000000..47a92c04e714eaadf6a3995042fec2c41163e8b1 --- /dev/null +++ b/remindme_log/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for remindme_log project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'remindme_log.settings') + +application = get_wsgi_application() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..957a9eb86022f8b368641ab89d10bbd62dadf833 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,15 @@ +coverage>=5.3,<6.0 +django-cors-headers==3.7.0 +dj-database-url>=0.5.0 +django-cors-headers==3.7.0 +djangogrpcframework>=0.2.1 +djangorestframework==3.11.0 +djangorestframework-camel-case==1.2.0 +djangorestframework-simplejwt>=4.4.0 +Django>=3.1.0,<4.0.0 +gunicorn>=20.0.0,<21.0.0 +grpcio>=1.46.3 +grpcio-tools>=1.5.2 +psycopg2-binary>=2.8.0,<3.0.0 +selenium>=3.141.0,<4.0.0 +whitenoise>=5.2.0,<6.0.0 diff --git a/static/css/style.css b/static/css/style.css new file mode 100644 index 0000000000000000000000000000000000000000..d24f73297e789e40c8de159dbbec33496daead30 --- /dev/null +++ b/static/css/style.css @@ -0,0 +1,7 @@ +/* Project-wide style */ + +@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@400;700&display=swap'); + +body { + font-family: 'Rubik', sans-serif; +} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000000000000000000000000000000000000..fd6ead8beb5dc710c3538bea1485c0abd05f4f59 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,18 @@ +{% load static %} +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <link rel="stylesheet" href="{% static 'css/style.css' %}"> + {% block meta %} + {% endblock meta %} +</head> + +<body> + {% block content %} + {% endblock content %} +</body> + +</html>