{"id":23412702,"url":"https://github.com/leobitto/django-calendar","last_synced_at":"2025-04-09T04:10:43.912Z","repository":{"id":214766956,"uuid":"737299555","full_name":"leoBitto/Django-calendar","owner":"leoBitto","description":"An app to visualize a calendar inside django","archived":false,"fork":false,"pushed_at":"2024-01-03T14:46:59.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T22:31:42.163Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://leobitto.github.io/django-calendar/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leoBitto.png","metadata":{"files":{"readme":"docs/README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-30T14:31:12.000Z","updated_at":"2024-01-03T14:54:49.000Z","dependencies_parsed_at":"2024-01-01T17:22:42.180Z","dependency_job_id":"fec662e6-5a80-43ae-a8d5-a163dbc84ddc","html_url":"https://github.com/leoBitto/Django-calendar","commit_stats":null,"previous_names":["leobitto/django-calendar"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoBitto%2FDjango-calendar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoBitto%2FDjango-calendar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoBitto%2FDjango-calendar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leoBitto%2FDjango-calendar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leoBitto","download_url":"https://codeload.github.com/leoBitto/Django-calendar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247974731,"owners_count":21026742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-22T18:18:03.964Z","updated_at":"2025-04-09T04:10:43.907Z","avatar_url":"https://github.com/leoBitto.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Calendar App Documentation\n\n## Introduction\n\nWelcome to the documentation for the Calendar app! This app is designed to manage events and link them to custom models with a \"date\" field. The documentation will cover installation, configuration, and basic usage of the app.\n\n## Installation\n\nTo get started, make sure you have Django installed in your project. After cloning this repo inside the project,\n\nAdd 'calendar_app' to your installed apps in `settings.py`:\n\n```python\nINSTALLED_APPS = [\n    # ...\n    'calendar_app',\n    # ...\n]\n```\n\nRun migrations:\n\n```bash\npython manage.py makemigrations\npython manage.py migrate\n```\n\n## Configuration\n\n### Signals\n\nSignals are used to automatically create `EventLink` instances when a linked object is created or deleted, when a linked object is deleted the event is deeted as well:\n\n```python\n# In the signals.py file\nfrom django.db.models.signals import post_save, pre_delete\nfrom django.dispatch import receiver\nfrom django.apps import apps\nfrom django.contrib.contenttypes.models import ContentType\nfrom .models import EventLink\n\n@receiver(post_save)\ndef create_event_link(sender, instance, created, **kwargs):\n    if created and has_date_field(instance):\n        # Create an EventLink instance associated with the object\n        EventLink.objects.create(\n            object_date=get_date_field_value(instance),\n            content_type=ContentType.objects.get_for_model(sender),\n            object_id=instance.id,\n        )\n\n@receiver(pre_delete)\ndef delete_event_link(sender, instance, **kwargs):\n    try:\n        # Try to get the value of the 'object_date' field\n        object_date = getattr(instance, 'date', None)\n\n        if object_date:\n            # Find and delete the EventLink associated with the object about to be deleted\n            content_type = ContentType.objects.get_for_model(sender)\n            event_link = EventLink.objects.filter(\n                content_type=content_type,\n                object_id=instance.id,\n                object_date=object_date\n            ).first()\n\n            if event_link:\n                event_link.delete()\n    except Exception as e:\n        # Handle any exceptions during execution\n        pass\n\ndef has_date_field(instance):\n    # Check if the object has a 'date' field (add other fields if necessary)\n    return hasattr(instance, 'date')\n\ndef get_date_field_value(instance):\n    # Get the value of the 'date' field (add other fields if necessary)\n    return getattr(instance, 'date', None)\n```\n\n# In the apps.py file\n``` python\n\n# Add the signal to the `apps.py` file:\nfrom django.apps import AppConfig\n\nclass CalendarAppConfig(AppConfig):\n    default_auto_field = 'django.db.models.BigAutoField'\n    name = 'calendar_app'\n\n    def ready(self):\n        import calendar_app.signals  # Import the signals module\n```\n\n## Using the App\n\n### Managing Events\n\nEvents are managed through the `EventLink` model. You can get events for a specific month using the `get_events_for_month` function in the `views.py` file:\n\n```python\n# In the views.py file\nimport calendar as cal_module\nfrom django.shortcuts import render\nfrom .models import EventLink\nfrom datetime import datetime, date\nfrom dateutil.relativedelta import relativedelta\n\ndef monthly_calendar(request, year, month):\n    # Logic to get the month's calendar\n    calendar_data = cal_module.monthcalendar(year, month)\n\n    # Logic to get the month's events\n    events = get_events_for_month(year, month)\n\n    # Calculate the previous and next month\n    prev_month = get_previous_month(year, month)\n    next_month = get_next_month(year, month)\n\n    context = {\n        'calendar': calendar_data,\n        'events': events,\n        'year': year,\n        'month': month,\n        'prev_month': prev_month,\n        'next_month': next_month,\n    }\n\n    return render(request, 'calendar/monthly_calendar.html', context)\n\ndef get_events_for_month(year, month):\n    # Calculate the start and end date of the month\n    start_date = date(year, month, 1)\n    _, last_day = cal_module.monthrange(year, month)\n    end_date = start_date + relativedelta(day=last_day)\n\n    # Filter for events that have the date equal to the selected month\n    events = EventLink.objects.filter(\n        object_date__gte=start_date,\n        object_date__lte=end_date\n    )\n\n    return events\n\ndef get_next_month(year, month):\n    current_date = datetime(year, month, 1)\n    next_month = current_date + relativedelta(months=+1)\n    return next_month.year, next_month.month\n\ndef get_previous_month(year, month):\n    current_date = datetime(year, month, 1)\n    previous_month = current_date - relativedelta(months=1)\n    return previous_month.year, previous_month.month\n\ndef event_detail(request, event_id):\n    # Retrieve the event using the event_id\n    event = get_object_or_404(Event, id=event_id)\n\n    context = {\n        'event': event\n    }\n\n    return render(request, 'calendar/event_detail.html', context)\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleobitto%2Fdjango-calendar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleobitto%2Fdjango-calendar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleobitto%2Fdjango-calendar/lists"}