Ticket #795: ticket795.patch

File ticket795.patch, 3.1 KB (added by tofay, 9 years ago)
  • mediagoblin/submit/forms.py

    diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py
    index c5bacc4..69d211e 100644
    a b  
    1616
    1717
    1818import wtforms
    19 
     19from wtforms.ext.sqlalchemy.fields import QuerySelectField
    2020from mediagoblin import mg_globals
    2121from mediagoblin.tools.text import tag_length_validator
    2222from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
    def get_submit_start_form(form, **kwargs):  
    5050            _('License'),
    5151            [wtforms.validators.Optional(),],
    5252            choices=licenses_as_choices())
     53        collection = QuerySelectField(
     54            _('Collection'),
     55            allow_blank=True, blank_text=_('-- Select --'), get_label='title',)
    5356        max_file_size = wtforms.HiddenField('')
    5457        upload_limit = wtforms.HiddenField('')
    5558        uploaded = wtforms.HiddenField('')
  • mediagoblin/submit/views.py

    diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py
    index eae4a1e..3c7d659 100644
    a b import logging  
    2323
    2424_log = logging.getLogger(__name__)
    2525
    26 
     26from mediagoblin.db.models import Collection
     27from mediagoblin.tools.federation import create_activity
    2728from mediagoblin.tools.translate import pass_to_ugettext as _
    2829from mediagoblin.tools.response import render_to_response, redirect
    2930from mediagoblin.decorators import require_active_login, user_has_privilege
    from mediagoblin.media_types import FileTypeNotSupported  
    3334from mediagoblin.submit.lib import \
    3435    check_file_field, submit_media, get_upload_file_limits, \
    3536    FileUploadLimit, UserUploadLimit, UserPastUploadLimit
     37from mediagoblin.user_pages.lib import add_media_to_collection
    3638
    3739
    3840@require_active_login
    def submit_start(request):  
    4951        max_file_size=max_file_size,
    5052        upload_limit=upload_limit,
    5153        uploaded=request.user.uploaded)
     54    submit_form.collection.query = Collection.query.filter_by(
     55        actor=request.user.id,
     56        type=Collection.USER_DEFINED_TYPE
     57    ).order_by(Collection.title)
    5258
    5359    if request.method == 'POST' and submit_form.validate():
    5460        if not check_file_field(request, 'file'):
    def submit_start(request):  
    5662                _(u'You must provide a file.'))
    5763        else:
    5864            try:
    59                 submit_media(
     65                media = submit_media(
    6066                    mg_app=request.app, user=request.user,
    6167                    submitted_file=request.files['file'],
    6268                    filename=request.files['file'].filename,
    def submit_start(request):  
    6773                    upload_limit=upload_limit, max_file_size=max_file_size,
    6874                    urlgen=request.urlgen)
    6975
     76                if submit_form.collection.data:
     77                    add_media_to_collection(
     78                        submit_form.collection.data, media)
     79                    create_activity(
     80                        "add", media, request.user, target=collection)
     81
    7082                add_message(request, SUCCESS, _('Woohoo! Submitted!'))
    7183
    7284                return redirect(request, "mediagoblin.user_pages.user_home",