<s> from django import forms <EOL> from django . utils . translation import ugettext as _ <EOL> from projector . core . exceptions import ForkError <EOL> from projector . forks . base import BaseExternalForkForm <EOL> from projector . models import Project <EOL> from vcs . exceptions import VCSError <EOL> class BitbucketForkForm ( BaseExternalForkForm ) : <EOL> site = '<STR_LIT>' <EOL> help_text = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> username = forms . RegexField ( regex = r'<STR_LIT>' , max_length = <NUM_LIT> , <EOL> label = _ ( '<STR_LIT>' ) , <EOL> help_text = _ ( '<STR_LIT>' ) ) <EOL> projectname = forms . RegexField ( regex = r'<STR_LIT>' , max_length = <NUM_LIT> , <EOL> label = _ ( '<STR_LIT>' ) , <EOL> help_text = _ ( '<STR_LIT>' <EOL> '<STR_LIT:user>' ) ) <EOL> use_https = forms . BooleanField ( initial = False , label = _ ( '<STR_LIT>' ) , <EOL> help_text = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , required = False ) <EOL> def clean_projectname ( self ) : <EOL> data = self . cleaned_data [ '<STR_LIT>' ] <EOL> if getattr ( self , '<STR_LIT>' , None ) is not None : <EOL> try : <EOL> Project . objects . get ( name = data , author = self . request . user ) <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> except Project . DoesNotExist : <EOL> pass <EOL> return data <EOL> def fork ( self ) : <EOL> """<STR_LIT>""" <EOL> data = self . cleaned_data <EOL> url = self . get_url ( ) <EOL> try : <EOL> project = Project . objects . create_project ( <EOL> vcs_alias = '<STR_LIT>' , <EOL> author = self . request . user , <EOL> name = data [ '<STR_LIT>' ] , <EOL> public = self . is_public ( ) , <EOL> fork_url = url ) <EOL> except VCSError : <EOL> raise ForkError ( _ ( "<STR_LIT>" ) ) <EOL> return project <EOL> def get_url ( self ) : <EOL> if self . cleaned_data . get ( '<STR_LIT>' , False ) : <EOL> schema = '<STR_LIT>' <EOL> else : <EOL> schema = '<STR_LIT:http>' <EOL> url = '<STR_LIT>' . join ( ( schema , self . site ) ) <EOL> username = self . cleaned_data [ '<STR_LIT:username>' ] <EOL> projectname = self . cleaned_data [ '<STR_LIT>' ] <EOL> url = '<STR_LIT:/>' . join ( ( url , username , projectname ) ) <EOL> return url </s>
