~cmiller/ubuntu/quantal/deluge/fix-parameter-move-storage

« back to all changes in this revision

Viewing changes to deluge/ui/webui/torrent_add.py

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2009-11-13 02:39:45 UTC
  • mfrom: (4.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091113023945-te1bybo2912ejzuc
Tags: 1.2.0~rc3-4
* debian/control: bump build-dep on python-setuptools to (>= 0.6c9).
* debian/patches:
  - 25_r5921_fastresume_files.patch
    new, should fix problems with fresh configs;
  - 30_r5931_ipc_lockfile.patch:
    new, should fix an issue where Deluge will fail to start if there is a
    stale ipc lockfile. (Closes: #555849)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# -*- coding: utf-8 -*-
3
 
#
4
 
# Copyright (C) Martijn Voncken 2008 <mvoncken@gmail.com>
5
 
#
6
 
# This program is free software; you can redistribute it and/or modify
7
 
# it under the terms of the GNU General Public License as published by
8
 
# the Free Software Foundation; either version 3, or (at your option)
9
 
# any later version.
10
 
#
11
 
# This program is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program.  If not, write to:
18
 
#     The Free Software Foundation, Inc.,
19
 
#     51 Franklin Street, Fifth Floor
20
 
#     Boston, MA  02110-1301, USA.
21
 
#
22
 
#    In addition, as a special exception, the copyright holders give
23
 
#    permission to link the code of portions of this program with the OpenSSL
24
 
#    library.
25
 
#    You must obey the GNU General Public License in all respects for all of
26
 
#    the code used other than OpenSSL. If you modify file(s) with this
27
 
#    exception, you may extend this exception to your version of the file(s),
28
 
#    but you are not obligated to do so. If you do not wish to do so, delete
29
 
#    this exception statement from your version. If you delete this exception
30
 
#    statement from all source files in the program, then also delete it here.
31
 
#
32
 
 
33
 
#
34
 
 
35
 
#
36
 
from deluge.ui.client import sclient as proxy
37
 
from deluge.log import LOG as log
38
 
from deluge import component
39
 
 
40
 
import utils
41
 
from render import render, error_page
42
 
import page_decorators as deco
43
 
import lib.newforms_plus as forms
44
 
import web
45
 
 
46
 
class OptionsForm(forms.Form):
47
 
    download_location =  forms.ServerFolder(_("Download Location"))
48
 
    compact_allocation = forms.CheckBox(_("Compact Allocation"))
49
 
 
50
 
    #download
51
 
    max_download_speed_per_torrent = forms.DelugeFloat(
52
 
        _("Maximum Down Speed"))
53
 
    max_upload_speed_per_torrent = forms.DelugeFloat(
54
 
        _("Maximum Up Speed"))
55
 
    max_connections_per_torrent = forms.DelugeInt(_("Maximum Connections"))
56
 
    max_upload_slots_per_torrent = forms.DelugeInt(_("Maximum Upload Slots"))
57
 
    #general
58
 
    prioritize_first_last_pieces = forms.CheckBox(
59
 
        _('Prioritize first and last pieces'))
60
 
    add_paused = forms.CheckBox(_('Add In Paused State'))
61
 
    default_private = forms.CheckBox(_('Set Private Flag'))
62
 
 
63
 
    def initial_data(self):
64
 
        data = proxy.get_config()
65
 
        log.debug("add:Init options with:%s" % data)
66
 
        return data
67
 
 
68
 
class AddForm(forms.Form):
69
 
    url = forms.CharField(label=_("Url"), required=False,
70
 
        widget=forms.TextInput(attrs={'size':60}))
71
 
    torrent = forms.CharField(label=_("Upload torrent"), required=False,
72
 
        widget=forms.FileInput(attrs={'size':60}))
73
 
    #hash = forms.CharField(label=_("Hash"), required=False,
74
 
    #    widget=forms.TextInput(attrs={'size':60}))
75
 
    #ret = forms.CheckBox(_('Add more'))
76
 
 
77
 
    #choose_files = forms.CheckBox(_('Choose Files')) #BROKEN!
78
 
 
79
 
 
80
 
class torrent_add:
81
 
 
82
 
    def add_page(self,error = None):
83
 
        vars  = web.input(url = None)
84
 
        form_data = {'url':vars.url}
85
 
 
86
 
        options_data = None
87
 
        if error:
88
 
            options_data = utils.get_newforms_data(OptionsForm)
89
 
            log.debug("add:(error-state):Init options with:%s" % options_data)
90
 
        return render.torrent_add(AddForm(form_data),OptionsForm(options_data), error)
91
 
 
92
 
    @deco.deluge_page
93
 
    def GET(self, name):
94
 
        return self.add_page()
95
 
 
96
 
 
97
 
    @deco.check_session
98
 
    def POST(self, name):
99
 
        """
100
 
        allows:
101
 
        *posting of url
102
 
        *posting file-upload
103
 
        """
104
 
        vars = web.input(url = None, torrent = {},choose_files = False)
105
 
 
106
 
        options_form = OptionsForm(utils.get_newforms_data(OptionsForm))
107
 
        if not options_form.is_valid():
108
 
            print self.add_page(error = _("Error in torrent options."))
109
 
            return
110
 
        options = options_form.cleaned_data
111
 
 
112
 
 
113
 
 
114
 
        torrent_name = None
115
 
        torrent_data  = None
116
 
        if vars.torrent.filename:
117
 
            torrent_name = vars.torrent.filename
118
 
            torrent_data  = vars.torrent.file.read()
119
 
 
120
 
        if vars.url and torrent_name:
121
 
            #error_page(_("Choose an url or a torrent, not both."))
122
 
            print self.add_page(error = _("Choose an url or a torrent, not both."))
123
 
            return
124
 
 
125
 
        if vars.url:
126
 
            proxy.add_torrent_url(vars.url,options)
127
 
            log.debug("add-url:options :%s" % options)
128
 
            self.redirect(vars.choose_files)
129
 
        elif torrent_name:
130
 
            proxy.add_torrent_file_binary(vars.torrent.filename, torrent_data, options)
131
 
            log.debug("add-file:options :%s" % options)
132
 
            self.redirect(vars.choose_files)
133
 
        else:
134
 
            print self.add_page(error = _("No data"))
135
 
            return
136
 
 
137
 
    def redirect(self,choose_files):
138
 
        if choose_files: #redirect to file chooser
139
 
            torrent_id = proxy.get_session_state()[-1] #HACK! no return-value for torrent_add_*
140
 
            utils.seeother("/torrent/files/%s" % torrent_id)
141
 
 
142
 
        else: #default
143
 
            utils.do_redirect()
144
 
 
145
 
 
146
 
def register():
147
 
    component.get("PageManager").register_page("/torrent/add(.*)",torrent_add)
 
 
b'\\ No newline at end of file'