Exemplo n.º 1
0
    def save(self, *args, **kwargs):
        "Form processor"

        profile = None

        if self.invitation:
            # Create DjangoUser
            django_user = django_auth.User(
                username=self.cleaned_data['username'], password='')
            django_user.set_password(self.cleaned_data['password'])
            django_user.save()

            # Crate profile
            try:
                profile = django_user.profile
            except:
                profile = User()
                profile.user = django_user

            profile.name = django_user.username
            profile.default_group = self.invitation.default_group
            profile.save()

            # Create contact
            try:
                contact_type = ContactType.objects.get(
                    Q(name='Person') | Q(slug='person'))
            except:
                contact_type = ContactType.objects.all()[0]

            try:
                # Check if contact has already been created (e.g. by a signals
                contact = profile.get_contact()
                if not contact:
                    contact = Contact()
            except:
                contact = Contact()

            contact.name = self.cleaned_data['name']
            contact.contact_type = contact_type
            contact.related_user = profile
            contact.save()

            # Set email
            try:
                emailfield = contact_type.fields.filter(field_type='email')[0]
                email = ContactValue(
                    value=self.invitation.email, field=emailfield, contact=contact)
                email.save()
            except:
                pass

            # Add quick start widget
            widget = Widget(user=profile,
                            perspective=profile.get_perspective(),
                            module_name='anaf.core',
                            widget_name='widget_welcome')
            widget.save()

        return profile
Exemplo n.º 2
0
def workspace_test():
	print_data('workspaces objects', br=False)

	for index in range(3):
		w = Workspace()
		w.name = 'New workspace name'
		w.description = 'Some new description'
		w.save()

	workspaces = Workspace.all()
	print_data('new objects -> model.all()', workspaces)

	w.name = 'Updated name'
	w.save()

	workspaces = Workspace.all()
	print_data('UPDATED -> model.all()', workspaces)

	workspaces = Workspace.get(id=w.id, name=w.name)
	print_data('GET -> model.get()', [workspaces])

	workspaces = Workspace.filter(name='New workspace name')
	print_data('FILTER -> model.filter()', workspaces)

	for index in range(2):
		o = Application()
		o.workspace_id = w.guid
		o.save()

	a = View()
	a.application_id = o.guid
	a.save()

	a = Resource()
	a.application_id = o.guid
	a.save()

	for index in range(3):
		o = Widget()
		o.workspace_id = w.guid
		o.save()

	for index in range(3):
		o = DataSource()
		o.workspace_id = w.guid
		o.save()

	objects = Workspace.all() + Resource.all() + Application.all() + Widget.all() + DataSource.all() + View.all()
	print_data('All objects in db', objects)

#	[w.delete() for w in Workspace.all()]
	workspaces = Workspace.all()
	print_data('cleaned', workspaces)

	workspaces = Workspace.filter(include_deleted=True)
	print_data('cleaned with deleted if exists', workspaces)

	objects = Workspace.all() + Resource.all() + Application.all() + Widget.all() + DataSource.all() + View.all()
	print_data('no objects left', objects)
Exemplo n.º 3
0
def create_photo_widget(wid, img_url):

    w1 = Widget(type_id=3, name="Mason!", size=3)
    i1 = [
        WidgetItem(widget_id=wid,
                   color_class=random.choice(COLOR_CLASSES),
                   img_url=img_url)
    ]

    return [w1, i1]
Exemplo n.º 4
0
def create_twitter_widget():

    w1 = Widget(type_id=2, name="@webdevMason", size=5)
    i1 = [
        WidgetItem(
            widget_id=2,
            text=
            "<a class='twitter-timeline' href='https://twitter.com/webdevMason?ref_src=twsrc%5Etfw'>Tweets by webdevMason</a> <script async src='https://platform.twitter.com/widgets.js' charset='utf-8'></script>"
        )
    ]

    return [w1, i1]
Exemplo n.º 5
0
 def test_proxy_model_included(self):
     """
     Regression for #11428 - Proxy models aren't included when you dumpdata
     """
     stdout = StringIO()
     # Create an instance of the concrete class
     Widget(name='grommet').save()
     management.call_command('dumpdata',
                             'fixtures_regress.widget',
                             'fixtures_regress.widgetproxy',
                             format='json',
                             stdout=stdout)
     self.assertEqual(
         stdout.getvalue(),
         """[{"pk": 1, "model": "fixtures_regress.widget", "fields": {"name": "grommet"}}]"""
     )
