Esempio n. 1
0
    def mutate(self, info, text, visibility):
        creator = info.context.user
        idea = Idea(text=text, visibility=visibility, creator=creator)
        idea.save()
        send_ideas_to_followers(creator, idea)

        return CreateIdea(idea=idea)
Esempio n. 2
0
def create_view(request):
    idea = Idea()
    title = request.POST.get('title', '')
    description = request.POST.get('description', '')
    idea.title = title
    idea.description = description
    idea.user = request.user
    idea.save()
    return json_response({'is_success': True})
Esempio n. 3
0
def new_idea(request):
    if request.user.is_authenticated():
        idea = Idea(
            creator=request.user,
            title=request.POST['title'],
            description=request.POST['description'],
            views=0,
            category=Category.objects.get(name=request.POST['category']))
        idea.save()
        return HttpResponse("true")
    else:
        return HttpResponse("false")
Esempio n. 4
0
def new_idea(request):
	if request.user.is_authenticated():
		idea = Idea(
			creator=request.user,
			title=request.POST['title'],
			description=request.POST['description'],
			views=0,
			category=Category.objects.get(name=request.POST['category']))
		idea.save()
		return HttpResponse("true")
	else:
		return HttpResponse("false")
Esempio n. 5
0
    def test_add_to_list(self):
        """
        Tests that adding to favorite list object works
        """
        user = createUser()
        
        idea = Idea(title="some title", text="some text i write")
        idea.save()
        
        fav = FavoriteItem(user=user, content_object=idea)

        self.assertEqual(idea.pk, fav.content_object.pk)
        
Esempio n. 6
0
def add_additional_create_idea_params(idea: Idea, data: dict,
                                      url_slug: str) -> None:
    idea.url_slug = url_slug
    try:
        hub = Hub.objects.get(url_slug=data['hub'])
        hub_shared_in = Hub.objects.get(url_slug=data['hub_shared_in'])
    except Hub.DoesNotExist:
        idea.delete()
        raise ValidationError('Hub does not exist: ' + data['hub'])
    idea.hub = hub
    idea.hub_shared_in = hub_shared_in
    if 'location' in data:
        idea.location = get_location(data['location'])

    if 'image' in data and 'thumbnail_image' in data:
        idea.image = get_image_from_data_url(data['image'])[0]
        idea.thumbnail_image = get_image_from_data_url(
            data['thumbnail_image'])[0]
    if 'parent_organization' in data:
        try:
            organization = Organization.objects.get(
                id=data['parent_organization'])
        except Organization.DoesNotExist:
            idea.delete()
            raise ValidationError('Organization does not exist!')
        idea.organization = organization

    try:
        idea.save()
    except IntegrityError:
        if url_slug.endswith(str(idea.id)):
            # It seems like we alread called this function and added the id to the url slug, but there is still an integrity error!
            # Seems like it is unrelated to the url_slug and there is some bigger problem
            idea.delete()
            raise ValidationError("Internal Server Error")
        else:
            # The url slug is already taken! We'll append the project id in the end to make it unique again
            add_additional_create_idea_params(idea, data,
                                              url_slug + str(idea.id))
Esempio n. 7
0
class _BaseIdeaTest(APITestCase):
    def setUp(self):
        self.user = User.objects.create_user('bob', password='******')
        self.project = Project(owner=self.user,
                                title='testing',
                                description='Super test',
                                status='IDEA')

        self.project.save()
        self.client.login(username='******', password='******')
        self.IDEA_DATA = {'owner': self.user,
                            'title' : 'really descriptive title',
                            'project' : self.project,
                            'description': 'test idea',
                            'votes': 1}

        self.idea = Idea(**self.IDEA_DATA)
        self.idea.save()

    def tearDown(self):
        self.user.delete()
        self.idea.delete()
        self.project.delete()
Esempio n. 8
0
 def test_project_list_has_ideas_count(self):
     i = Idea(owner=self.user, project=self.project, title='IDEAR', description='RRRRr', votes=0)
     i.save()
     url = reverse('project-list')
     response = self.client.get(url)
     self.assertEqual(response.data['results'][0]['ideas_count'], 1)
Esempio n. 9
0
def create_idea(title='Sample Idea', text='Some random idea', public=False,owner=None, parent=None):
    idea = Idea(title=title, text=text, owner=owner, public=public, parent=parent)
    idea.save()
    return idea