Exemplo n.º 1
0
Arquivo: views.py Projeto: boxed/curia
def edit_event(request, event_id):
    event = Event.objects.get(pk=event_id)
    check_access(request.user, event, command="change event")
    if not event.event_parent:
        if request.POST:
            form = get_event_form()(request.POST)
            # users, groups = validate_invites(form,event)

            if not form.errors:
                event.title = form.data["title"]
                event.description = form.data["description"]
                event.start_time = form.data["start_time_0"] + " " + form.data["start_time_1"]
                event.end_time = form.data["start_time_0"] + " " + form.data["start_time_1"]
                event.save()

                # Change all children
                event_children = event.event_children.all()
                for child in event_children:
                    try:
                        django.forms.models.save_instance(form, child)
                    except:
                        pass

                # handle_invites(request.user, event, users, groups)
                handle_labels(request, event)

                if event.owner_group != None:
                    return HttpResponseRedirect("/calendars/groups/%s/agenda/" % (event.owner_group.id,))
                else:
                    return HttpResponseRedirect("/calendars/users/%s/agenda/" % (event.owner_user.id,))
        else:
            form = get_event_form()(
                initial={
                    "start_time": event.start_time,
                    "end_time": event.end_time,
                    "title": event.title,
                    "description": event.description,
                    "all_day": event.all_day,
                    "labels": ", ".join([unicode(label) for label in get_labels(event)]),
                }
            )
    else:
        form = get_event_form()(
            initial={
                "start_time": event.start_time,
                "end_time": event.end_time,
                "title": event.title,
                "description": event.description,
                "all_day": event.all_day,
                "labels": ", ".join([unicode(label) for label in get_labels(edit)]),
            }
        )

    return render_to_response(request, "calendars/edit.html", {"event": event, "form": form})
Exemplo n.º 2
0
def edit_file(request, file_id):
    file = get_object_or_404_and_check_access(request,
                                              File,
                                              pk=file_id,
                                              command='edit')

    class EditForm(django.forms.Form):
        title = django.forms.CharField(
            label=_('Title'),
            required=True,
            help_text=_('The title will be visible in the file list'))
        labels = django.forms.CharField(
            required=False,
            label=_('Labels'),
            help_text=_('Help your friends find this item'))
        description = django.forms.CharField(widget=django.forms.Textarea,
                                             label=_('Description'))

    if request.POST:
        form = EditForm(request.POST)

        if form.is_valid():
            file.title = form.cleaned_data['title']
            file.description = form.cleaned_data['description']
            file.save()

            #Handle the labels
            handle_labels(request, file)

            if file.owner_group:
                return HttpResponseRedirect('/files/groups/%s/' %
                                            (file.owner_group.id, ))
            else:
                return HttpResponseRedirect('/files/users/%s/' %
                                            (file.owner_user.id, ))

    else:
        form = EditForm({
            'description':
            file.description,
            'title':
            file.title,
            'labels':
            ', '.join([unicode(label) for label in get_labels(file)])
        })

    return render_to_response(request, 'files/edit.html', {
        'form': form,
        'file': file
    })
Exemplo n.º 3
0
def edit_set(request, set_id, group_id=None):
    if group_id != None:
        group = get_object_or_404_and_check_access(request,
                                                   Group,
                                                   pk=group_id,
                                                   command='view')
    else:
        group = get_current_community()
    image_set = ImageSet.objects.get(pk=set_id)
    check_access(request.user, image_set, command='view')

    class EditForm(django.forms.Form):
        title = django.forms.CharField(
            label=_('Album title'),
            help_text=_('The title will be visible in the set list'))
        labels = django.forms.CharField(
            required=False,
            label=_('Labels'),
            help_text=_('Help your friends find this item'))
        description = django.forms.CharField(required=False,
                                             widget=django.forms.Textarea,
                                             label=_('Description'))

    if request.POST:
        form = EditForm(request.POST)

        if form.is_valid():
            image_set.title = form.cleaned_data['title']
            image_set.description = form.cleaned_data['description']
            image_set.save()

            #Handle the labels
            handle_labels(request, image_set, group)
            return HttpResponseRedirect(image_set.get_absolute_url())

    else:
        form = EditForm({
            'title':
            image_set.title,
            'description':
            image_set.description,
            'labels':
            ', '.join([unicode(label) for label in get_labels(image_set)])
        })

    return render_to_response(request, 'images/edit_set.html', {
        'owner': get_owner(image_set),
        'set': image_set,
        'form': form
    })
Exemplo n.º 4
0
def edit_thread(request, thread_id):
    thread = get_object_or_404_and_check_access(request,
                                                Thread,
                                                pk=thread_id,
                                                command='edit')

    import django.forms

    class EditForm(django.forms.Form):
        name = django.forms.CharField(
            max_length=1024,
            label=_('Name'),
            help_text=_('The title will be visible in the thread list'))
        labels = django.forms.CharField(
            required=False,
            label=_('Labels'),
            help_text=_('Help your friends find this item'))

    if request.POST:
        form = EditForm(request.POST)

        #Handle the labels
        handle_labels(request, thread)

        if form.is_valid():
            thread.name = form.cleaned_data['name']
            thread.save()
            return HttpResponseRedirect(thread.get_absolute_url())
    else:
        form = EditForm({
            'name':
            thread.name,
            'labels':
            ', '.join([unicode(label) for label in get_labels(thread)])
        })

    return render_to_response(request, 'forums/edit.html', {
        'form': form,
        'thread': thread
    })