Exemplo n.º 6
0
def widget_test():
	print_data('widgets objects', br=False)
	workspaces = []
	for index in range(3):
		w = Workspace()
		w.name = 'New workspace name'
		w.description = 'Some new description'
		w.save()
		workspaces.append(w)

	for index in range(3):
		w = Widget()
		w.source = '<source>some stuff</source>'
		w.workspace_id = workspaces[0].guid if index in [0, 1] else workspaces[1].guid
		w.save()

	widgets = Widget.all()
	print_data('new objects -> model.all()', widgets)

	w.source = '<b>UDPATED</b>'
	w.save()
	w.reload()

	print_data('UPDATED', [w.source])

	widgets = Widget.get(id=w.id)
	print_data('GET -> model.get()', [widgets])

	widgets = Widget.filter(source='<source>some stuff</source>')
	print_data('FILTER -> model.filter()', widgets)

	for index, w in enumerate(workspaces):
		widgets = w.widgets
		print_data('workspace %s -> workspace.widgets' % str(index), widgets)

	[w.delete() for w in Widget.all()]
	objects = Widget.all() + Workspace.all()
	print_data('cleaned', objects)

	widgets = Widget.filter(include_deleted=True)
	print_data('cleaned with deleted if exists', widgets)
Exemplo n.º 7
0
def main(data):

    action = data.get("action", "read")
    input_data = data.get("data", {})
    result = {}

    if action == "create":
        widget = Widget()
        widget.fill_from_json(input_data)
        widget.save(b64source=input_data.get("b64source", None))
        result[widget.guid] = widget.to_json()

    elif action == "read":
        for wid_guid in input_data:
            widget = Widget.get(guid=wid_guid)
            result[wid_guid] = widget.to_json(
                include=["b64source"]) if widget else None

    elif action == "update":
        for widget_guid in input_data:
            widget = Widget.get(guid=widget_guid)
            wid_json = input_data[widget_guid]
            if widget:
                widget.fill_from_json(wid_json)
                widget.save(b64source=input_data.get("b64source", None))
                result[widget_guid] = widget.to_json(include=["b64source"])

    elif action == "delete":
        for widget_guid in input_data:
            widget = Widget.get(guid=widget_guid)
            if widget:
                widget.delete()
                result[widget_guid] = "deleted"
            else:
                result[widget_guid] = "not_found"

    write_response(result)
