-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Harshith Pabbati <pabbatiharshith@gmail.com>
- Loading branch information
1 parent
8fdc9a7
commit 0d6246c
Showing
8 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
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,14 @@ | ||
from django.contrib import admin | ||
from .models import * | ||
from import_export.admin import ImportExportModelAdmin, ExportActionMixin | ||
|
||
|
||
@admin.register(Event) | ||
class EventsAdmin(ImportExportModelAdmin, ExportActionMixin, admin.ModelAdmin): | ||
fields = [ | ||
('name', 'slug'), | ||
('date', 'creator', 'album'), | ||
'content' | ||
] | ||
|
||
list_display = ('name', 'slug', 'date', 'creator') |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class EventsConfig(AppConfig): | ||
name = 'events' |
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,20 @@ | ||
from django.db import models | ||
from gallery.models import Album | ||
from django.contrib.auth.models import User | ||
from django.utils import timezone | ||
|
||
|
||
class Event(models.Model): | ||
name = models.CharField(max_length=50, blank=True, verbose_name='Title of the event') | ||
slug = models.CharField(max_length=50, blank=True, verbose_name='Slug') | ||
content = models.TextField(blank=True, null=True, verbose_name='Content') | ||
date = models.DateTimeField(verbose_name="Event Date", default=timezone.now) | ||
album = models.ForeignKey(Album, on_delete=models.CASCADE, null=True) | ||
creator = models.OneToOneField(User, on_delete=models.CASCADE, related_name='Events', verbose_name='User', null=True, blank=True) | ||
|
||
class Meta: | ||
verbose_name_plural = "Events" | ||
verbose_name = "Event" | ||
|
||
def __str__(self): | ||
return self.name |
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,52 @@ | ||
import graphene | ||
from framework.api.user import UserBasicObj | ||
from events.models import * | ||
from framework.api.APIException import APIException | ||
from gallery.models import Album | ||
from gallery.schema import AlbumObj | ||
|
||
|
||
class EventsObj(graphene.ObjectType): | ||
title = graphene.String() | ||
slug = graphene.String() | ||
content = graphene.String() | ||
creator = graphene.Field(UserBasicObj) | ||
date = graphene.DateTime() | ||
album = graphene.Field(AlbumObj) | ||
|
||
def resolve_title(self, info): | ||
return self['name'] | ||
|
||
def resolve_slug(self, info): | ||
return self['slug'] | ||
|
||
def resolve_content(self, info): | ||
return self['content'] | ||
|
||
def resolve_creator(self, info): | ||
return User.objects.values().get(id=self['creator_id']) | ||
|
||
def resolve_date(self, info): | ||
return self['date'] | ||
|
||
def resolve_album(self, info): | ||
return Album.objects.values().get(id=self['album_id']) | ||
|
||
|
||
class Query(graphene.ObjectType): | ||
events = graphene.List(EventsObj) | ||
event = graphene.Field(EventsObj, slug=graphene.String(required=True)) | ||
|
||
def resolve_events(self, info): | ||
return Event.objects.values().all() | ||
|
||
def resolve_event(self, info, **kwargs): | ||
slug = kwargs.get('slug') | ||
if slug is not None: | ||
return Event.objects.values().get(slug=slug) | ||
else: | ||
raise APIException('Slug is required', | ||
code='SLUG_IS_REQUIRED') | ||
|
||
|
||
schema = graphene.Schema(query=Query) |
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,20 @@ | ||
from django.test import TestCase | ||
from datetime import datetime | ||
from .models import Event | ||
|
||
|
||
class EventTest(TestCase): | ||
|
||
def setUp(self): | ||
Event.objects.create( | ||
name = "The Open Talks 2020", | ||
slug = "open-talks", | ||
content = "The open talks 2020 was conducted on Februaury 15 by amFOSS in Amritapuri" | ||
) | ||
|
||
def test_event_fields(self): | ||
events = Event.objects.get(name="The Open Talks 2020") | ||
|
||
self.assertEquals(events.name,'The Open Talks 2020') | ||
self.assertEquals(events.slug,'open-talks') | ||
self.assertEquals(events.content,'The open talks 2020 was conducted on Februaury 15 by amFOSS in Amritapuri') |
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