Exemplo n.º 5
0
Arquivo: views.py Projeto: boxed/curia
def edit_event(request, event_id):
    event = Event.objects.get(pk=event_id)
    check_access(request.user, event, command='change event')
    if not event.event_parent:
        if request.POST:
            form = get_event_form()(request.POST)
            #users, groups = validate_invites(form,event)

            if not form.errors:
                event.title=form.data['title']
                event.description=form.data['description'] 
                event.start_time=form.data['start_time_0']+' '+form.data['start_time_1']
                event.end_time=form.data['start_time_0']+' '+form.data['start_time_1']
                event.save()
        
                #Change all children
                event_children = event.event_children.all()
                for child in event_children:
                    try:
                        django.forms.models.save_instance(form, child)
                    except:
                        pass            

                #handle_invites(request.user, event, users, groups)
                handle_labels(request, event)
                
                if event.owner_group != None:
                    return HttpResponseRedirect('/calendars/groups/%s/agenda/' % (event.owner_group.id,))
                else:
                    return HttpResponseRedirect('/calendars/users/%s/agenda/' % (event.owner_user.id,))
        else:
            form = get_event_form()(initial={'start_time':event.start_time, 'end_time':event.end_time, 'title':event.title, 'description':event.description, 'all_day':event.all_day, 'labels': ', '.join([unicode(label) for label in get_labels(event)])})
    else:
        form = get_event_form()(initial={'start_time':event.start_time, 'end_time':event.end_time, 'title':event.title, 'description':event.description, 'all_day':event.all_day, 'labels': ', '.join([unicode(label) for label in get_labels(edit)])})

    return render_to_response(request, 'calendars/edit.html', {'event': event, 'form': form})
Exemplo n.º 6
0
Arquivo: views.py Projeto: boxed/curia
def edit_user(request, user_id):
    user = get_object_or_404_and_check_access(request,
                                              User,
                                              pk=user_id,
                                              command='edit')
    try:
        meta_user = user.meta
    except MetaUser.DoesNotExist:
        from django.http import Http404
        raise Http404
    #group = Group.objects.get(name='friends of '+user.username)
    presentation = get_presentation_for_user(user, request.community)

    details = Detail.objects.filter(owner_user=user).exclude(
        name='display name').order_by('id')

    class EditForm(django.forms.Form):
        presentation = django.forms.CharField(widget=django.forms.Textarea,
                                              required=False,
                                              label=_('Presentation text'))
        picture = django.forms.ImageField(required=False, label=_('Picture'))
        no_picture = django.forms.BooleanField(required=False,
                                               label=_('Remove my picture'))

    if request.POST:
        new_data = request.POST.copy()
        new_data.update(request.FILES)
        form = EditForm(new_data)

        if form.is_valid():
            django.forms.models.save_instance(form, meta_user)

            if form.cleaned_data['picture'] is not None:
                save_file_for_object(obj=meta_user,
                                     fieldname='picture',
                                     data=new_data)
            meta_user.save()
            name = user.username

            new_version = Version(document=presentation,
                                  title='Presentation',
                                  contents=strip_p(
                                      form.cleaned_data['presentation']),
                                  owner=user)
            new_version.save()

            # remove presentation picture if wanted
            if form.cleaned_data['no_picture']:
                meta_user.picture = u'user-pictures/default_user_image.png'
                meta_user.thumbnail = u'user-thumbnails/default_user_image.png'
                meta_user.icon = u'user-icons/default_user_image.png'
                meta_user.save()

        return HttpResponseRedirect(str(user.get_absolute_url()))
    else:
        form = EditForm(
            initial={
                'birthday': meta_user.birthday,
                'username': user.username,
                'presentation': presentation.get_latest_version().contents,
                'labels': ', '.join(
                    [unicode(label) for label in get_labels(user)])
            })
    return render_to_response(request, 'authentication/edit_user.html', {
        'form': form,
        'the_user': user,
        'details': details,
        'viewer': request.user
    })
Exemplo n.º 7
0
Arquivo: views.py Projeto: boxed/curia
def edit_file(request, file_id):
    file = get_object_or_404_and_check_access(request, File, pk=file_id, command='edit')

    class EditForm(django.forms.Form):
        title = django.forms.CharField(label=_('Title'), required=True, help_text=_('The title will be visible in the file list'))
        labels = django.forms.CharField(required=False, label=_('Labels'), help_text=_('Help your friends find this item'))
        description = django.forms.CharField(widget = django.forms.Textarea, label=_('Description'))
        
    if request.POST:
        form = EditForm(request.POST)

        if form.is_valid():
            file.title = form.cleaned_data['title']
            file.description = form.cleaned_data['description']
            file.save()
            
            #Handle the labels
            handle_labels(request,file)
            
            if file.owner_group:
                return HttpResponseRedirect('/files/groups/%s/' % (file.owner_group.id,))
            else:
                return HttpResponseRedirect('/files/users/%s/' % (file.owner_user.id,))

    else:
        form = EditForm({'description': file.description, 'title': file.title, 'labels': ', '.join([unicode(label) for label in get_labels(file)])})
                
    return render_to_response(request, 'files/edit.html', {'form':form, 'file': file})