Exemplo n.º 8
0
def create_widget_1():

    i1 = "Finish writing <b>my book</b>"
    i2 = "Make a pile of edible golden eggs, <a href='https://yhoo.it/2C6FpSm'>like these</a>"
    i3 = "Make a <b>wearable project</b> from/inspired by this book: <a href='http://amzn.to/2EsSDL2'><i>Make: Wearable Electronics</i></a>"
    i4 = "Volunteer @ Burning Man"
    i5 = "Fully document an <b>IVF cycle</b>"
    i6 = "Contribute to an open source project"
    i7 = "<b>Sky dive</b>, or something similarly terrifying"
    i8 = "<b>Teach Bert</b> to do an r/dogtraining trick of the month, e.g. <a href='http://bit.ly/2lB6GWg'>mirror me</a>"
    i9 = "Design an educational simulation"
    i10 = "Write a long-form essay"
    i11 = "Run a 5k"
    i12 = "Read <b>50 books</b> in a year"
    i13 = "Do a chin-up"
    i14 = "Write a song"
    i15 = "Grow & harvest a vegetable"
    i16 = "Throw a <b>big party</p>"
    i17 = "Complete a <b>doula training</b> course, e.g. <a href='http://bit.ly/2zXyrxc'>this one</a>"
    i18 = "Do a <b>10+ mile</b> hike"
    i19 = "Lead a training/seminar at work"
    i20 = "Make kombucha from scratch"
    i21 = "<b>Meditate</b> every day for a month"
    i22 = "<b>Repair</b> something currently too damaged to use"
    i23 = "Play D&D"
    i24 = "Attend a conference solo"
    i25 = "Design an <b>escape room</b>"
    i26 = "Attend <b>Sleep No More</b> or similar <a href='http://bit.ly/2wMtklZ'>(See: Sleep No More)</a>"
    i27 = "Host a dinner to connect interesting friends who've never met one another"
    i28 = "Write an interesting Twitter bot"
    i29 = "Finish a painting"
    i30 = "Create a <b>new recipe</b>"

    w1 = Widget(type_id=1, name="<30 Bucket List", size=4)

    i1 = WidgetItem(widget_id=1,
                    text=i1,
                    score=10,
                    color_class=select_cc(10),
                    progress=3)
    i2 = WidgetItem(widget_id=1, text=i2, score=4, color_class=select_cc(4))
    i3 = WidgetItem(widget_id=1, text=i3, score=8, color_class=select_cc(8))
    i4 = WidgetItem(widget_id=1, text=i4, score=7, color_class=select_cc(7))
    i5 = WidgetItem(widget_id=1, text=i5, score=8, color_class=select_cc(8))
    i6 = WidgetItem(widget_id=1, text=i6, score=3, color_class=select_cc(3))
    i7 = WidgetItem(widget_id=1, text=i7, score=5, color_class=select_cc(5))
    i8 = WidgetItem(widget_id=1, text=i8, score=6, color_class=select_cc(6))
    i9 = WidgetItem(widget_id=1, text=i9, score=5, color_class=select_cc(5))
    i10 = WidgetItem(widget_id=1, text=i10, score=4, color_class=select_cc(4))
    i11 = WidgetItem(widget_id=1, text=i11, score=4, color_class=select_cc(4))
    i12 = WidgetItem(widget_id=1,
                     text=i12,
                     score=10,
                     color_class=select_cc(10))
    i13 = WidgetItem(widget_id=1, text=i13, score=6, color_class=select_cc(6))
    i14 = WidgetItem(widget_id=1, text=i14, score=2, color_class=select_cc(2))
    i15 = WidgetItem(widget_id=1, text=i15, score=2, color_class=select_cc(2))
    i16 = WidgetItem(widget_id=1, text=i16, score=5, color_class=select_cc(5))
    i17 = WidgetItem(widget_id=1, text=i17, score=9, color_class=select_cc(9))
    i18 = WidgetItem(widget_id=1, text=i18, score=5, color_class=select_cc(5))
    i19 = WidgetItem(widget_id=1, text=i19, score=4, color_class=select_cc(4))
    i20 = WidgetItem(widget_id=1, text=i20, score=3, color_class=select_cc(3))
    i21 = WidgetItem(widget_id=1, text=i21, score=5, color_class=select_cc(5))
    i22 = WidgetItem(widget_id=1, text=i22, score=3, color_class=select_cc(3))
    i23 = WidgetItem(widget_id=1, text=i23, score=2, color_class=select_cc(2))
    i24 = WidgetItem(widget_id=1, text=i24, score=3, color_class=select_cc(3))
    i25 = WidgetItem(widget_id=1, text=i25, score=6, color_class=select_cc(6))
    i26 = WidgetItem(widget_id=1, text=i26, score=1, color_class=select_cc(1))
    i27 = WidgetItem(widget_id=1,
                     text=i27,
                     score=5,
                     color_class=select_cc(5),
                     progress=10)
    i28 = WidgetItem(widget_id=1,
                     text=i28,
                     score=4,
                     color_class=select_cc(4),
                     progress=100)
    i29 = WidgetItem(widget_id=1, text=i29, score=3, color_class=select_cc(3))
    i30 = WidgetItem(widget_id=1, text=i30, score=3, color_class=select_cc(3))

    i = [
        i1, i2, i3, i6, i15, i8, i4, i9, i7, i10, i11, i12, i13, i14, i16, i17,
        i18, i19, i20, i21, i22, i23, i24, i25, i26, i27, i28, i29, i5, i30
    ]

    return [w1, i]
Exemplo n.º 9
0
workspace = Workspace.get(guid=workspace_id)

if not workspace:
	self.action('goTo', ['/main'])

elif command in ['delete', 'update']:

	if 'widget_id' not in request.arguments:
		raise Exception(u'Widget ID is not provided')
	widget_id = request.arguments['widget_id']
	widget = Widget.get(guid=widget_id, workspace_id=workspace.guid)

	if widget:
		if command == 'delete':
			widget.delete()
		else:
			title = request.arguments['title']
			if title:
				widget.name = title
				widget.save()

	self.dialog_update.action('hide', ['0'])

elif command == 'create':
	title = request.arguments['title']
	if title:
		widget = Widget()
		widget.workspace_id = workspace.guid
		widget.name = title
		widget.save()