Beispiel #1
0
 def mutate(self,
            info,
            formID,
            name,
            email=None,
            phone=None,
            formData=None,
            slot=None):
     form = Form.objects.get(id=formID)
     if form.isActive:
         if form.submissionDeadline is None or datetime.now(
         ) < form.submissionDeadline:
             if email is not None or phone is not None:
                 apps = Entry.objects.filter((Q(email=email)
                                              | Q(phone=phone))
                                             & Q(form_id=formID))
                 if form.allowMultiple or apps.count() == 0:
                     app = Entry.objects.create(
                         name=name,
                         submissionTime=datetime.now(),
                         form_id=formID,
                         email=email,
                         phone=phone,
                         formData=formData,
                         slot_id=slot)
                     app.save()
                     if slot is not None:
                         SObj = FormSlot.objects.get(id=slot).slot
                         return ResponseObj(id=app.id,
                                            name=name,
                                            submissionTime=str(
                                                datetime.now()),
                                            email=email,
                                            phone=phone,
                                            slot=SObj.name)
                     else:
                         return ResponseObj(id=app.id,
                                            name=name,
                                            submissionTime=str(
                                                datetime.now()),
                                            email=email,
                                            phone=phone,
                                            slot=None)
                 else:
                     raise APIException(
                         'Registered already with the same email or phone number.',
                         code='ALREADY_REGISTERED')
             else:
                 raise APIException(
                     'Either Name or Phone Number is required.',
                     code='REQUIRED_FIELD_MISSING')
         else:
             raise APIException('Submission deadline has passed',
                                code='SUBMISSION_DEADLINE_ENDED')
     else:
         raise APIException(
             'Applications are not accepted for this form right now.',
             code='INACTIVE_FORM')
Beispiel #2
0
 def resolve_getForm(self, info, **kwargs):
     user = info.context.user
     formID = kwargs.get('formID')
     try:
         form = Form.objects.values().get(id=formID)
     except ObjectDoesNotExist:
         raise APIException('No form exists with the ID provided',
                            code='FORM_NOT_FOUND')
     if user.is_superuser or user in Form.objects.get(
             id=formID).admins.all() or form.creator == user:
         return form
     else:
         raise APIException('You don\'t have permission to view this form',
                            code='PERMISSION_DENIED')
Beispiel #3
0
 def resolve_photo(self, info, **kwargs):
     caption = kwargs.get('caption')
     if caption is not None:
         return Photo.objects.values().get(caption=caption)
     else:
         raise APIException('Caption is required',
                            code='CAPTION_IS_REQUIRED')
Beispiel #4
0
 def resolve_viewEntries(self, info, **kwargs):
     formID = kwargs.get('formID')
     user = info.context.user
     form = Form.objects.get(id=formID)
     if user in form.admins.all() or user.is_superuser:
         return Application.objects.values().filter(form_id=formID)
     else:
         raise APIException('You don\'t have permission required to view entries of this form', code='ACCESS_DENIED')
Beispiel #5
0
 def resolve_getFormFields(self, info, **kwargs):
     formID = kwargs.get('formID')
     try:
         form = Form.objects.get(id=formID)
     except ObjectDoesNotExist:
         raise APIException('No form exists with the ID provided',
                            code='FORM_NOT_FOUND')
     return json.loads(form.formFields)
Beispiel #6
0
 def resolve_getSlotFillData(self, info, **kwargs):
     formID = kwargs.get('formID')
     try:
         form = Form.objects.get(id=formID)
     except ObjectDoesNotExist:
         raise APIException('No form exists with the ID provided',
                            code='FORM_NOT_FOUND')
     return form.formslot_set.values()
Beispiel #7
0
 def resolve_inGitLabGroup(self, info):
     if info.context.user.is_superuser:
         if self['gitlabUsername']:
             return GitLab(self['gitlabUsername']).checkIfUserExists()
         else:
             return False
     else:
         raise APIException('Only Superusers have access',
                            code='ONLY_SUPERUSER_HAS_ACCESS')
Beispiel #8
0
 def resolve_inCloudFlareGroup(self, info):
     if info.context.user.is_superuser:
         if self['email']:
             return Cloudflare(self['email']).checkIfUserExists()
         else:
             return False
     else:
         raise APIException('Only Superusers have access',
                            code='ONLY_SUPERUSER_HAS_ACCESS')
Beispiel #9
0
 def mutate(self, info, title, description, date, draft, pinned):
     post = Post.objects.values().filter(title=title)
     if post.count() == 0:
         post = Post.objects.create(title=title,
                                    description=description,
                                    date=date,
                                    author=info.context.user,
                                    draft=draft,
                                    pinned=pinned)
         post.save()
         return postStatusObj(status=True)
     else:
         raise APIException('Post already exists with same name',
                            code='POST_EXISTS')
Beispiel #10
0
    def resolve_achievements(self, info, **kwargs):
        username = kwargs.get('username')
        category = kwargs.get('category')

        if username is None and category is None:
            raise APIException('Username or Category is required',
                               code='USERNAME_OR_CATEGORY_IS_REQUIRED')
        else:
            if category is not None:
                return Achievements.objects.values().filter(
                    category__name=category)
            else:
                return Achievements.objects.values().filter(
                    user__username=username)
Beispiel #11
0
 def mutate(self, info, title, slug, description, date, draft):
     blogs = Blog.objects.filter(title=title)
     if blogs.count() == 0:
         blog = Blog.objects.create(title=title,
                                    slug=slug,
                                    description=description,
                                    date=date,
                                    author=info.context.user,
                                    draft=draft,
                                    cover=info.context.FILES['cover'])
         blog.save()
         return blogStatusObj(id=blog.id)
     else:
         raise APIException('Blog already exists with same name',
                            code='BLOG_EXISTS')
Beispiel #12
0
 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')
Beispiel #13
0
 def resolve_post(self, info, **kwargs):
     title = kwargs.get('title')
     if title is not None:
         Post.objects.values().get(title=title)
     else:
         raise APIException('Title is required', code='TITLE_IS_REQUIRED')
Beispiel #14
0
 def resolve_inCMSGroup(self, info):
     if info.context.user.is_superuser:
         return Group.objects.values().filter(members__id=self['user_id'])
     else:
         raise APIException('Only Superusers have access',
                            code='ONLY_SUPERUSER_HAS_ACCESS')
Beispiel #15
0
 def resolve_inTelegramGroup(self, info):
     if info.context.user.is_superuser:
         return Telegram(self['telegram_id']).checkIfUserExists()
     else:
         raise APIException('Only Superusers have access',
                            code='ONLY_SUPERUSER_HAS_ACCESS')
Beispiel #16
0
 def resolve_getNews(self, info, **kwargs):
     slug = kwargs.get('slug')
     if slug is not None:
         return News.objects.values().get(slug=slug, featured=True)
     else:
         raise APIException('Slug is required', code='SLUG_IS_REQUIRED')