Exemplo n.º 8
0
Arquivo: views.py Projeto: boxed/curia
def edit_set(request, set_id, group_id=None):
    if group_id != None:
        group = get_object_or_404_and_check_access(request, Group, pk=group_id, command='view')
    else:
        group = get_current_community()
    image_set = ImageSet.objects.get(pk=set_id)
    check_access(request.user, image_set, command='view')

    class EditForm(django.forms.Form):
        title = django.forms.CharField(label=_('Album title'), help_text=_('The title will be visible in the set list'))
        labels = django.forms.CharField(required=False, label=_('Labels'), help_text=_('Help your friends find this item'))  
        description = django.forms.CharField(required=False, widget = django.forms.Textarea, label=_('Description'))

    if request.POST:
        form = EditForm(request.POST)

        if form.is_valid():
            image_set.title = form.cleaned_data['title']
            image_set.description = form.cleaned_data['description']
            image_set.save()
            
            #Handle the labels
            handle_labels(request,image_set,group)
            return HttpResponseRedirect(image_set.get_absolute_url())

    else:
        form = EditForm({'title':image_set.title, 'description':image_set.description, 'labels': ', '.join([unicode(label) for label in get_labels(image_set)])})
        
    return render_to_response(request, 'images/edit_set.html', {'owner':get_owner(image_set), 'set':image_set, 'form':form})
Exemplo n.º 9
0
Arquivo: views.py Projeto: boxed/curia
def edit_thread(request, thread_id):
    thread = get_object_or_404_and_check_access(request, Thread, pk=thread_id, command="edit")

    import django.forms

    class EditForm(django.forms.Form):
        name = django.forms.CharField(
            max_length=1024, label=_("Name"), help_text=_("The title will be visible in the thread list")
        )
        labels = django.forms.CharField(
            required=False, label=_("Labels"), help_text=_("Help your friends find this item")
        )

    if request.POST:
        form = EditForm(request.POST)

        # Handle the labels
        handle_labels(request, thread)

        if form.is_valid():
            thread.name = form.cleaned_data["name"]
            thread.save()
            return HttpResponseRedirect(thread.get_absolute_url())
    else:
        form = EditForm({"name": thread.name, "labels": ", ".join([unicode(label) for label in get_labels(thread)])})

    return render_to_response(request, "forums/edit.html", {"form": form, "thread": thread})
Exemplo n.º 10
0
Arquivo: views.py Projeto: boxed/curia
def edit_user(request, user_id):
    user = get_object_or_404_and_check_access(request, User, pk=user_id, command='edit')
    try:
        meta_user = user.meta
    except MetaUser.DoesNotExist:
        from django.http import Http404
        raise Http404
    #group = Group.objects.get(name='friends of '+user.username)
    presentation = get_presentation_for_user(user, request.community)
    
    details = Detail.objects.filter(owner_user=user).exclude(name='display name').order_by('id')
    
    class EditForm(django.forms.Form):
        presentation = django.forms.CharField(widget = django.forms.Textarea,required=False, label=_('Presentation text'))
        picture = django.forms.ImageField(required=False, label=_('Picture'))
        no_picture = django.forms.BooleanField(required=False, label=_('Remove my picture'))

    if request.POST:
        new_data = request.POST.copy()
        new_data.update(request.FILES)
        form = EditForm(new_data)

        if form.is_valid():
            django.forms.models.save_instance(form, meta_user)
            
            if form.cleaned_data['picture'] is not None:  
                save_file_for_object(obj=meta_user, fieldname='picture', data=new_data)
            meta_user.save()
            name = user.username
            
            new_version = Version(document=presentation,title='Presentation', contents=strip_p(form.cleaned_data['presentation']), owner=user)
            new_version.save()
            
            # remove presentation picture if wanted
            if form.cleaned_data['no_picture']:
                meta_user.picture = u'user-pictures/default_user_image.png'
                meta_user.thumbnail = u'user-thumbnails/default_user_image.png'
                meta_user.icon = u'user-icons/default_user_image.png'                
                meta_user.save()
            
        return HttpResponseRedirect(str(user.get_absolute_url()))
    else:
        form = EditForm(initial={'birthday': meta_user.birthday, 'username': user.username, 'presentation':presentation.get_latest_version().contents,'labels': ', '.join([unicode(label) for label in get_labels(user)])})
    return render_to_response(request, 'authentication/edit_user.html', {'form':form, 'the_user': user, 'details': details, 'viewer':request.user})