~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/views/charms.py

  • Committer: Tarmac
  • Author(s): Aaron Bentley
  • Date: 2013-08-06 21:06:58 UTC
  • mfrom: (328.2.13 separate-qa)
  • Revision ID: tarmac-20130806210658-6eau0bkn7o9rmspo
[r=benji][bug=][author=abentley] Separate QA answers from other data.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
    CharmSource,
20
20
    getfs,
21
21
    find_charms,
22
 
    QAData,
 
22
    QADataSource,
23
23
)
24
24
from charmworld.utils import quote_key
25
25
from charmworld.views import log
124
124
            endpoint='charm'
125
125
        )
126
126
        icon_path = icon_path + '/' + remainder
 
127
    qa_data_source = QADataSource.from_db(request.db)
127
128
    return {
128
129
        "charm": charm,
129
130
        'format_change': format_change,
132
133
        "name": charm.name,
133
134
        "others": others,
134
135
        "project": request.registry.settings.get('project_name', 'Not Set.'),
135
 
        "qadata": QAData(request.db, charm.qa),
 
136
        "qadata": qa_data_source.get_qa_data(charm),
136
137
        "readme_format": readme_format,
137
138
        "readme": readme,
138
139
    }
372
373
    schema = get_qa_form_schema(qa_questions)
373
374
    qa_form = Form(schema, buttons=('submit',))
374
375
    qa_form.css_class = 'form-horizontal well'
375
 
 
 
376
    qa_data_source = QADataSource.from_db(request.db)
376
377
    if 'submit' in request.POST:
377
378
        data = request.POST.items()
378
379
        try:
379
380
            valid_data = qa_form.validate(data)
380
 
            charm['qa'] = valid_data
381
 
            CharmSource.from_request(request).save(charm)
 
381
            qa_data_source.save_qa_data(Charm(charm), valid_data)
382
382
            form = qa_form.render(valid_data)
383
383
        except ValidationFailure, exc:
384
384
            qa_form = exc
385
385
            valid_data = {}
386
386
            form = qa_form.render()
387
 
    elif 'qa' in charm:
388
 
        # There's existing data to use to fill the form with.
389
 
        valid_data = charm['qa']
390
 
        form = qa_form.render(valid_data)
391
387
    else:
 
388
        qa_data = qa_data_source.get_qa_data(Charm(charm)).charm_data
 
389
        if qa_data is not None:
 
390
            # There's existing data to use to fill the form with.
 
391
            valid_data = qa_data
392
392
        form = qa_form.render(valid_data)
393
393
 
394
394
    return {